[Dbconfig-common-changes] [dbconfig-common] r234 - in branches/sqlite: dpkg internal

Matt Brown mattb-guest at costa.debian.org
Mon May 29 12:40:29 CEST 2006


Author: mattb-guest
Date: 2006-05-29 10:40:28 +0000 (Mon, 29 May 2006)
New Revision: 234

Added:
   branches/sqlite/dpkg/config.sqlite
   branches/sqlite/dpkg/postinst.sqlite
   branches/sqlite/dpkg/postrm.sqlite
   branches/sqlite/dpkg/preinst.sqlite
   branches/sqlite/dpkg/prerm.sqlite
   branches/sqlite/internal/sqlite
Modified:
   branches/sqlite/dpkg/common
   branches/sqlite/dpkg/config
   branches/sqlite/internal/common
Log:
Initial changes to support sqlite databases
* Create lists of functionality supported by different dbtypes
* Only load debconf templates if the functionality is supported
  by the current dbtype
* Add basic SQLite backend functions


Modified: branches/sqlite/dpkg/common
===================================================================
--- branches/sqlite/dpkg/common	2006-05-29 07:49:30 UTC (rev 233)
+++ branches/sqlite/dpkg/common	2006-05-29 10:40:28 UTC (rev 234)
@@ -40,9 +40,18 @@
 	# templates common to postgresql database types
 	dbc_pgsql_templates="pgsql/method remote/host remote/newhost pgsql/app-pass pgsql/admin-user pgsql/admin-pass remote/port pgsql/authmethod-admin pgsql/authmethod-user pgsql/changeconf pgsql/manualconf db/dbname db/app-user pgsql/no-empty-passwords"
 
+	# templates common to sqlite database types
+	dbc_sqlite_templates="db/dbname"
+
 	# all dbtypes supported by dbconfig-common
-	dbc_all_supported_dbtypes="mysql pgsql"
+	dbc_all_supported_dbtypes="mysql pgsql sqlite"
 
+	# database types supporting authenticated access
+	dbc_authenticated_dbtypes="mysql pgsql"
+
+	# database types supporting remote access
+	dbc_remote_dbtypes="mysql pgsql"
+
 	###
 	### source the pre-existing config, if it exists
 	###
@@ -97,8 +106,24 @@
 		dbc_use_dbuser="false"
 		dbc_dbvendor="PostgreSQL"
 	;;
+	sqlite)
+		. /usr/share/dbconfig-common/internal/sqlite
+		dbc_createuser_cmd=''
+		dbc_checkuser_cmd='dbc_sqlite_check_user'
+		dbc_createdb_cmd='dbc_sqlite_createdb'
+		dbc_dropdb_cmd='dbc_sqlite_dropdb'
+		dbc_dropuser_cmd=''
+		dbc_sqlexec_cmd='dbc_sqlite_exec_command'
+		dbc_sqlfile_cmd='dbc_sqlite_exec_file'
+		dbc_dump_cmd='dbc_sqlite_dump'
+		dbc_register_templates="$dbc_standard_templates $dbc_sqlite_templates"
+		dbc_default_admin=""
+		dbc_default_dbuser=`whoami`;
+		dbc_use_dbuser="false"
+		dbc_dbvendor="SQLite"
+	;;
 	*)
-		dbc_register_templates="$dbc_standard_templates $dbc_mysql_templates $dbc_pgsql_templates"
+		dbc_register_templates="$dbc_standard_templates $dbc_mysql_templates $dbc_pgsql_templates $dbc_sqlite_templates"
 	;;
 	esac
 }
@@ -168,19 +193,23 @@
 	# set app user
 	db_set $dbc_package/db/app-user "$dbc_dbuser"
 
-	# set the app user password
-	db_set $dbc_package/$dbc_dbtype/app-pass "$dbc_dbpass"
+	if echo "$dbc_authenticated_dbtypes" | grep -q "$dbc_dbtype"; then
+		# set the app user password
+		db_set $dbc_package/$dbc_dbtype/app-pass "$dbc_dbpass"
 
