summaryrefslogtreecommitdiffstats
path: root/kexi/tools/add_column
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
commit8362bf63dea22bbf6736609b0f49c152f975eb63 (patch)
tree0eea3928e39e50fae91d4e68b21b1e6cbae25604 /kexi/tools/add_column
downloadkoffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz
koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kexi/tools/add_column')
-rw-r--r--kexi/tools/add_column/Makefile.am5
-rwxr-xr-xkexi/tools/add_column/kexi_add_column114
-rw-r--r--kexi/tools/add_column/kexi_add_column_gui99
-rw-r--r--kexi/tools/add_column/kexi_add_column_gui_transl_pl.sh24
4 files changed, 242 insertions, 0 deletions
diff --git a/kexi/tools/add_column/Makefile.am b/kexi/tools/add_column/Makefile.am
new file mode 100644
index 00000000..74e150d1
--- /dev/null
+++ b/kexi/tools/add_column/Makefile.am
@@ -0,0 +1,5 @@
+
+bin_SCRIPTS = kexi_add_column kexi_add_column_gui
+
+message_pldir = $(kde_locale)/pl/LC_MESSAGES
+message_pl_DATA = kexi_add_column_gui_transl_pl.sh
diff --git a/kexi/tools/add_column/kexi_add_column b/kexi/tools/add_column/kexi_add_column
new file mode 100755
index 00000000..02d03de6
--- /dev/null
+++ b/kexi/tools/add_column/kexi_add_column
@@ -0,0 +1,114 @@
+#!/bin/sh
+#
+# Copyright (C) 2006 Jaroslaw Staniek <[email protected]>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+#
+
+usage {
+ echo "This script adds a new empty column to a table in a .kexi (SQLite 3)
+ database file without removing data from the table.
+
+Usage:
+ $0 database_name table_name new_column_name new_column_type
+ [new_column_caption]
+
+- {database_name}.old backup file is created before proceeding
+- database_name and table_name must exist
+- new_column_name must not exist and should be valid idetifier
+- new_column_type must be one of:
+ Byte, ShortInteger, Integer, BigInteger, Boolean, Date, DateTime, Time,
+ Float, Double, Text, LongText, BLOB (for images)
+- new_column_caption can be any text; enclose it in \" \" if you want to use
+ spaces there
+
+Example: to append a column 'photo' of type BLOB to the table 'cars', type
+ $0 db.kexi cars photo BLOB Photo"
+}
+
+exit_with_error {
+ rm -f "$temp_db"
+ echo $*
+ echo "Error."
+ exit 1
+}
+
+check {
+ [ -n "$*" ] && exit_with_error "$*"
+}
+
+ksqlite="ksqlite -noheader"
+
+if [ $# -lt 4 ] ; then
+ usage
+ exit 0
+fi
+database_name=$1
+table_name=$2
+new_column_name=$3
+new_column_type=$4
+new_column_caption=$5
+
+# get numeric value for the data type
+case $new_column_type in
+ Byte) typenum=1;;
+ ShortInteger) typenum=2;;
+ Integer) typenum=3;;
+ BigInteger) typenum=4;;
+ Boolean) typenum=5;;
+ Date) typenum=6;;
+ DateTime) typenum=7;;
+ Time) typenum=8;;
+ Float) typenum=9;;
+ Double) typenum=10;;
+ Text) typenum=11;;
+ LongText) typenum=12;;
+ BLOB) typenum=13;;
+ *) echo "Unknown type name '$new_column_type'"; exit 1;;
+esac
+
+temp_db=`mktemp "$database_name"XXXXXXXX` || exit_with_error
+cp "$database_name" "$temp_db" || exit_with_error
+msg=`echo "DROP TABLE '$table_name';" | $ksqlite "$temp_db"`
+check "$msg"
+
+# 1. Recreate table with new field appended
+msg=`echo ".schema '$table_name';" | $ksqlite "$database_name" | grep "^CREATE TABLE $table_name " | \
+ sed -e "s/);/, $new_column_name $new_column_type);/g" | $ksqlite "$temp_db"`
+check "$msg"
+
+# 2.1. Get table's ID
+table_id=`echo "SELECT o_id FROM kexi__objects WHERE o_type=1 AND o_name='$table_name';" | \
+ $ksqlite "$temp_db" || exit_with_error`
+
+# 2.2. Get the new field's order
+order=`echo "SELECT MAX(f_order)+1 FROM kexi__fields WHERE t_id=$table_id;" | $ksqlite "$temp_db" || exit_with_error`
+
+# 2.3. Add the new column information to kexi__fields metadata table
+msg=`echo "INSERT INTO kexi__fields (t_id, f_type, f_name, f_length, f_precision, f_constraints, \
+ f_options, f_default, f_order, f_caption, f_help) \
+ VALUES ($table_id, $typenum, '$new_column_name', \
+ 0, 0, 0, 0, NULL, $order, '$new_column_caption', NULL);" | $ksqlite "$temp_db"`
+check "$msg"
+
+# 3. Copy the old data
+msg=`echo ".dump '$table_name';" | $ksqlite "$database_name" | grep -v "^CREATE TABLE " | \
+ sed -e "s/\(^INSERT.*\));$/\\1, NULL);/g" | $ksqlite "$temp_db"`
+check "$msg"
+
+# 4. Copy the original database file to .old file and replace the original with the new one
+cp "$database_name" "$database_name.old" || exit_with_error
+mv "$temp_db" "$database_name" || exit_with_error
diff --git a/kexi/tools/add_column/kexi_add_column_gui b/kexi/tools/add_column/kexi_add_column_gui
new file mode 100644
index 00000000..29731d69
--- /dev/null
+++ b/kexi/tools/add_column/kexi_add_column_gui
@@ -0,0 +1,99 @@
+#!/bin/sh
+#
+# Copyright (C) 2006 Jaroslaw Staniek <[email protected]>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+#
+
+basedir=`dirname "$0"`
+
+setup_messages {
+ lang=`grep Language= ~/.kde/share/config/kdeglobals | head -n 1 | \
+ sed -e 's/Language=\(.*\):.*/\1/'`
+ if [ -z "$lang" ] ; then lang="en" ; fi
+
+ IFS=:
+ for dir in `kde-config --expandvars --path locale` ; do
+ transl_file="$dir"$lang"/LC_MESSAGES/kexi_add_column_gui_transl_$lang.sh";
+ if [ -f "$transl_file" ] ; then
+ source "$transl_file"
+ break
+ else
+ transl_file=;
+ fi
+ done
+ IFS=" "
+ if [ -z "$transl_file" ] ; then
+ transl_file="$basedir/kexi_add_column_gui_transl_$lang.sh";
+ if [ ! -f "$transl_file" ] ; then source "$transl_file"; else transl_file=; fi
+ fi
+echo $transl_file
+ if [ -z "$transl_file" ] ; then
+ # default: english messages:
+ msg_filters="*.kexi|Kexi Project stored in a file
+*.*|All files"
+ msg_select_db_file="Select database file"
+ msg_enter_table_name="Table name (without spaces):"
+ msg_enter_new_column_name="New column's name (without spaces):"
+ msg_enter_new_column_type="New column's type:"
+ msg_byte="Byte"
+ msg_short_integer="Short integer"
+ msg_integer="Integer"
+ msg_big_integer="Big integer"
+ msg_yes_no="Yes/No"
+ msg_date="Date"
+ msg_date_time="Date/Time"
+ msg_time="Time"
+ msg_float="Single precision number"
+ msg_double="Double precision number"
+ msg_text="Text"
+ msg_long_text="Long text"
+ msg_object="Object (image)"
+ msg_enter_new_column_caption="New column's caption (optional):"
+ fi
+} # /setup_messages
+
+setup_messages
+
+database_name=`kdialog --title "$msg_select_db_file" --getopenfilename . "$msg_filters"` || exit 1
+
+table_name=`kdialog --inputbox "$msg_enter_table_name"` || exit 1
+
+new_column_name=`kdialog --inputbox "$msg_enter_new_column_name"` || exit 1
+
+new_column_type=`kdialog --radiolist "$msg_enter_new_column_type " \
+Byte "$msg_byte" off \
+ShortInteger "$msg_short_integer" off \
+Integer "$msg_integer" off \
+BigInteger "$msg_big_integer" off \
+Boolean "$msg_yes_no" off \
+Date "$msg_date" off \
+DateTime "$msg_date_time" off \
+Time "$msg_time" off \
+Float "$msg_float" off \
+Double "$msg_double" off \
+Text "$msg_text" off \
+LongText "$msg_long_text" off \
+BLOB "$msg_object" off ` || exit 1
+new_column_caption=`kdialog --inputbox "$msg_enter_new_column_caption"`
+
+msg=`sh kexi_add_column "$database_name" "$table_name" "$new_column_name" \
+ "$new_column_type" "$new_column_caption" 2>&1`
+
+[ -z "$msg" ] && exit 0
+
+kdialog --error "$msg"
+exit 1
diff --git a/kexi/tools/add_column/kexi_add_column_gui_transl_pl.sh b/kexi/tools/add_column/kexi_add_column_gui_transl_pl.sh
new file mode 100644
index 00000000..974b79cf
--- /dev/null
+++ b/kexi/tools/add_column/kexi_add_column_gui_transl_pl.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+# Translation file for kexi_add_column_gui
+
+msg_filters="*.kexi|Projekt Kexi zapisany w pliku
+*.*|Wszystkie pliki"
+msg_select_db_file="Wybierz plik bazy danych"
+msg_enter_table_name="Nazwa tabeli (bez spacji):"
+msg_enter_new_column_name="Nazwa nowej kolumny (bez spacji):"
+msg_enter_new_column_type="Typ nowej kolumny:"
+msg_byte="Bajt"
+msg_short_integer="Liczba calkowita krotka"
+msg_integer="Liczba calkowita"
+msg_big_integer="Liczba calkowita wielka"
+msg_yes_no="Tak/Nie"
+msg_date="Data"
+msg_date_time="Data/Czas"
+msg_time="Czas"
+msg_float="Liczba zmiennoprzecinkowa krotka"
+msg_double="Liczba zmiennoprzecinkowa dluga"
+msg_text="Tekst"
+msg_long_text="Dlugi tekst"
+msg_object="Obiekt (obraz)"
+msg_enter_new_column_caption="Tytul nowej kolumny (opcjonalnie):"