-	# set the remote server/port
-	db_set $dbc_package/remote/host "$dbc_dbserver"
-	db_set $dbc_package/remote/port "$dbc_dbport"
+		# set the database administrator name
+		db_set $dbc_package/$dbc_dbtype/admin-user "$dbc_dbadmin"
+	fi
 
+	if echo "$dbc_remote_dbtypes" | grep -q "$dbc_dbtype"; then
+		# set the remote server/port
+		db_set $dbc_package/remote/host "$dbc_dbserver"
+		db_set $dbc_package/remote/port "$dbc_dbport"
+	fi
+
 	# set the name of the database to be created
 	db_set $dbc_package/db/dbname "$dbc_dbname"
 
-	# set the database administrator name
-	db_set $dbc_package/$dbc_dbtype/admin-user "$dbc_dbadmin"
-
 	# a few db-specific things
 	case $dbc_dbtype in
 	"pgsql")
@@ -231,22 +260,27 @@
 	# get app user
 	db_get $dbc_package/db/app-user && dbc_dbuser="$RET"
 
-	# get the app user password
-	db_get $dbc_package/$dbc_dbtype/app-pass && dbc_dbpass="$RET"
+	if echo "$dbc_authenticated_dbtypes" | grep -q "$dbc_dbtype"; then
+		# get the app user password
+		db_get $dbc_package/$dbc_dbtype/app-pass && dbc_dbpass="$RET"
 
-	# get the db server/port
-	db_get $dbc_package/remote/host && dbc_dbserver="$RET"
-	db_get $dbc_package/remote/port && dbc_dbport="$RET"
+		# get the database administrator name
+		db_get $dbc_package/$dbc_dbtype/admin-user && dbc_dbadmin="$RET"
 
+		# get the database administrator pass
+		db_get $dbc_package/$dbc_dbtype/admin-pass && dbc_dbadmpass="$RET"
+	fi
+
+	if echo "$dbc_remote_dbtypes" | grep -q "$dbc_dbtype"; then
+
+		# get the db server/port
+		db_get $dbc_package/remote/host && dbc_dbserver="$RET"
+		db_get $dbc_package/remote/port && dbc_dbport="$RET"
+	fi
+
 	# get the name of the database to be created
 	db_get $dbc_package/db/dbname && dbc_dbname="$RET"
 
-	# get the database administrator name
-	db_get $dbc_package/$dbc_dbtype/admin-user && dbc_dbadmin="$RET"
-
-	# get the database administrator pass
-	db_get $dbc_package/$dbc_dbtype/admin-pass && dbc_dbadmpass="$RET"
-
 	# a few db-specific things
 	case $dbc_dbtype in
 	"pgsql")
@@ -656,12 +690,14 @@
 ##
 dbc_postinst_cleanup(){
 	dbc_debug "dbc_postinst_cleanup() $@"
-	if [ "$dbc_remember_admin_pass" != "true" ]; then
-		dbc_forget_dbadmin_password
+	if echo "$dbc_authenticated_dbtypes" | grep -q "$dbc_dbtype"; then
+		if [ "$dbc_remember_admin_pass" != "true" ]; then
+			dbc_forget_dbadmin_password
+		fi
+		if [ "$dbc_remember_app_pass" != "true" ]; then
+			dbc_forget_app_password
+		fi
 	fi
-	if [ "$dbc_remember_app_pass" != "true" ]; then
-		dbc_forget_app_password
-	fi
 }
 
 ##

Modified: branches/sqlite/dpkg/config
===================================================================
--- branches/sqlite/dpkg/config	2006-05-29 07:49:30 UTC (rev 233)
+++ branches/sqlite/dpkg/config	2006-05-29 10:40:28 UTC (rev 234)
@@ -64,17 +64,27 @@
 			if [ "$dbc_load_include" ] && [ -f "$ifile" ]; then
 				db_input high $dbc_package/import-oldsettings || true
 				eval `dbconfig-load-include $dbc_load_include_args -f $iformat $ifile`
-				for f in database-type $dbc_dbtype/method remote/host remote/newhost remote/port pgsql/authmethod-admin pgsql/authmethod-user $dbc_dbtype/admin-user db/app-user db/dbname; do
+				for f in database-type $dbc_dbtype/method db/dbname; do
 					db_fset $dbc_package/$f seen true || true
 				done
+				if echo "$dbc_authenticated_dbtypes" | grep -q "$dbc_dbtype"; then
+					for f in pgsql/authmethod-admin pgsql/authmethod-user $dbc_dbtype/admin-user db/app-user; do
+						db_fset $dbc_package/$f seen true || true
+					done
+					db_set $dbc_package/db/app-user "$dbc_dbuser"
+					db_set $dbc_package/$dbc_dbtype/app-pass "$dbc_dbpass"
+					db_set $dbc_package/password-confirm "$dbc_dbpass"
+				fi
+				if echo "$dbc_remote_dbtypes" | grep -q "$dbc_dbtype"; then
+					for f in remote/host remote/newhost remote/port ; do
+						db_fset $dbc_package/$f seen true || true
+					done
+					db_set $dbc_package/remote/host "$dbc_dbserver"
+					db_set $dbc_package/remote/port "$dbc_dbport"
+				fi
 
 				db_set $dbc_package/database-type $dbc_dbtype
-				db_set $dbc_package/db/app-user "$dbc_dbuser"
 				db_set $dbc_package/db/dbname "$dbc_dbname"
-				db_set $dbc_package/remote/host "$dbc_dbserver"
-				db_set $dbc_package/remote/port "$dbc_dbport"
-				db_set $dbc_package/$dbc_dbtype/app-pass "$dbc_dbpass"
-				db_set $dbc_package/password-confirm "$dbc_dbpass"
 			fi
 		fi
 
@@ -152,6 +162,11 @@
 			if [ ! "$dbc_dbname" ]; then 
 				dbc_dbname=`echo $dbc_package | tr -d +-.`; 
 			fi
+			db_set $dbc_package/db/dbname "$dbc_dbname"
+		elif [ "$dbc_dbtype" = "sqlite" ]; then
+			# Set the db name to a sensible default
+			db_set $dbc_package/db/dbname "/var/lib/$dbc_package.sqlite"
+			db_input high $dbc_package/db/dbname || true
 		fi
 
 		# pre-seed any already defined values into debconf as defaults
@@ -160,101 +175,108 @@
 		fi
 		if [ "$dbc_remove" ]; then
 			db_set $dbc_package/dbconfig-remove "$dbc_remove"
-		fi      
-		if [ "$dbc_dbuser" ]; then 
-			db_set $dbc_package/db/app-user "$dbc_dbuser"
-		fi      
-		if [ "$dbc_dbpass" ]; then 
-			db_set $dbc_package/$dbc_dbtype/app-pass "$dbc_dbpass"
-			db_fset $dbc_package/$dbc_dbtype/app-pass seen true
-			db_set $dbc_package/app-password-confirm "$dbc_dbpass"
-			db_fset $dbc_package/app-password-confirm seen true
-		fi      
-		if [ "$dbc_dbname" ]; then 
-			db_set $dbc_package/db/dbname "$dbc_dbname"
-		fi      
-		if [ "$dbc_dbserver" ]; then
-			db_set $dbc_package/remote/host "$dbc_dbserver"
 		fi
-		if [ "$dbc_dbport" ]; then
-			db_set $dbc_package/remote/port "$dbc_dbport"
+		if echo "$dbc_authenticated_dbtypes" | grep -q "$dbc_dbtype"; then
+			if [ "$dbc_dbuser" ]; then 
+				db_set $dbc_package/db/app-user "$dbc_dbuser"
+			fi
+			if [ "$dbc_dbpass" ]; then 
+				db_set $dbc_package/$dbc_dbtype/app-pass "$dbc_dbpass"
+				db_fset $dbc_package/$dbc_dbtype/app-pass seen true
+				db_set $dbc_package/app-password-confirm "$dbc_dbpass"
+				db_fset $dbc_package/app-password-confirm seen true
+			fi
+			if [ "$dbc_dbadmin" ]; then
+				db_set $dbc_package/$dbc_dbtype/admin-user "$dbc_dbadmin"
+			fi
 		fi
-		if [ "$dbc_dbadmin" ]; then
-			db_set $dbc_package/$dbc_dbtype/admin-user "$dbc_dbadmin"
+		if echo "$dbc_remote_dbtypes" | grep -q "$dbc_dbtype"; then
+			if [ "$dbc_dbserver" ]; then
+				db_set $dbc_package/remote/host "$dbc_dbserver"
+			fi
+			if [ "$dbc_dbport" ]; then
+				db_set $dbc_package/remote/port "$dbc_dbport"
+			fi
+			if [ "$dbc_ssl" = "true" -a "$dbc_dbtype" = "pgsql" ]; then
+				db_set $dbc_package/pgsql/method "tcp/ip + ssl"
+			fi
+			db_input low $dbc_package/$dbc_dbtype/method || true
 		fi
-		if [ "$dbc_ssl" = "true" -a "$dbc_dbtype" = "pgsql" ]; then
-			db_set $dbc_package/pgsql/method "tcp/ip + ssl"
-		fi
-		db_input low $dbc_package/$dbc_dbtype/method || true
 	;;
 	# state 4 - do stuff based on the connection method
 	4)
 		db_get $dbc_package/$dbc_dbtype/method && dbc_method="$RET"
 
-		# if package/method == tcp/ip or tcp/ip + ssl
-		if [ "$dbc_method" != "unix socket" ]; then
-			# look at the hosts used in any other dbconfig-using
-			# package, and create a list of hosts.
-			_preconf_list=` (
-			for f in /etc/dbconfig-common/*.conf; do
-				test -f $f || continue
-				eval \`dbconfig-generate-include --dbserver=_s $f | grep -v '^#'\`
-				[ "$_s" ] && echo $_s
-			done
-			) | sort | uniq`
-			# turn the list into a comma separated list if it exists
-			# and then substitute it into the list of available hosts
-			if [ "$_preconf_list" ]; then
-				_preconf_list=`echo $_preconf_list | sed -e 's/ /, /g'`
-				_preconf_list="new host, $_preconf_list"
-				db_subst $dbc_package/remote/host hosts "$_preconf_list"
-				# and then ask them for one
-				db_input high $dbc_package/remote/host || true
+		if echo "$dbc_remote_dbtypes" | grep -q "$dbc_dbtype"; then
+			# if package/method == tcp/ip or tcp/ip + ssl
+			if [ "$dbc_method" != "unix socket" ]; then
+				# look at the hosts used in any other dbconfig-using
+				# package, and create a list of hosts.
+				_preconf_list=` (
+				for f in /etc/dbconfig-common/*.conf; do
+					test -f $f || continue
+					eval \`dbconfig-generate-include --dbserver=_s $f | grep -v '^#'\`
+					[ "$_s" ] && echo $_s
+				done
+				) | sort | uniq`
+				# turn the list into a comma separated list if it exists
+				# and then substitute it into the list of available hosts
+				if [ "$_preconf_list" ]; then
+					_preconf_list=`echo $_preconf_list | sed -e 's/ /, /g'`
+					_preconf_list="new host, $_preconf_list"
+					db_subst $dbc_package/remote/host hosts "$_preconf_list"
+					# and then ask them for one
+					db_input high $dbc_package/remote/host || true
+				fi
+			# but if it is unix socket, forget all the host stuff
+			else
+				db_reset $dbc_package/remote/host || true
+				db_reset $dbc_package/remote/newhost || true
+				db_reset $dbc_package/remote/port || true
 			fi
-		# but if it is unix socket, forget all the host stuff
-		else
-			db_reset $dbc_package/remote/host || true
-			db_reset $dbc_package/remote/newhost || true
-			db_reset $dbc_package/remote/port || true
 		fi
 	;;
 	# state 5 - get host / port info if necessary
 	5)
-		if [ "$dbc_method" != "unix socket" ]; then
-			if [ "$_preconf_list" ]; then
-				db_get $dbc_package/remote/host 
-				host=$RET
-			fi
+		if echo "$dbc_remote_dbtypes" | grep -q "$dbc_dbtype"; then
+			if [ "$dbc_method" != "unix socket" ]; then
+				if [ "$_preconf_list" ]; then
+					db_get $dbc_package/remote/host 
+					host=$RET
+				fi
 
-			# if they've chosen "new host" or the host list was empty
-			if [ ! "$host" -o "$host" = "new host" ]; then
-				# prompt them for a new hostname
-				db_input high $dbc_package/remote/newhost || true
+				# if they've chosen "new host" or the host list was empty
+				if [ ! "$host" -o "$host" = "new host" ]; then
+					# prompt them for a new hostname
+					db_input high $dbc_package/remote/newhost || true
+				fi
 			fi
 		fi
 	;;
 	# state 6 - do stuff based on host/port selection
 	6)
-		if [ "$dbc_method" != "unix socket" ]; then
-			if [ ! "$host" -o "$host" = "new host" ]; then
-				db_get $dbc_package/remote/newhost 
-				newhost="$RET"
+		if echo "$dbc_remote_dbtypes" | grep -q "$dbc_dbtype"; then
+			if [ "$dbc_method" != "unix socket" ]; then
+				if [ ! "$host" -o "$host" = "new host" ]; then
+					db_get $dbc_package/remote/newhost 
+					newhost="$RET"
 
-				# add the new host to the existing list of hosts
-				db_metaget $dbc_package/remote/host choices
-				oldhosts="$RET"
-				db_subst $dbc_package/remote/host hosts "$oldhosts, $newhost"
-				db_set $dbc_package/remote/host "$newhost"
-				db_fset $dbc_package/remote/host seen true
-			else
-				# set the "newhost" to the selected host, because
-				# the second time through the configure script we'll
-				# need this set
-				db_set $dbc_package/remote/newhost "$host"
+					# add the new host to the existing list of hosts
+					db_metaget $dbc_package/remote/host choices
+					oldhosts="$RET"
+					db_subst $dbc_package/remote/host hosts "$oldhosts, $newhost"
+					db_set $dbc_package/remote/host "$newhost"
+					db_fset $dbc_package/remote/host seen true
+				else
+					# set the "newhost" to the selected host, because
+					# the second time through the configure script we'll
+					# need this set
+					db_set $dbc_package/remote/newhost "$host"
+				fi
+
+				# on what port?
+				db_input low $dbc_package/remote/port || true
 			fi
-
-			# on what port?
-			db_input low $dbc_package/remote/port || true
 		fi
 	;;
 	# state 7 - pgsql specific auth stuff, part 1
@@ -294,18 +316,22 @@
 			fi
 		fi
 
-		# who's the admin user (is there any reason to even ask this?)
-		# TODO: should there be a difference between the local and remote admin?
-		db_input low $dbc_package/$dbc_dbtype/admin-user || true
+		if echo "$dbc_authenticated_dbtypes" | grep -q "$dbc_dbtype"; then
 
-		if [ "$need_adminpw" != "false" ]; then
-			dbc_get_admin_pass
-		fi
+			# who's the admin user (is there any reason to even ask this?)
+			# TODO: should there be a difference between the local and 
+			# remote admin?
+			db_input low $dbc_package/$dbc_dbtype/admin-user || true
 
-		db_input low $dbc_package/db/app-user || true
+			if [ "$need_adminpw" != "false" ]; then
+				dbc_get_admin_pass
+			fi
 
-		if [ "$need_userpw" != "false" ]; then
-			dbc_get_app_pass
+			db_input low $dbc_package/db/app-user || true
+
+			if [ "$need_userpw" != "false" ]; then
+				dbc_get_app_pass
+			fi
 		fi
 
 		# get the name of the database to use

Added: branches/sqlite/dpkg/config.sqlite
===================================================================
--- branches/sqlite/dpkg/config.sqlite	2006-05-29 07:49:30 UTC (rev 233)
+++ branches/sqlite/dpkg/config.sqlite	2006-05-29 10:40:28 UTC (rev 234)
@@ -0,0 +1,2 @@
+dbc_hardcoded_dbtype=sqlite
+. /usr/share/dbconfig-common/dpkg/config $@

Added: branches/sqlite/dpkg/postinst.sqlite
===================================================================
--- branches/sqlite/dpkg/postinst.sqlite	2006-05-29 07:49:30 UTC (rev 233)
+++ branches/sqlite/dpkg/postinst.sqlite	2006-05-29 10:40:28 UTC (rev 234)
@@ -0,0 +1,2 @@
+dbc_hardcoded_dbtype=sqlite
+. /usr/share/dbconfig-common/dpkg/postinst $@

Added: branches/sqlite/dpkg/postrm.sqlite
===================================================================
--- branches/sqlite/dpkg/postrm.sqlite	2006-05-29 07:49:30 UTC (rev 233)
+++ branches/sqlite/dpkg/postrm.sqlite	2006-05-29 10:40:28 UTC (rev 234)
@@ -0,0 +1,2 @@
+dbc_hardcoded_dbtype=sqlite
+. /usr/share/dbconfig-common/dpkg/postrm $@

Added: branches/sqlite/dpkg/preinst.sqlite
===================================================================
--- branches/sqlite/dpkg/preinst.sqlite	2006-05-29 07:49:30 UTC (rev 233)
+++ branches/sqlite/dpkg/preinst.sqlite	2006-05-29 10:40:28 UTC (rev 234)
@@ -0,0 +1,2 @@
+dbc_hardcoded_dbtype=sqlite
+. /usr/share/dbconfig-common/dpkg/preinst $@

Added: branches/sqlite/dpkg/prerm.sqlite
===================================================================
--- branches/sqlite/dpkg/prerm.sqlite	2006-05-29 07:49:30 UTC (rev 233)
+++ branches/sqlite/dpkg/prerm.sqlite	2006-05-29 10:40:28 UTC (rev 234)
@@ -0,0 +1,2 @@
+dbc_hardcoded_dbtype=sqlite
+. /usr/share/dbconfig-common/dpkg/prerm $@

Modified: branches/sqlite/internal/common
===================================================================
--- branches/sqlite/internal/common	2006-05-29 07:49:30 UTC (rev 233)
+++ branches/sqlite/internal/common	2006-05-29 10:40:28 UTC (rev 234)
@@ -127,6 +127,14 @@
 				return 1
 			fi
 		;;
+		"sqlite")
+			if ! which sqlite >/dev/null; then
+				dbc_error="No sqlite client to execute.  (have
+				       you installed the sqlite package?"
+				dbc_logline "sanity check failed for sqlite"
+				return 1
+			fi
+		;;
 		"createdb")
 			if ! which createdb >/dev/null; then
 				dbc_error="No pgsql createdb to execute.  (have

Added: branches/sqlite/internal/sqlite
===================================================================
--- branches/sqlite/internal/sqlite	2006-05-29 07:49:30 UTC (rev 233)
+++ branches/sqlite/internal/sqlite	2006-05-29 10:40:28 UTC (rev 234)
@@ -0,0 +1,147 @@
+###
+### sqlite bindings for dbconfig-common
+###
+### Author:     Matt Brown <debian at mattb.net.nz>
+###
+###	all variables and functions fall under the namespace "dbc_foo" and
+###	"_dbc_foo", depending on whether or not they are "external"
+###
+
+# get some common functions
+. /usr/share/dbconfig-common/internal/common
+
+##
+## execute a file with sqlite commands
+##
+dbc_sqlite_exec_file(){
+	local l_sqlfile l_retval l_error l_dbname l_errfile
+	l_sqlfile=$1
+	l_errfile=`mktemp -t dbconfig-common_sql_exec_error.XXXXXX`
+
+	if [ ! "$l_sqlfile" ]; then
+		dbc_error="no file supplied to execute"
+		dbc_log="no file supplied to execute"
+		return 1
+	fi
+
+	sqlite $dbc_dbname < "$l_sqlfile"
+	retval=$?
+	return $retval
+}
+
+##
+## execute a specific sqlite command
+##
+##	note this is done without passing any info on the cmdline,
+##  including the command itself
+##
+dbc_sqlite_exec_command(){
+	local statement l_sqlfile l_retval
+	statement=$@
+	l_retval=0
+	l_sqlfile=`mktemp -t dbconfig-common_sqlfile.XXXXXX`
+	cat << EOF > $l_sqlfile
+$statement
+EOF
+	dbc_sqlite_exec_file "$l_sqlfile"
+	l_retval=$?
+	rm -f "$l_sqlfile"
+	return $l_retval
+}
+
+##
+## check for the existance of a specified database
+##
+_dbc_sqlite_check_database(){
+	local dbc_dbname
+	dbc_dbname=$1
+	if test -f "$dbc_dbname"; then
+		return 0
+	else
+		return 1
+	fi
+}
+
+##
+## check for access for a specific user
+##
+##	this works by checking the filesystem permissions connect
+##
+dbc_sqlite_check_user(){
+	# XXX: TODO
+	return 0
+}
+
+##
+## creates a new sqlite database file
+##
+##
+dbc_sqlite_createdb(){
+	local ret l_dbname _dbc_nodb
+	dbc_status=error
+
+	_dbc_sanity_check dbname sqlite || return 1
+
+	dbc_logpart "creating database $dbc_dbname:"
+
+	if _dbc_sqlite_check_database "$dbc_dbname"; then
+		dbc_logline "already exists"
+		dbc_status=nothing
+	else
+		_dbc_nodb="yes" dbc_sqlite_exec_command ".schema"
+		ret=$?
+		_dbc_nodb=""
+		if [ "$ret" = "0" ]; then
+			dbc_logline "success"
+			dbc_logpart "verifying database $dbc_dbname exists:"
+			if ! _dbc_sqlite_check_database "$dbc_dbname"; then
+				dbc_logline "failed"
+			else
+				dbc_logline "success"
+				dbc_status=create
+			fi
+		else
+			dbc_logline "failed"
+		fi
+	fi
+}
+
+##
+## drops the sqlite database file by removing it from the disk
+##
+##
+dbc_mysql_dropdb(){
+	dbc_status=error
+
+	_dbc_sanity_check dbname || return 1
+
+	dbc_logpart "dropping database $dbc_dbname:"
+
+	if _dbc_sqlite_check_database "$dbc_dbname"; then
+		if rm -f "$dbc_dbname"; then
+			dbc_logline "success"
+			dbc_logpart "verifying database $dbc_dbname was dropped:"
+			if _dbc_sqlite_check_database "$dbc_dbname"; then
+				dbc_logline "failed"
+			else
+				dbc_logline "success"
+				dbc_status=drop
+			fi
+		else
+			dbc_logline "failed"
+		fi
+	else
+		dbc_status=nothing
+		dbc_logline "database does not exist"
+	fi
+}
+
+##
+## dump a sqlite database 
+##
+dbc_sqlite_dump(){
+	local dumperr
+	_dbc_sanity_check dbname sqlite || return 1
+	dbc_sqlite_exec_command ".dump"
+	return $?
+}




More information about the Dbconfig-common-changes mailing list