libgda r3218 - in trunk: . WixInstaller doc/C doc/C/tmpl libgda libgda/sql-parser libgda/sqlite libgda/sqlite/virtual providers/mysql samples/SqlParserConsole tests tools
- From: vivien svn gnome org
- To: svn-commits-list gnome org
- Subject: libgda r3218 - in trunk: . WixInstaller doc/C doc/C/tmpl libgda libgda/sql-parser libgda/sqlite libgda/sqlite/virtual providers/mysql samples/SqlParserConsole tests tools
- Date: Mon, 29 Sep 2008 19:09:39 +0000 (UTC)
Author: vivien
Date: Mon Sep 29 19:09:39 2008
New Revision: 3218
URL: http://svn.gnome.org/viewvc/libgda?rev=3218&view=rev
Log:
2008-09-29 Vivien Malerba <malerba gnome-db org>
* tools/gda-sql.c:
- added some commands to manage data sources
- improved providers list and DSN list output
- allow executing files which start with ~ (HOME dir)
* libgda/gda-config.c: make sure the DSN info records a boolean for its
is_system attribute
* WixInstaller/make-zip-exe.sh: now generate 3 ZIP files:
- one for the runtime DLLs
- one with the dev. files (includes, .pc, ...)
- one with the runtime dependencies (Glib, database's native DLLs, ...)
* libgda/gda-data-proxy.c:
* libgda/gda-meta-struct-io.c:
* libgda/gda-meta-struct.h:
* libgda/gda-statement.c:
* libgda/gda-util.c:
* libgda/sql-parser/gda-sql-parser.h:
* libgda/sqlite/virtual/gda-vprovider-data-model.c:
* tests/gda-ddl-creator.c:
* tools/command-exec.c:
* libgda/sql-parser/gda-statement-struct-util.[ch]: export some new symbols, for bug #541991
* libgda/sqlite/gda-sqlite-meta.c: correctly handle multiple FK constraints to the same
table
* samples/SqlParserConsole/graph.c: make the example work again
* providers/mysql/gda-mysql-provider.c: partially integrate the new
GDA_STATEMENT_MODEL_ALLOW_NOPARAM (Carlos Savoretti)
* doc/C: doc updates
2008-09-29 Massimo Cora' <maxcvs email it>
* libgda/gda-holder.c (gda_holder_init), (gda_holder_copy),
(gda_holder_dispose), (real_gda_holder_set_value),
(real_gda_holder_set_const_value), (gda_holder_take_static_value),
(gda_holder_force_invalid), (gda_holder_set_value_to_default),
(gda_holder_set_full_bind):
* libgda/gda-holder.h:
added function gda_holder_take_static_value () to permit a quicker use of GValues
without allocation/deallocation. On my tests I can gain 20ms on 100 queries.
Modified:
trunk/ChangeLog
trunk/NEWS
trunk/WixInstaller/make-zip-exe.sh
trunk/doc/C/libgda-4.0-sections.txt
trunk/doc/C/tmpl/gda-meta-struct.sgml
trunk/doc/C/tmpl/gda-sql-parser.sgml
trunk/libgda/gda-config.c
trunk/libgda/gda-data-proxy.c
trunk/libgda/gda-holder.c
trunk/libgda/gda-holder.h
trunk/libgda/gda-meta-struct-io.c
trunk/libgda/gda-meta-struct.c
trunk/libgda/gda-meta-struct.h
trunk/libgda/gda-statement.c
trunk/libgda/gda-util.c
trunk/libgda/sql-parser/gda-sql-parser.h
trunk/libgda/sql-parser/gda-statement-struct-util.c
trunk/libgda/sql-parser/gda-statement-struct-util.h
trunk/libgda/sqlite/gda-sqlite-meta.c
trunk/libgda/sqlite/virtual/gda-vprovider-data-model.c
trunk/providers/mysql/gda-mysql-provider.c
trunk/samples/SqlParserConsole/graph.c
trunk/tests/gda-ddl-creator.c
trunk/tools/command-exec.c
trunk/tools/gda-sql.c
Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS (original)
+++ trunk/NEWS Mon Sep 29 19:09:39 2008
@@ -1,5 +1,5 @@
- - bug fixes: #508407, #552708
+ - bug fixes: #508407, #552708, #90751
libgda 3.99.4, 2008-09-16
Modified: trunk/WixInstaller/make-zip-exe.sh
==============================================================================
--- trunk/WixInstaller/make-zip-exe.sh (original)
+++ trunk/WixInstaller/make-zip-exe.sh Mon Sep 29 19:09:39 2008
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
#
#
@@ -17,36 +17,38 @@
cross_path=/fillme
depend_path=/local/Win32
prefix=/fillme
-version=3.99.5
-
+version=`date +%Y%m%d`
#
# no modification below
#
current_dir=`pwd`
-archive=${current_dir}/gda-sql-${version}.zip
-
+archive=${current_dir}/libgda-${version}.zip
+archive_dev=${current_dir}/libgda-dev-${version}.zip
+archive_ext=${current_dir}/libgda-dep-${version}.zip
# remove current archive if it exists
-rm -f $archive
+rm -f $archive $archive_dev $archive_ext
#
# Takes 3 arguments:
-# $1 = the prefix directory where files are located
-# $2 = the prefix under $1 where all the files are
-# $3 = a list of files physically in $1/$2/
+# $1 = the archive name
+# $2 = the prefix directory where files are located
+# $3 = the prefix under $1 where all the files are
+# $4 = a list of files physically in $1/$2/
#
function add_files_to_zip
{
- dir=$1
- subdir=$2
- files=$3
+ arch=$1
+ dir=$2
+ subdir=$3
+ files=$4
pushd $dir >& /dev/null
for item in ${files[*]}
do
echo "Adding file $dir/$subdir/$item"
- zip ${archive} $subdir/$item >& /dev/null
+ zip ${arch} $subdir/$item >& /dev/null
if [ $? -ne 0 ]
then
echo "Error (file may noy exist)"
@@ -60,45 +62,90 @@
# dependencies DLLs
#
files=(charset.dll iconv.dll intl.dll libgio-2.0-0.dll libglib-2.0-0.dll libgmodule-2.0-0.dll libgobject-2.0-0.dll libgthread-2.0-0.dll libxml2.dll zlib1.dll)
-add_files_to_zip ${depend_path}/gtk bin $files
+add_files_to_zip $archive_ext ${depend_path}/gtk bin $files
files=(libdb47.dll msvcp80.dll msvcr80.dll)
-add_files_to_zip ${depend_path}/bdb bin $files
+add_files_to_zip $archive_ext ${depend_path}/bdb bin $files
files=(libmdb-0.dll)
-add_files_to_zip ${depend_path}/mdb bin $files
+add_files_to_zip $archive_ext ${depend_path}/mdb bin $files
files=(libmySQL.dll)
-add_files_to_zip ${depend_path}/mysql bin $files
+add_files_to_zip $archive_ext ${depend_path}/mysql bin $files
files=(libpq.dll comerr32.dll gssapi32.dll k5sprt32.dll krb5_32.dll libeay32.dll libiconv2.dll libintl3.dll msvcr71.dll pgaevent.dll ssleay32.dll)
-add_files_to_zip ${depend_path}/pgsql bin $files
+add_files_to_zip $archive_ext ${depend_path}/pgsql bin $files
#
# dependencies from the cross compilation environment
#
files=(readline5.dll)
-add_files_to_zip $cross_path bin $files
+add_files_to_zip $archive $cross_path bin $files
#
# Libgda's files
#
files=(bdb_specs_dsn.xml information_schema.xml mdb_specs_dsn.xml mysql_specs_add_column.xml mysql_specs_create_db.xml mysql_specs_create_index.xml mysql_specs_create_table.xml mysql_specs_create_view.xml mysql_specs_drop_column.xml mysql_specs_drop_db.xml mysql_specs_drop_index.xml mysql_specs_drop_table.xml mysql_specs_drop_view.xml mysql_specs_dsn.xml mysql_specs_rename_table.xml postgres_specs_add_column.xml postgres_specs_create_db.xml postgres_specs_create_index.xml postgres_specs_create_table.xml postgres_specs_create_view.xml postgres_specs_drop_column.xml postgres_specs_drop_db.xml postgres_specs_drop_index.xml postgres_specs_drop_table.xml postgres_specs_drop_view.xml postgres_specs_dsn.xml postgres_specs_rename_table.xml sqlite_specs_add_column.xml sqlite_specs_create_db.xml sqlite_specs_create_index.xml sqlite_specs_create_table.xml sqlite_specs_create_view.xml sqlite_specs_drop_db.xml sqlite_specs_drop_index.xml sqlite_specs_drop_table.xml sqlite_specs_drop_view
.xml sqlite_specs_dsn.xml sqlite_specs_rename_table.xml)
-add_files_to_zip $prefix share/libgda-4.0 $files
+add_files_to_zip $archive $prefix share/libgda-4.0 $files
files=(libgda-paramlist.dtd libgda-array.dtd libgda-server-operation.dtd)
-add_files_to_zip $prefix share/libgda-4.0/dtd $files
+add_files_to_zip $archive $prefix share/libgda-4.0/dtd $files
files=(config sales_test.db)
-add_files_to_zip $prefix etc/libgda-4.0 $files
+add_files_to_zip $archive $prefix etc/libgda-4.0 $files
-files=(gda-sql-4.0.exe gda-test-connection-4.0.exe libgda-4.0-4.dll)
-add_files_to_zip $prefix bin $files
+files=(gda-sql-4.0.exe gda-test-connection-4.0.exe libgda-4.0-4.dll libgda-report-4.0-4.dll)
+add_files_to_zip $archive $prefix bin $files
files=(libgda-sqlite.dll libgda-postgres.dll libgda-mysql.dll libgda-mdb.dll libgda-bdb.dll)
-add_files_to_zip $prefix lib/libgda-4.0/providers $files
+add_files_to_zip $archive $prefix lib/libgda-4.0/providers $files
+
+#
+# includes
+#
+files=(gda-batch.h gda-blob-op.h gda-column.h gda-config.h gda-connection-event.h gda-connection.h gda-connection-private.h gda-data-access-wrapper.h gda-data-comparator.h gda-data-handler.h gda-data-model-array.h gda-data-model-bdb.h gda-data-model-dir.h gda-data-model-extra.h gda-data-model.h gda-data-model-import.h gda-data-model-iter-extra.h gda-data-model-iter.h gda-data-model-private.h gda-data-proxy.h gda-data-select.h gda-debug-macros.h gda-decl.h gda-easy.h gda-enums.h gda-enum-types.h gda-holder.h gda-lockable.h gda-log.h gda-marshal.h gda-meta-store.h gda-meta-struct.h gda-mutex.h gda-quark-list.h gda-row.h gda-server-operation.h gda-server-provider-extra.h gda-server-provider.h gda-server-provider-private.h gda-set.h gda-statement-extra.h gda-statement.h gda-threader.h gda-transaction-status.h gda-transaction-status-private.h gda-util.h gda-value.h gda-xa-transaction.h libgda.h)
+add_files_to_zip $archive_dev $prefix include/libgda-4.0/libgda $files
+
+files=(gda-sqlite-provider.h)
+add_files_to_zip $archive_dev $prefix include/libgda-4.0/libgda/sqlite $files
+
+files=(gda-handler-bin.h gda-handler-boolean.h gda-handler-numerical.h gda-handler-string.h gda-handler-time.h gda-handler-type.h)
+add_files_to_zip $archive_dev $prefix include/libgda-4.0/libgda/handlers $files
+
+files=(gda-report-docbook-document.h gda-report-document.h gda-report-engine.h gda-report-rml-document.h libgda-report.h)
+add_files_to_zip $archive_dev $prefix include/libgda-4.0/libgda-report $files
+
+files=(gda-data-select-priv.h gda-pstmt.h)
+add_files_to_zip $archive_dev $prefix include/libgda-4.0/providers-support $files
+
+files=(gda-sql-parser-enum-types.h gda-sql-parser.h gda-sql-statement.h gda-statement-struct-compound.h gda-statement-struct-decl.h gda-statement-struct-delete.h gda-statement-struct.h gda-statement-struct-insert.h gda-statement-struct-parts.h gda-statement-struct-pspec.h gda-statement-struct-select.h gda-statement-struct-trans.h gda-statement-struct-unknown.h gda-statement-struct-update.h gda-statement-struct-util.h)
+add_files_to_zip $archive_dev $prefix include/libgda-4.0/sql-parser $files
+
+files=(gda-vconnection-data-model.h gda-vconnection-hub.h gda-virtual-connection.h gda-virtual-provider.h gda-vprovider-data-model.h gda-vprovider-hub.h libgda-virtual.h)
+add_files_to_zip $archive_dev $prefix include/libgda-4.0/virtual $files
+
+#
+# PC files
+#
+files=(libgda-4.0.pc libgda-bdb-4.0.pc libgda-mdb-4.0.pc libgda-mysql-4.0.pc libgda-postgres-4.0.pc libgda-report-4.0.pc libgda-sqlite-4.0.pc libgda-xslt-4.0.pc)
+add_files_to_zip $archive_dev $prefix lib/pkgconfig $files
+
+#
+# static libs
+#
+files=(libgda-4.0.a libgda-4.0.dll.a libgda-report-4.0.a libgda-report-4.0.dll.a)
+add_files_to_zip $archive_dev $prefix lib $files
+
+#
+# doc
+#
+files=(architecture.html architecture.png ch05s03.html ch06s02.html ch06s03.html ch07s02.html ch07s03.html ch07s06.html ch09s02.html ch09s06.html ch09s07.html ch09s09.html ch09s10.html ch09s11.html ch10.html ch17.html ch25.html ch28.html ch29s02.html ch29s03.html ch30s02.html ch31s02.html ch31s03.html ch33s02.html ch33s03.html ch33s04.html ch33s05.html ch33s06.html ch33s07.html ch33s08.html ch33s10.html compiling.html connection.html connections.html data_conv.html data-model.html data_models.html DataModels.png data_proxy1.png data_proxy2.png data_proxy3.png data_proxy4.png data_proxy5.png data-select.html data_validation_holder.png data_validation_proxy.png data_validation_set.png ddl_example.html fdl.html fdl-section10.html fdl-section1.html fdl-section2.html fdl-section3.html fdl-section4.html fdl-section5.html fdl-section6.html fdl-section7.html fdl-section8.html fdl-section9.html fdl-using.html features.html GdaBatch.html GdaBlobOp.html GdaColumn.html GdaConnectionEven
t.html GdaConnection.html GdaDataAccessWrapper.html GdaDataModelArray.html GdaDataModelBdb.html GdaDataModelDir.html GdaDataModel.html GdaDataModelImport.html GdaDataModelIter.html GdaDataModelIter.png GdaDataProxy.html GdaDataSelect.html gda-dict.html GdaHandlerBin.html GdaHandlerBoolean.html GdaHandlerNumerical.html GdaHandlerString.html GdaHandlerTime.html GdaHandlerType.html GdaHolder.html GdaLockable.html GdaMetaStoreCustomData.html GdaMetaStore.html GdaMetaStruct.html GdaPStmt.html GdaReportDocbookDocument.html GdaReportDocument.html GdaReportEngine.html GdaReportRmlDocument.html GdaRow.html GdaServerOperation.html GdaServerProvider.html GdaSet.html gda-sql-graph.png gda-sql.html gda-sql-manual-icommands.html gda-sql-manual-open.html gda-sql-manual-run.html GdaSqlParser.html GdaStatement.html GdaThreader.html GdaTransactionStatus.html GdaVconnectionDataModel.html GdaVconnectionHub.html GdaVirtualConnection.html GdaVirtualProvider.html GdaVproviderDataModel.html GdaVpro
viderHub.html getting_started.html home.png howto-exec-non-select.html howto-exec-select.html howto.html howto-meta1.html howto-modify-select.html index.html index.sgml information_schema.html information_schema.png init_config.html installation-configuring.html installation.html installation-installing.html introduction.html i_s_data_types.png ix01.html left.png libgda-40-Configuration.html libgda-40-Convenience-functions.html libgda-40-Default-Data-handlers.html libgda-4.0.devhelp libgda-4.0.devhelp2 libgda-40-GdaDataComparator.html libgda-40-GdaMutex.html libgda-40-GdaSqlStatement.html libgda-40-Gda-Value.html libgda-40-GdaXaTransaction.html libgda-40-Libgda-Initialization.html libgda-40-Logging.html libgda-40-Misc-API.html libgda-40-Quark-lists.html libgda-40-Subclassing-GdaDataSelect.html libgda-40-Utility-functions.html libgda-list-server-op.html libgda-provider-blobop.html libgda-provider-class.html libgda-provider-pack.html libgda-provider-recordset.html libgda-repor
ts-introduction.html libgda-sql.html libgda-tools-introduction.html libgda-tools-list-config.html libgda-tools-test-connection.html libgda-xslt-api.html libgda-xslt-introduction.html limitations.html limitations_mysql.html limitations_oracle.html limitations_postgres.html limitations_sqlite.html main_example.html managing-errors.html MetaStore1.png MetaStore2.png migration-1.html migration-2-dict.html migration-2-exec.html migration-2.html misc.html other_examples.html part_begin.html part_index.html part_libgda_api.html part_libgda-reports.html part_libgda-xslt.html part_providers.html parts.png part_tools.html prov-metadata.html psupport.html right.png stmt-compound.png stmt-insert1.png stmt-insert2.png stmt-select.png stmt-unknown.png stmt-update.png style.css transactions.html up.png virtual_connection.html writable_data_model.png)
+add_files_to_zip $archive_dev $prefix share/gtk-doc/html/libgda-4.0 $files
#
# The End
#
-echo "Archive written to ${archive}"
+echo "Archives written to:"
+echo " ${archive}"
+echo " ${archive_dev}"
+echo " ${archive_ext}"
Modified: trunk/doc/C/libgda-4.0-sections.txt
==============================================================================
--- trunk/doc/C/libgda-4.0-sections.txt (original)
+++ trunk/doc/C/libgda-4.0-sections.txt Mon Sep 29 19:09:39 2008
@@ -1112,6 +1112,10 @@
gda_sql_parser_lock
gda_sql_parser_trylock
gda_sql_parser_unlock
+<SUBSECTION>
+gda_sql_identifier_needs_quotes
+gda_sql_identifier_add_quotes
+gda_sql_identifier_remove_quotes
<SUBSECTION Standard>
GDA_IS_SQL_PARSER
GDA_SQL_PARSER
@@ -1329,6 +1333,7 @@
gda_meta_struct_complement
gda_meta_struct_complement_schema
gda_meta_struct_complement_default
+gda_meta_struct_complement_depend
GdaMetaSortType
gda_meta_struct_sort_db_objects
gda_meta_struct_get_all_db_objects
Modified: trunk/doc/C/tmpl/gda-meta-struct.sgml
==============================================================================
--- trunk/doc/C/tmpl/gda-meta-struct.sgml (original)
+++ trunk/doc/C/tmpl/gda-meta-struct.sgml Mon Sep 29 19:09:39 2008
@@ -139,7 +139,7 @@
</para>
<para>
Note: @obj_catalog, @obj_schema, @obj_name, @obj_short_name and @obj_full_name are case sensitive:
- one must call _identifier_needs_quotes() to know if is it is necessary to surround by double quotes
+ one must call gda_sql_identifier_needs_quotes() to know if is it is necessary to surround by double quotes
before using in an SQL statement
</para>
@@ -292,6 +292,17 @@
@Returns:
+<!-- ##### FUNCTION gda_meta_struct_complement_depend ##### -->
+<para>
+
+</para>
+
+ mstruct:
+ dbo:
+ error:
+ Returns:
+
+
<!-- ##### ENUM GdaMetaSortType ##### -->
<para>
Modified: trunk/doc/C/tmpl/gda-sql-parser.sgml
==============================================================================
--- trunk/doc/C/tmpl/gda-sql-parser.sgml (original)
+++ trunk/doc/C/tmpl/gda-sql-parser.sgml Mon Sep 29 19:09:39 2008
@@ -153,3 +153,21 @@
@Returns:
+<!-- ##### FUNCTION gda_sql_identifier_needs_quotes ##### -->
+<para>
+
+</para>
+
+ str:
+ Returns:
+
+
+<!-- ##### FUNCTION gda_sql_identifier_add_quotes ##### -->
+<para>
+
+</para>
+
+ str:
+ Returns:
+
+
Modified: trunk/libgda/gda-config.c
==============================================================================
--- trunk/libgda/gda-config.c (original)
+++ trunk/libgda/gda-config.c Mon Sep 29 19:09:39 2008
@@ -792,7 +792,7 @@
if (info->is_system != einfo->is_system) {
save_system = TRUE;
save_user = TRUE;
- einfo->is_system = info->is_system;
+ einfo->is_system = info->is_system ? TRUE : FALSE;
}
g_signal_emit (unique_instance, gda_config_signals[DSN_CHANGED], 0, einfo);
}
@@ -807,7 +807,7 @@
einfo->description = g_strdup (info->description);
if (info->auth_string)
einfo->auth_string = g_strdup (info->auth_string);
- einfo->is_system = info->is_system;
+ einfo->is_system = info->is_system ? TRUE : FALSE;
unique_instance->priv->dsn_list = g_slist_insert_sorted (unique_instance->priv->dsn_list, einfo,
(GCompareFunc) data_source_info_compare);
Modified: trunk/libgda/gda-data-proxy.c
==============================================================================
--- trunk/libgda/gda-data-proxy.c (original)
+++ trunk/libgda/gda-data-proxy.c Mon Sep 29 19:09:39 2008
@@ -2704,7 +2704,7 @@
GdaColumn *col = gda_data_model_describe_column (model, colnum);
const gchar *cname = gda_column_get_name (col);
if (cname && *cname) {
- if (_identifier_needs_quotes (cname))
+ if (gda_sql_identifier_needs_quotes (cname))
g_value_take_string (expr->value,
g_strdup_printf ("\"%s\"", cname));
else
@@ -2962,7 +2962,7 @@
cname = gda_column_get_name (gda_data_model_describe_column ((GdaDataModel*) proxy, col));
if (cname && *cname) {
- if (_identifier_needs_quotes (cname))
+ if (gda_sql_identifier_needs_quotes (cname))
colname = g_strdup_printf ("\"%s\"", cname);
else
colname = g_strdup (cname);
Modified: trunk/libgda/gda-holder.c
==============================================================================
--- trunk/libgda/gda-holder.c (original)
+++ trunk/libgda/gda-holder.c Mon Sep 29 19:09:39 2008
@@ -93,6 +93,7 @@
gboolean invalid_forced;
gboolean valid;
+ gboolean is_freeable;
GValue *value;
GValue *default_value; /* CAN be either NULL or of any type */
@@ -267,6 +268,7 @@
holder->priv->invalid_forced = FALSE;
holder->priv->valid = TRUE;
holder->priv->default_forced = FALSE;
+ holder->priv->is_freeable = TRUE;
holder->priv->value = NULL;
holder->priv->default_value = NULL;
@@ -337,6 +339,7 @@
/* direct settings */
holder->priv->invalid_forced = orig->priv->invalid_forced;
holder->priv->valid = orig->priv->valid;
+ holder->priv->is_freeable = orig->priv->is_freeable;
holder->priv->default_forced = orig->priv->default_forced;
if (orig->priv->value)
holder->priv->value = gda_value_copy (orig->priv->value);
@@ -464,8 +467,9 @@
holder->priv->g_type = G_TYPE_INVALID;
- if (holder->priv->value) {
- gda_value_free (holder->priv->value);
+ if (holder->priv->value) {
+ if (holder->priv->is_freeable)
+ gda_value_free (holder->priv->value);
holder->priv->value = NULL;
}
@@ -793,23 +797,23 @@
if (!value || !g_ascii_strcasecmp (value, "NULL"))
return gda_holder_set_value (holder, NULL, error);
- else {
- GValue *gdaval = NULL;
+ else {
+ GValue *gdaval = NULL;
if (!dh)
dh = gda_get_default_handler (holder->priv->g_type);
- if (dh)
- gdaval = gda_data_handler_get_value_from_str (dh, value, holder->priv->g_type);
+ if (dh)
+ gdaval = gda_data_handler_get_value_from_str (dh, value, holder->priv->g_type);
- if (gdaval)
+ if (gdaval)
return real_gda_holder_set_value (holder, gdaval, FALSE, error);
- else {
+ else {
g_set_error (error, GDA_HOLDER_ERROR, GDA_HOLDER_STRING_CONVERSION_ERROR,
_("Unable to convert string to '%s' type"),
gda_g_type_to_string (holder->priv->g_type));
- return FALSE;
+ return FALSE;
}
- }
+ }
}
/**
@@ -859,6 +863,14 @@
gboolean was_valid = gda_holder_is_valid (holder);
#endif
+ /* if the value has been set with gda_holder_take_static_value () you'll be able
+ * to change the value only with another call to real_gda_holder_set_value
+ */
+ if (!holder->priv->is_freeable) {
+ g_warning (_("Can't use this method to set value because there is already a static value"));
+ return FALSE;
+ }
+
/* holder will be changed? */
newnull = !value || gda_value_is_null (value);
current_val = gda_holder_get_value (holder);
@@ -962,6 +974,149 @@
return newvalid;
}
+static GValue *
+real_gda_holder_set_const_value (GdaHolder *holder, const GValue *value, GError **error)
+{
+ gboolean changed = TRUE;
+ gboolean newvalid;
+ const GValue *current_val;
+ GValue *value_to_return = NULL;
+ gboolean newnull;
+#define DEBUG_HOLDER
+#undef DEBUG_HOLDER
+
+#ifdef DEBUG_HOLDER
+ gboolean was_valid = gda_holder_is_valid (holder);
+#endif
+
+ /* holder will be changed? */
+ newnull = !value || gda_value_is_null (value);
+ current_val = gda_holder_get_value (holder);
+ if (current_val == value)
+ changed = FALSE;
+ else if ((!current_val || gda_value_is_null ((GValue *)current_val)) && newnull)
+ changed = FALSE;
+ else if (value && current_val &&
+ (G_VALUE_TYPE (value) == G_VALUE_TYPE ((GValue *)current_val)))
+ changed = gda_value_differ (value, (GValue *)current_val);
+
+ /* holder's validity */
+ newvalid = TRUE;
+ if (newnull && holder->priv->not_null) {
+ g_set_error (error, GDA_HOLDER_ERROR, GDA_HOLDER_VALUE_NULL_ERROR,
+ _("Holder does not allow NULL values"));
+ newvalid = FALSE;
+ changed = TRUE;
+ }
+ else if (!newnull && (G_VALUE_TYPE (value) != holder->priv->g_type)) {
+ g_set_error (error, GDA_HOLDER_ERROR, GDA_HOLDER_VALUE_TYPE_ERROR,
+ _("Wrong value type: expected type '%s' when value's type is '%s'"),
+ gda_g_type_to_string (holder->priv->g_type),
+ gda_g_type_to_string (G_VALUE_TYPE (value)));
+ newvalid = FALSE;
+ changed = TRUE;
+ }
+
+#ifdef DEBUG_HOLDER
+ g_print ("Changed holder %p (%s): value %s --> %s \t(type %d -> %d) VALID: %d->%d CHANGED: %d\n",
+ holder, holder->priv->id,
+ current_val ? gda_value_stringify ((GValue *)current_val) : "_NULL_",
+ value ? gda_value_stringify ((value)) : "_NULL_",
+ current_val ? G_VALUE_TYPE ((GValue *)current_val) : 0,
+ value ? G_VALUE_TYPE (value) : 0,
+ was_valid, newvalid, changed);
+#endif
+
+ /* end of procedure if the value has not been changed, after calculating the holder's validity */
+ if (!changed) {
+ holder->priv->invalid_forced = FALSE;
+ holder->priv->valid = newvalid;
+ return NULL;
+ }
+
+ /* check if we are allowed to change value */
+ GError *lerror = NULL;
+ g_signal_emit (holder, gda_holder_signals[VALIDATE_CHANGE], 0, value, &lerror);
+ if (lerror) {
+ /* change refused by signal callback */
+ g_propagate_error (error, lerror);
+ return NULL;
+ }
+
+ /* new valid status */
+ holder->priv->invalid_forced = FALSE;
+ holder->priv->valid = newvalid;
+ holder->priv->is_freeable = FALSE;
+
+ /* check is the new value is the default one */
+ holder->priv->default_forced = FALSE;
+ if (holder->priv->default_value) {
+ if ((G_VALUE_TYPE (holder->priv->default_value) == GDA_TYPE_NULL) && newnull)
+ holder->priv->default_forced = TRUE;
+ else if ((G_VALUE_TYPE (holder->priv->default_value) == holder->priv->g_type) &&
+ value && (G_VALUE_TYPE (value) == holder->priv->g_type))
+ holder->priv->default_forced = !gda_value_compare (holder->priv->default_value, value);
+ }
+
+ /* real setting of the value */
+ if (holder->priv->full_bind) {
+#ifdef DEBUG_HOLDER
+ g_print ("Holder %p is alias of holder %p => propagating changes to holder %p\n",
+ holder, holder->priv->full_bind, holder->priv->full_bind);
+#endif
+ return real_gda_holder_set_const_value (holder->priv->full_bind, value, error);
+ }
+ else {
+ if (holder->priv->value) {
+ value_to_return = holder->priv->value;
+ holder->priv->value = NULL;
+ }
+
+ if (value) {
+ if (newvalid) {
+ holder->priv->value = value;
+ }
+ }
+
+ g_signal_emit (holder, gda_holder_signals[CHANGED], 0);
+ }
+
+ return value_to_return;
+}
+
+/**
+ * gda_holder_take_static_value
+ * @holder: a #GdaHolder object
+ * @value: a const value to set the holder to
+ * @error: a place to store errors, or %NULL
+ *
+ * Sets the const value within the holder. If @holder is an alias for another
+ * holder, then the value is also set for that other holder.
+ *
+ * The value will not be freed, and user should take care of it, either for its
+ * freeing or for its correct value at the moment of query.
+ *
+ * If the value is not different from the one already contained within @holder,
+ * then @holder is not chaged and no signal is emitted.
+ *
+ * Note1: if @holder can't accept the @value value, then this method returns NULL, and @holder will be left
+ * in an invalid state.
+ *
+ * Note2: before the change is accepted by @holder, the "validate-change" signal will be emitted (the value
+ * of which can prevent the change from happening) which can be connected to to have a greater control
+ * of which values @holder can have, or implement some business rules.
+ *
+ * Returns:
+ */
+GValue *
+gda_holder_take_static_value (GdaHolder *holder, const GValue *value, GError **error)
+{
+ g_return_val_if_fail (GDA_IS_HOLDER (holder), FALSE);
+ g_return_val_if_fail (holder->priv, FALSE);
+
+ return real_gda_holder_set_const_value (holder, (GValue*) value, error);
+}
+
/**
* gda_holder_force_invalid
* @holder: a #GdaHolder object
@@ -988,7 +1143,8 @@
holder->priv->valid = FALSE;
if (holder->priv->value) {
- gda_value_free (holder->priv->value);
+ if (holder->priv->is_freeable)
+ gda_value_free (holder->priv->value);
holder->priv->value = NULL;
}
@@ -1050,7 +1206,8 @@
holder->priv->default_forced = TRUE;
holder->priv->invalid_forced = FALSE;
if (holder->priv->value) {
- gda_value_free (holder->priv->value);
+ if (holder->priv->is_freeable)
+ gda_value_free (holder->priv->value);
holder->priv->value = NULL;
}
}
@@ -1363,7 +1520,8 @@
/* get rid of the internal holder's value */
if (holder->priv->value) {
- gda_value_free (holder->priv->value);
+ if (holder->priv->is_freeable)
+ gda_value_free (holder->priv->value);
holder->priv->value = NULL;
}
Modified: trunk/libgda/gda-holder.h
==============================================================================
--- trunk/libgda/gda-holder.h (original)
+++ trunk/libgda/gda-holder.h Mon Sep 29 19:09:39 2008
@@ -75,6 +75,7 @@
gchar *gda_holder_get_value_str (GdaHolder *holder, GdaDataHandler *dh);
gboolean gda_holder_set_value (GdaHolder *holder, const GValue *value, GError **error);
gboolean gda_holder_take_value (GdaHolder *holder, GValue *value, GError **error);
+GValue *gda_holder_take_static_value (GdaHolder *holder, const GValue *value, GError **error);
gboolean gda_holder_set_value_str (GdaHolder *holder, GdaDataHandler *dh, const gchar *value, GError **error);
const GValue *gda_holder_get_default_value (GdaHolder *holder);
Modified: trunk/libgda/gda-meta-struct-io.c
==============================================================================
--- trunk/libgda/gda-meta-struct-io.c (original)
+++ trunk/libgda/gda-meta-struct-io.c Mon Sep 29 19:09:39 2008
@@ -61,15 +61,15 @@
if (catalog) {
g_value_set_string ((catalog_value = gda_value_new (G_TYPE_STRING)), catalog);
- if (_identifier_needs_quotes (catalog))
- quoted_catalog = _add_quotes (catalog);
+ if (gda_sql_identifier_needs_quotes (catalog))
+ quoted_catalog = gda_sql_identifier_add_quotes (catalog);
else
quoted_catalog = g_strdup (catalog);
}
if (schema) {
g_value_set_string ((schema_value = gda_value_new (G_TYPE_STRING)), schema);
- if (_identifier_needs_quotes (schema))
- quoted_schema = _add_quotes (schema);
+ if (gda_sql_identifier_needs_quotes (schema))
+ quoted_schema = gda_sql_identifier_add_quotes (schema);
else
quoted_schema = g_strdup (schema);
}
@@ -185,8 +185,8 @@
}
if (table_schema) {
g_value_set_string ((v2 = gda_value_new (G_TYPE_STRING)), (gchar *) table_schema);
- if (_identifier_needs_quotes ((gchar *) table_schema)) {
- gchar *tmp = _add_quotes ((gchar *) table_schema);
+ if (gda_sql_identifier_needs_quotes ((gchar *) table_schema)) {
+ gchar *tmp = gda_sql_identifier_add_quotes ((gchar *) table_schema);
g_string_append (full_table_name, tmp);
g_free (tmp);
}
@@ -200,8 +200,8 @@
g_string_append_c (full_table_name, '.');
}
g_value_set_string ((v3 = gda_value_new (G_TYPE_STRING)), (gchar *) table_name);
- if (_identifier_needs_quotes ((gchar *) table_name)) {
- gchar *tmp = _add_quotes ((gchar *) table_name);
+ if (gda_sql_identifier_needs_quotes ((gchar *) table_name)) {
+ gchar *tmp = gda_sql_identifier_add_quotes ((gchar *) table_name);
g_string_append (full_table_name, tmp);
g_free (tmp);
}
Modified: trunk/libgda/gda-meta-struct.c
==============================================================================
--- trunk/libgda/gda-meta-struct.c (original)
+++ trunk/libgda/gda-meta-struct.c Mon Sep 29 19:09:39 2008
@@ -421,19 +421,19 @@
/* create ready to compare strings for catalog, schema and name */
gchar *schema_s, *name_s;
if (_split_identifier_string (g_value_dup_string (name), &schema_s, &name_s)) {
- g_value_take_string ((iname = gda_value_new (G_TYPE_STRING)), _identifier_unquote (name_s));
+ g_value_take_string ((iname = gda_value_new (G_TYPE_STRING)), gda_sql_identifier_remove_quotes (name_s));
if (schema_s)
- g_value_take_string ((ischema = gda_value_new (G_TYPE_STRING)), _identifier_unquote (schema_s));
+ g_value_take_string ((ischema = gda_value_new (G_TYPE_STRING)), gda_sql_identifier_remove_quotes (schema_s));
}
else
g_value_take_string ((iname = gda_value_new (G_TYPE_STRING)),
- _identifier_unquote (g_value_dup_string (name)));
+ gda_sql_identifier_remove_quotes (g_value_dup_string (name)));
if (catalog)
g_value_take_string ((icatalog = gda_value_new (G_TYPE_STRING)),
- _identifier_unquote (g_value_dup_string (catalog)));
+ gda_sql_identifier_remove_quotes (g_value_dup_string (catalog)));
if (schema && !ischema)
g_value_take_string ((ischema = gda_value_new (G_TYPE_STRING)),
- _identifier_unquote (g_value_dup_string (schema)));
+ gda_sql_identifier_remove_quotes (g_value_dup_string (schema)));
if (!catalog) {
if (schema) {
@@ -1449,13 +1449,13 @@
g_return_val_if_fail (!schema || (G_VALUE_TYPE (schema) == G_TYPE_STRING), NULL);
/* prepare identifiers */
- g_value_take_string ((iname = gda_value_new (G_TYPE_STRING)), _identifier_unquote (g_value_dup_string (name)));
+ g_value_take_string ((iname = gda_value_new (G_TYPE_STRING)), gda_sql_identifier_remove_quotes (g_value_dup_string (name)));
if (catalog)
g_value_take_string ((icatalog = gda_value_new (G_TYPE_STRING)),
- _identifier_unquote (g_value_dup_string (catalog)));
+ gda_sql_identifier_remove_quotes (g_value_dup_string (catalog)));
if (schema)
g_value_take_string ((ischema = gda_value_new (G_TYPE_STRING)),
- _identifier_unquote (g_value_dup_string (schema)));
+ gda_sql_identifier_remove_quotes (g_value_dup_string (schema)));
dbo = _meta_struct_get_db_object (mstruct, icatalog, ischema, iname);
if (icatalog) gda_value_free (icatalog);
@@ -1965,8 +1965,8 @@
g_free (obj_schema);
return FALSE;
}
- g_value_take_string ((sv = gda_value_new (G_TYPE_STRING)), _identifier_unquote (obj_schema));
- g_value_take_string ((nv = gda_value_new (G_TYPE_STRING)), _identifier_unquote (obj_name));
+ g_value_take_string ((sv = gda_value_new (G_TYPE_STRING)), gda_sql_identifier_remove_quotes (obj_schema));
+ g_value_take_string ((nv = gda_value_new (G_TYPE_STRING)), gda_sql_identifier_remove_quotes (obj_name));
retval = determine_db_object_from_schema_and_name (mstruct, in_out_type, out_catalog,
out_short_name, out_full_name, out_owner,
sv, nv);
Modified: trunk/libgda/gda-meta-struct.h
==============================================================================
--- trunk/libgda/gda-meta-struct.h (original)
+++ trunk/libgda/gda-meta-struct.h Mon Sep 29 19:09:39 2008
@@ -116,7 +116,7 @@
* Struture to hold information about each database object (tables, views, triggers, ...)
*
* Note: @obj_catalog, @obj_schema, @obj_name, @obj_short_name and @obj_full_name are case sensitive:
- * one must call _identifier_needs_quotes() to know if is it is necessary to surround by double quotes
+ * one must call gda_sql_identifier_needs_quotes() to know if is it is necessary to surround by double quotes
* before using in an SQL statement
*/
typedef struct {
Modified: trunk/libgda/gda-statement.c
==============================================================================
--- trunk/libgda/gda-statement.c (original)
+++ trunk/libgda/gda-statement.c Mon Sep 29 19:09:39 2008
@@ -1220,7 +1220,7 @@
_("Unnamed parameter"));
goto err;
}
- quoted_pname = _add_quotes (pspec->name);
+ quoted_pname = gda_sql_identifier_add_quotes (pspec->name);
if (! (flag & (GDA_STATEMENT_SQL_PARAMS_LONG | GDA_STATEMENT_SQL_PARAMS_SHORT))) {
if (!expr->value || gda_value_is_null (expr->value) || strcmp (quoted_pname, pspec->name))
@@ -1245,12 +1245,12 @@
g_string_append (string, " /* ");
g_string_append_printf (string, "name:%s", quoted_pname);
if (pspec->g_type) {
- str = _add_quotes (gda_g_type_to_string (pspec->g_type));
+ str = gda_sql_identifier_add_quotes (gda_g_type_to_string (pspec->g_type));
g_string_append_printf (string, " type:%s", str);
g_free (str);
}
if (pspec->descr) {
- str = _add_quotes (pspec->descr);
+ str = gda_sql_identifier_add_quotes (pspec->descr);
g_string_append_printf (string, " descr:%s", str);
g_free (str);
}
Modified: trunk/libgda/gda-util.c
==============================================================================
--- trunk/libgda/gda-util.c (original)
+++ trunk/libgda/gda-util.c Mon Sep 29 19:09:39 2008
@@ -1309,7 +1309,7 @@
{
char *str;
gint tlen = strlen (ident);
- if (_identifier_needs_quotes (ident)) {
+ if (gda_sql_identifier_needs_quotes (ident)) {
str = malloc (sizeof (char) * (tlen + 3));
*str = '"';
strcpy (str+1, ident);
@@ -1333,7 +1333,7 @@
if (prefix)
plen = strlen (prefix) + 1;
- if (_identifier_needs_quotes (ident)) {
+ if (gda_sql_identifier_needs_quotes (ident)) {
str = malloc (sizeof (char) * (plen + tlen + 3));
if (prefix) {
strcpy (str, prefix);
Modified: trunk/libgda/sql-parser/gda-sql-parser.h
==============================================================================
--- trunk/libgda/sql-parser/gda-sql-parser.h (original)
+++ trunk/libgda/sql-parser/gda-sql-parser.h Mon Sep 29 19:09:39 2008
@@ -26,6 +26,7 @@
#include <libgda/gda-statement.h>
#include <libgda/gda-batch.h>
#include <sql-parser/gda-statement-struct.h>
+#include <sql-parser/gda-statement-struct-util.h>
G_BEGIN_DECLS
Modified: trunk/libgda/sql-parser/gda-statement-struct-util.c
==============================================================================
--- trunk/libgda/sql-parser/gda-statement-struct-util.c (original)
+++ trunk/libgda/sql-parser/gda-statement-struct-util.c Mon Sep 29 19:09:39 2008
@@ -134,8 +134,17 @@
return str;
}
+/**
+ * gda_sql_identifier_add_quotes
+ * @str: an SQL identifier
+ *
+ * Add double quotes around the @str identifier. Use the gda_sql_identifier_needs_quotes()
+ * function to tell if an identifier needs to be quoted.
+ *
+ * Returns: a new string
+ */
gchar *
-_add_quotes (const gchar *str)
+gda_sql_identifier_add_quotes (const gchar *str)
{
gchar *retval, *rptr;
const gchar *sptr;
@@ -273,10 +282,16 @@
}
/**
- * identifier_needs_quotes
+ * gda_sql_identifier_needs_quotes
+ * @str: an SQL identifier
+ *
+ * Tells if @str needs to be quoted before using it in an SQL statement. To actually add quotes,
+ * use gda_sql_identifier_add_quotes().
+ *
+ * Returns: TRUE if @str needs some quotes
*/
gboolean
-_identifier_needs_quotes (const gchar *str)
+gda_sql_identifier_needs_quotes (const gchar *str)
{
const gchar *ptr;
@@ -288,7 +303,10 @@
return FALSE;
}
-/*
+/**
+ * gda_sql_identifier_remove_quotes
+ * @str: a quoted string
+ *
* Prepares @str to be compared:
* - if surrounded by double quotes, then just remove the quotes
* - otherwise convert to lower case
@@ -298,7 +316,7 @@
* Returns: @str
*/
gchar *
-_identifier_unquote (gchar *str)
+gda_sql_identifier_remove_quotes (gchar *str)
{
if (!str)
return NULL;
Modified: trunk/libgda/sql-parser/gda-statement-struct-util.h
==============================================================================
--- trunk/libgda/sql-parser/gda-statement-struct-util.h (original)
+++ trunk/libgda/sql-parser/gda-statement-struct-util.h Mon Sep 29 19:09:39 2008
@@ -24,17 +24,17 @@
#include <glib-object.h>
/* utility functions */
-gchar *_remove_quotes (gchar *str);
-gchar *_add_quotes (const gchar *str);
+gchar *_remove_quotes (gchar *str);
+gchar *gda_sql_identifier_add_quotes (const gchar *str);
gchar *_json_quote_string (const gchar *str);
gboolean _string_is_identifier (const gchar *str);
-gboolean _identifier_needs_quotes (const gchar *str);
+gboolean gda_sql_identifier_needs_quotes (const gchar *str);
gboolean _split_identifier_string (gchar *str, gchar **remain, gchar **last);
-gchar *_identifier_unquote (gchar *str);
+gchar *gda_sql_identifier_remove_quotes (gchar *str);
/* to be removed, only here for debug */
-gchar *gda_sql_value_stringify (const GValue *value);
+gchar *gda_sql_value_stringify (const GValue *value);
#endif
Modified: trunk/libgda/sqlite/gda-sqlite-meta.c
==============================================================================
--- trunk/libgda/sqlite/gda-sqlite-meta.c (original)
+++ trunk/libgda/sqlite/gda-sqlite-meta.c Mon Sep 29 19:09:39 2008
@@ -788,7 +788,7 @@
break;
}
if (!strcmp (g_value_get_string (cvalue), TMP_DATABASE_NAME))
- continue; /* nothing to do */
+ continue; /* nothing to do */
if (! fill_tables_views_model (cnc, tables_model, views_model,
cvalue, NULL, error)) {
@@ -1018,7 +1018,7 @@
}
schema_name = g_value_get_string (cvalue);
if (!strcmp (schema_name, TMP_DATABASE_NAME))
- continue; /* nothing to do */
+ continue; /* nothing to do */
gchar *str;
GType col_types[] = {G_TYPE_STRING, G_TYPE_STRING, G_TYPE_NONE};
@@ -1261,7 +1261,7 @@
* FOREIGN KEYS
*/
GType fk_col_types[] = {G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_NONE};
- gchar *ref_table = NULL;
+ gint fkid = -1;
stmt = get_statement (I_PRAGMA_FK_LIST, schema_name, g_value_get_string (p_table_name), error);
tmpmodel = gda_connection_statement_execute_select_full (cnc, stmt, pragma_set,
GDA_STATEMENT_MODEL_RANDOM_ACCESS,
@@ -1270,22 +1270,29 @@
if (!tmpmodel)
return FALSE;
+ if (!strcmp (g_value_get_string (p_table_name), "baseFieldMappings"))
+ g_print ("AAA\n");
nrows = gda_data_model_get_n_rows (tmpmodel);
for (i = 0; i < nrows; i++) {
const GValue *cvalue;
- cvalue = gda_data_model_get_value_at (tmpmodel, 2, i, error);
+ cvalue = gda_data_model_get_value_at (tmpmodel, 0, i, error);
if (!cvalue) {
retval = FALSE;
break;
}
- if (! ref_table || strcmp (ref_table, g_value_get_string (cvalue))) {
+ if ((fkid == -1) || (fkid != g_value_get_int (cvalue))) {
gchar *constname;
GValue *v1, *v2;
- g_free (ref_table);
- ref_table = g_strdup (g_value_get_string (cvalue));
- constname = g_strdup_printf ("fk_%s", ref_table);
+ fkid = g_value_get_int (cvalue);
+
+ cvalue = gda_data_model_get_value_at (tmpmodel, 2, i, error);
+ if (!cvalue) {
+ retval = FALSE;
+ break;
+ }
+ constname = g_strdup_printf ("fk%d_%s", fkid, g_value_get_string (cvalue));
if (constraint_name_n && strcmp (g_value_get_string (constraint_name_n), constname)) {
g_free (constname);
continue;
@@ -1308,7 +1315,6 @@
retval = FALSE;
}
}
- g_free (ref_table);
g_object_unref (tmpmodel);
/*
@@ -1441,7 +1447,7 @@
schema_name = g_value_get_string (p_table_schema);
GType fk_col_types[] = {G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_NONE};
- gchar *ref_table = NULL;
+ gint fkid = -1;
stmt = get_statement (I_PRAGMA_FK_LIST, schema_name, g_value_get_string (p_table_name), error);
tmpmodel = gda_connection_statement_execute_select_full (cnc, stmt, pragma_set,
GDA_STATEMENT_MODEL_RANDOM_ACCESS,
@@ -1454,25 +1460,31 @@
for (i = 0; i < nrows; i++) {
const GValue *cvalue;
- cvalue = gda_data_model_get_value_at (tmpmodel, 2, i, error);
+ cvalue = gda_data_model_get_value_at (tmpmodel, 0, i, error);
if (!cvalue) {
retval = FALSE;
break;
}
- if (! ref_table || strcmp (ref_table, g_value_get_string (cvalue))) {
+ if ((fkid == -1) || (fkid != g_value_get_int (cvalue))) {
gchar *constname;
GValue *v2, *v3, *v4, *v5;
- g_free (ref_table);
- ref_table = g_strdup (g_value_get_string (cvalue));
- constname = g_strdup_printf ("fk_%s", ref_table);
+ fkid = g_value_get_int (cvalue);
+
+ cvalue = gda_data_model_get_value_at (tmpmodel, 2, i, error);
+ if (!cvalue) {
+ retval = FALSE;
+ break;
+ }
+
+ constname = g_strdup_printf ("fk%d_%s", fkid, g_value_get_string (cvalue));
if (constraint_name_n && strcmp (g_value_get_string (constraint_name_n), constname)) {
g_free (constname);
continue;
}
g_value_set_string ((v2 = gda_value_new (G_TYPE_STRING)), "FOREIGN KEY");
- g_value_set_string ((v3 = gda_value_new (G_TYPE_STRING)), ref_table);
+ g_value_set_string ((v3 = gda_value_new (G_TYPE_STRING)), g_value_get_string (cvalue));
g_value_set_string ((v4 = gda_value_new (G_TYPE_STRING)), "primary_key");
if (!constraint_name_n)
g_value_take_string ((v5 = gda_value_new (G_TYPE_STRING)), constname);
@@ -1495,7 +1507,6 @@
g_free (constname);
}
}
- g_free (ref_table);
g_object_unref (tmpmodel);
return retval;
@@ -1690,12 +1701,12 @@
}
g_object_unref (tmpmodel);
}
- else if ((*const_name == 'f') && (const_name[1] == 'k') && (const_name[2] == '_')) {
+ else if ((*const_name == 'f') && (const_name[1] == 'k')) {
/*
* FOREIGN key columns
*/
GType fk_col_types[] = {G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_NONE};
- gchar *ref_table = NULL;
+ gint fkid = -1;
gint ord_pos;
stmt = get_statement (I_PRAGMA_FK_LIST, schema_name, g_value_get_string (p_table_name), error);
tmpmodel = gda_connection_statement_execute_select_full (cnc, stmt, pragma_set,
@@ -1710,21 +1721,24 @@
const GValue *cvalue;
GValue *v1;
- cvalue = gda_data_model_get_value_at (tmpmodel, 2, i, error);
+ cvalue = gda_data_model_get_value_at (tmpmodel, 0, i, error);
if (!cvalue) {
retval = FALSE;
break;
}
- if (! ref_table || strcmp (ref_table, g_value_get_string (cvalue))) {
+ if ((fkid == -1) || (fkid != g_value_get_int (cvalue))) {
gchar *constname;
- g_free (ref_table);
- ref_table = g_strdup (g_value_get_string (cvalue));
- constname = g_strdup_printf ("fk_%s", ref_table);
+ fkid = g_value_get_int (cvalue);
+
+ cvalue = gda_data_model_get_value_at (tmpmodel, 2, i, error);
+ if (!cvalue) {
+ retval = FALSE;
+ break;
+ }
+ constname = g_strdup_printf ("fk%d_%s", fkid, g_value_get_string (cvalue));
if (strcmp (g_value_get_string (constraint_name), constname)) {
g_free (constname);
- g_free (ref_table);
- ref_table = NULL;
continue;
}
ord_pos = 1;
@@ -1746,7 +1760,6 @@
retval = FALSE;
}
- g_free (ref_table);
g_object_unref (tmpmodel);
}
else {
Modified: trunk/libgda/sqlite/virtual/gda-vprovider-data-model.c
==============================================================================
--- trunk/libgda/sqlite/virtual/gda-vprovider-data-model.c (original)
+++ trunk/libgda/sqlite/virtual/gda-vprovider-data-model.c Mon Sep 29 19:09:39 2008
@@ -441,7 +441,7 @@
name = gda_column_get_name (column);
if (!name || !(*name))
newcolname = g_strdup_printf ("_%d", i + 1);
- else if (_identifier_needs_quotes (name))
+ else if (gda_sql_identifier_needs_quotes (name))
newcolname = g_strdup_printf ("\"%s\"", name);
else
newcolname = g_strdup (name);
Modified: trunk/providers/mysql/gda-mysql-provider.c
==============================================================================
--- trunk/providers/mysql/gda-mysql-provider.c (original)
+++ trunk/providers/mysql/gda-mysql-provider.c Mon Sep 29 19:09:39 2008
@@ -1295,6 +1295,9 @@
{
GdaMysqlPStmt *ps;
MysqlConnectionData *cdata;
+ gboolean allow_noparam;
+ gboolean empty_rs = FALSE; /* TRUE when @allow_noparam is TRUE and there is a problem with @params
+ => resulting data model will be empty (0 row) */
g_return_val_if_fail (GDA_IS_CONNECTION (cnc), NULL);
g_return_val_if_fail (gda_connection_get_provider (cnc) == provider, NULL);
@@ -1307,13 +1310,20 @@
return FALSE;
}
- cdata = (MysqlConnectionData*) gda_connection_internal_get_provider_data (cnc);
- if (!cdata)
- return FALSE;
+ if (! (model_usage & GDA_STATEMENT_MODEL_RANDOM_ACCESS) &&
+ ! (model_usage & GDA_STATEMENT_MODEL_CURSOR_FORWARD))
+ model_usage |= GDA_STATEMENT_MODEL_RANDOM_ACCESS;
+
+ allow_noparam = (model_usage & GDA_STATEMENT_MODEL_ALLOW_NOPARAM) &&
+ (gda_statement_get_statement_type (stmt) == GDA_SQL_STATEMENT_SELECT);
if (last_inserted_row)
*last_inserted_row = NULL;
+ cdata = (MysqlConnectionData*) gda_connection_internal_get_provider_data (cnc);
+ if (!cdata)
+ return FALSE;
+
/* get/create new prepared statement */
ps = (GdaMysqlPStmt *) gda_connection_get_prepared_statement (cnc, stmt);
if (!ps) {
@@ -1378,24 +1388,42 @@
}
}
if (!h) {
- gchar *str;
- str = g_strdup_printf (_("Missing parameter '%s' to execute query"), pname);
- event = gda_connection_event_new (GDA_CONNECTION_EVENT_ERROR);
- gda_connection_event_set_description (event, str);
- g_set_error (error, GDA_SERVER_PROVIDER_ERROR,
- GDA_SERVER_PROVIDER_MISSING_PARAM_ERROR, str);
- g_free (str);
- break;
+
+ if (!allow_noparam) {
+ gchar *str;
+ str = g_strdup_printf (_("Missing parameter '%s' to execute query"), pname);
+ event = gda_connection_event_new (GDA_CONNECTION_EVENT_ERROR);
+ gda_connection_event_set_description (event, str);
+ g_set_error (error, GDA_SERVER_PROVIDER_ERROR,
+ GDA_SERVER_PROVIDER_MISSING_PARAM_ERROR, str);
+ g_free (str);
+ break;
+ } else {
+ /* bind param to NULL */
+ TO_IMPLEMENT;
+ empty_rs = TRUE;
+ continue;
+ }
+
}
if (!gda_holder_is_valid (h)) {
- gchar *str;
- str = g_strdup_printf (_("Parameter '%s' is invalid"), pname);
- event = gda_connection_event_new (GDA_CONNECTION_EVENT_ERROR);
- gda_connection_event_set_description (event, str);
- g_set_error (error, GDA_SERVER_PROVIDER_ERROR,
- GDA_SERVER_PROVIDER_MISSING_PARAM_ERROR, str);
- g_free (str);
- break;
+
+ if (!allow_noparam) {
+ gchar *str;
+ str = g_strdup_printf (_("Parameter '%s' is invalid"), pname);
+ event = gda_connection_event_new (GDA_CONNECTION_EVENT_ERROR);
+ gda_connection_event_set_description (event, str);
+ g_set_error (error, GDA_SERVER_PROVIDER_ERROR,
+ GDA_SERVER_PROVIDER_MISSING_PARAM_ERROR, str);
+ g_free (str);
+ break;
+ } else {
+ /* bind param to NULL */
+ TO_IMPLEMENT;
+ empty_rs = TRUE;
+ continue;
+ }
+
}
/* actual binding using the C API, for parameter at position @i */
@@ -1450,7 +1478,6 @@
return NULL;
}
-
/* use cursor when retrieving result */
if ((model_usage & GDA_STATEMENT_MODEL_RANDOM_ACCESS) == 0 &&
gda_statement_get_statement_type (stmt) == GDA_SQL_STATEMENT_SELECT) {
@@ -1467,12 +1494,36 @@
#endif
}
-
/* add a connection event for the execution */
event = gda_connection_event_new (GDA_CONNECTION_EVENT_COMMAND);
gda_connection_event_set_description (event, _GDA_PSTMT (ps)->sql);
gda_connection_add_event (cnc, event);
+ if (empty_rs) {
+ /* There are some missing parameters, so the SQL can't be executed but we still want
+ * to execute something to get the columns correctly. A possibility is to actually
+ * execute another SQL which is the code shown here.
+ *
+ * To adapt depending on the C API and its features */
+ GdaStatement *estmt;
+ gchar *esql;
+ estmt = gda_select_alter_select_for_empty (stmt, error);
+ if (!estmt)
+ return NULL;
+ esql = gda_statement_to_sql (estmt, NULL, error);
+ g_object_unref (estmt);
+ if (!esql)
+ return NULL;
+
+ /* Execute the 'esql' SQL code */
+ g_free (esql);
+
+ TO_IMPLEMENT;
+ } else {
+ /* Execute the _GDA_PSTMT (ps)->sql SQL code */
+ TO_IMPLEMENT;
+ }
+
GObject *return_value = NULL;
if (mysql_stmt_execute (cdata->mysql_stmt)) {
Modified: trunk/samples/SqlParserConsole/graph.c
==============================================================================
--- trunk/samples/SqlParserConsole/graph.c (original)
+++ trunk/samples/SqlParserConsole/graph.c Mon Sep 29 19:09:39 2008
@@ -333,7 +333,6 @@
if (expr->param_spec) {
add_node (string, expr->param_spec , "GdaSqlParamSpec",
"name", G_TYPE_STRING, expr->param_spec->name,
- "type", G_TYPE_STRING, expr->param_spec->type,
"descr", G_TYPE_STRING, expr->param_spec->descr,
"is_param", G_TYPE_BOOLEAN, expr->param_spec->is_param,
"nullok", G_TYPE_BOOLEAN, expr->param_spec->nullok,
@@ -368,7 +367,7 @@
case GDA_SQL_ANY_SQL_OPERATION: {
GdaSqlOperation *op = (GdaSqlOperation*) part;
add_node (string, part , "GdaSqlOperation",
- "operator", G_TYPE_STRING, gda_sql_operation_operator_to_string (op->operator),
+ "operator", G_TYPE_STRING, gda_sql_operation_operator_to_string (op->operator_type),
NULL);
link_a_list (string, part, op->operands, "operands");
break;
@@ -408,7 +407,7 @@
"position", G_TYPE_INT, join->position,
NULL);
link_a_node (string, part, join->expr, "expr");
- link_a_list (string, part, join->using, "using");
+ link_a_list (string, part, join->use, "using");
break;
}
case GDA_SQL_ANY_SQL_SELECT_FROM: {
Modified: trunk/tests/gda-ddl-creator.c
==============================================================================
--- trunk/tests/gda-ddl-creator.c (original)
+++ trunk/tests/gda-ddl-creator.c Mon Sep 29 19:09:39 2008
@@ -289,8 +289,8 @@
creator->priv->quoted_catalog = NULL;
if (g_value_get_string (value) && *g_value_get_string (value)) {
creator->priv->catalog = gda_value_copy (value);
- if (_identifier_needs_quotes (g_value_get_string (value)))
- creator->priv->quoted_catalog = _add_quotes (g_value_get_string (value));
+ if (gda_sql_identifier_needs_quotes (g_value_get_string (value)))
+ creator->priv->quoted_catalog = gda_sql_identifier_add_quotes (g_value_get_string (value));
else
creator->priv->quoted_catalog = g_value_dup_string (value);
}
@@ -303,8 +303,8 @@
creator->priv->quoted_schema = NULL;
if (g_value_get_string (value) && *g_value_get_string (value)) {
creator->priv->schema = gda_value_copy (value);
- if (_identifier_needs_quotes (g_value_get_string (value)))
- creator->priv->quoted_schema = _add_quotes (g_value_get_string (value));
+ if (gda_sql_identifier_needs_quotes (g_value_get_string (value)))
+ creator->priv->quoted_schema = gda_sql_identifier_add_quotes (g_value_get_string (value));
else
creator->priv->quoted_schema = g_value_dup_string (value);
}
Modified: trunk/tools/command-exec.c
==============================================================================
--- trunk/tools/command-exec.c (original)
+++ trunk/tools/command-exec.c Mon Sep 29 19:09:39 2008
@@ -433,7 +433,8 @@
"table_type LIKE '%TABLE%' AND table_short_name = table_name "
"ORDER BY table_schema, table_name";
- g_value_set_string (v = gda_value_new (G_TYPE_STRING), args[0]);
+ gchar *tmp = gda_sql_identifier_remove_quotes (g_strdup (args[0]));
+ g_value_take_string (v = gda_value_new (G_TYPE_STRING), tmp);
model = gda_meta_store_extract (gda_connection_get_meta_store (cnc), sql, error, "tname", v, NULL);
gda_value_free (v);
}
@@ -573,19 +574,21 @@
}
else {
/* try to find it as a table or view */
- if (!gda_meta_struct_complement (mstruct, GDA_META_DB_UNKNOWN, NULL, NULL, v, NULL)) {
- if (g_str_has_suffix (arg, "=") && (*arg != '=')) {
- GdaMetaDbObject *dbo;
- gchar *str;
- str = g_strdup (arg);
- str[strlen (str) - 1] = 0;
- g_value_take_string (v, str);
- dbo = gda_meta_struct_complement (mstruct, GDA_META_DB_UNKNOWN,
- NULL, NULL, v, NULL);
- if (dbo)
- gda_meta_struct_complement_depend (mstruct, dbo, NULL);
- }
+ if (g_str_has_suffix (arg, "=") && (*arg != '=')) {
+ GdaMetaDbObject *dbo;
+ gchar *str;
+ str = g_strdup (arg);
+ str[strlen (str) - 1] = 0;
+ g_value_take_string (v, str);
+ dbo = gda_meta_struct_complement (mstruct, GDA_META_DB_UNKNOWN,
+ NULL, NULL, v, error);
+ if (dbo)
+ gda_meta_struct_complement_depend (mstruct, dbo, error);
+ else
+ goto onerror;
}
+ else if (!gda_meta_struct_complement (mstruct, GDA_META_DB_UNKNOWN, NULL, NULL, v, error))
+ goto onerror;
}
}
@@ -932,7 +935,7 @@
for (j = 0; j < cnrows; j++) {
if (j > 0)
g_string_append (string, ", ");
- cvalue = gda_data_model_get_value_at (cols, 2, j, error);
+ cvalue = gda_data_model_get_value_at (cols, 3, j, error);
if (!cvalue) {
gda_internal_command_exec_result_free (res);
res = NULL;
Modified: trunk/tools/gda-sql.c
==============================================================================
--- trunk/tools/gda-sql.c (original)
+++ trunk/tools/gda-sql.c Mon Sep 29 19:09:39 2008
@@ -836,7 +836,14 @@
}
if (file) {
- data->input_stream = g_fopen (file, "r");
+ if (*file == '~') {
+ gchar *tmp;
+ tmp = g_strdup_printf ("%s%s", g_get_home_dir (), file+1);
+ data->input_stream = g_fopen (tmp, "r");
+ g_free (tmp);
+ }
+ else
+ data->input_stream = g_fopen (file, "r");
if (!data->input_stream) {
g_set_error (error, 0, 0,
_("Can't open file '%s' for reading: %s\n"),
@@ -1360,6 +1367,10 @@
GError **error, MainData *data);
static GdaInternalCommandResult *extra_command_list_dsn (GdaConnection *cnc, const gchar **args,
GError **error, MainData *data);
+static GdaInternalCommandResult *extra_command_create_dsn (GdaConnection *cnc, const gchar **args,
+ GError **error, MainData *data);
+static GdaInternalCommandResult *extra_command_remove_dsn (GdaConnection *cnc, const gchar **args,
+ GError **error, MainData *data);
static GdaInternalCommandResult *extra_command_list_providers (GdaConnection *cnc, const gchar **args,
GError **error, MainData *data);
static GdaInternalCommandResult *extra_command_manage_cnc (GdaConnection *cnc, const gchar **args,
@@ -1506,9 +1517,9 @@
commands->commands = g_slist_prepend (commands->commands, c);
c = g_new0 (GdaInternalCommand, 1);
- c->group = _("General");
- c->name = "l";
- c->description = _("List configured data sources (DSN)");
+ c->group = _("DSN (data sources) management");
+ c->name = g_strdup_printf (_("%s [DSN]"), "l");
+ c->description = _("List all DSN (or named DSN's attributes)");
c->args = NULL;
c->command_func = (GdaInternalCommandFunc) extra_command_list_dsn;
c->user_data = data;
@@ -1516,9 +1527,29 @@
commands->commands = g_slist_prepend (commands->commands, c);
c = g_new0 (GdaInternalCommand, 1);
- c->group = _("General");
- c->name = "providers_list";
- c->description = _("List installed database providers");
+ c->group = _("DSN (data sources) management");
+ c->name = g_strdup_printf (_("%s DSN_NAME DSN_DEFINITION [DESCRIPTION]"), "lc");
+ c->description = _("Create (or modify) a DSN");
+ c->args = NULL;
+ c->command_func = (GdaInternalCommandFunc) extra_command_create_dsn;
+ c->user_data = data;
+ c->arguments_delimiter_func = NULL;
+ commands->commands = g_slist_prepend (commands->commands, c);
+
+ c = g_new0 (GdaInternalCommand, 1);
+ c->group = _("DSN (data sources) management");
+ c->name = g_strdup_printf (_("%s DSN_NAME [DSN_NAME...]"), "lr");
+ c->description = _("Remove a DSN");
+ c->args = NULL;
+ c->command_func = (GdaInternalCommandFunc) extra_command_remove_dsn;
+ c->user_data = data;
+ c->arguments_delimiter_func = NULL;
+ commands->commands = g_slist_prepend (commands->commands, c);
+
+ c = g_new0 (GdaInternalCommand, 1);
+ c->group = _("DSN (data sources) management");
+ c->name = g_strdup_printf (_("%s [PROVIDER]"), "lp");
+ c->description = _("List all installed database providers (or named one's attributes)");
c->args = NULL;
c->command_func = (GdaInternalCommandFunc) extra_command_list_providers;
c->user_data = data;
@@ -1842,22 +1873,285 @@
extra_command_list_dsn (GdaConnection *cnc, const gchar **args, GError **error, MainData *data)
{
GdaInternalCommandResult *res;
+ GdaDataModel *dsn_list, *model = NULL;
+ gint i, nrows;
+ GList *list = NULL;
+
+ dsn_list = gda_config_list_dsn ();
+ nrows = gda_data_model_get_n_rows (dsn_list);
+
+ if (args[0]) {
+ /* details about a DSN */
+ for (i = 0; i < nrows; i++) {
+ const GValue *value;
+ value = gda_data_model_get_value_at (dsn_list, 0, i, error);
+ if (!value)
+ goto onerror;
+
+ if (!strcmp (g_value_get_string (value), args[0])) {
+ gint j;
+ model = gda_data_model_array_new_with_g_types (2,
+ G_TYPE_STRING,
+ G_TYPE_STRING);
+ gda_data_model_set_column_title (model, 0, _("Attribute"));
+ gda_data_model_set_column_title (model, 1, _("Value"));
+ g_object_set_data_full (G_OBJECT (model), "name",
+ g_strdup_printf (_("DSN '%s' description"), args[0]),
+ g_free);
+
+ for (j = 0; j < 6; j++) {
+ GValue *tmpvalue;
+ if (gda_data_model_append_row (model, error) == -1)
+ goto onerror;
+
+ g_value_set_string ((tmpvalue = gda_value_new (G_TYPE_STRING)),
+ gda_data_model_get_column_title (dsn_list, j));
+ if (! gda_data_model_set_value_at (model, 0, j, tmpvalue, error))
+ goto onerror;
+ gda_value_free (tmpvalue);
+
+ value = gda_data_model_get_value_at (dsn_list, j, i, error);
+ if (!value ||
+ ! gda_data_model_set_value_at (model, 1, j, value, error))
+ goto onerror;
+ }
+ res = g_new0 (GdaInternalCommandResult, 1);
+ res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
+ res->u.model = model;
+ g_object_unref (dsn_list);
+ return res;
+ }
+ }
+ g_object_unref (dsn_list);
+ g_set_error (error, 0, 0,
+ _("Could not find any DSN named '%s'"), args[0]);
+ return NULL;
+ }
+ else {
+ model = gda_data_model_array_new_with_g_types (3,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_STRING);
+ gda_data_model_set_column_title (model, 0, _("DSN"));
+ gda_data_model_set_column_title (model, 1, _("Description"));
+ gda_data_model_set_column_title (model, 2, _("Provider"));
+ g_object_set_data (G_OBJECT (model), "name", _("DSN list"));
+
+ for (i =0; i < nrows; i++) {
+ const GValue *value;
+ list = NULL;
+ value = gda_data_model_get_value_at (dsn_list, 0, i, error);
+ if (!value)
+ goto onerror;
+ list = g_list_append (NULL, gda_value_copy (value));
+ value = gda_data_model_get_value_at (dsn_list, 2, i, error);
+ if (!value)
+ goto onerror;
+ list = g_list_append (list, gda_value_copy (value));
+ value = gda_data_model_get_value_at (dsn_list, 1, i, error);
+ if (!value)
+ goto onerror;
+ list = g_list_append (list, gda_value_copy (value));
+
+ if (gda_data_model_append_values (model, list, error) == -1)
+ goto onerror;
+
+ g_list_foreach (list, (GFunc) gda_value_free, NULL);
+ g_list_free (list);
+ }
+
+ res = g_new0 (GdaInternalCommandResult, 1);
+ res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
+ res->u.model = model;
+ g_object_unref (dsn_list);
+
+ return res;
+ }
+
+ onerror:
+ if (list) {
+ g_list_foreach (list, (GFunc) gda_value_free, NULL);
+ g_list_free (list);
+ }
+ g_object_unref (dsn_list);
+ g_object_unref (model);
+ return NULL;
+}
+
+static GdaInternalCommandResult *
+extra_command_create_dsn (GdaConnection *cnc, const gchar **args, GError **error, MainData *data)
+{
+ GdaInternalCommandResult *res = NULL;
+ GdaDsnInfo newdsn;
+ gchar *real_cnc, *real_provider, *user, *pass;
+
+ if (!args[0] || !args[1]) {
+ g_set_error (error, 0, 0,
+ _("Missing arguments"));
+ return NULL;
+ }
+
+ newdsn.name = (gchar *) args [0];
+ gda_connection_string_split ((gchar *) args[1], &real_cnc, &real_provider, &user, &pass);
+ newdsn.provider = real_provider;
+ newdsn.description = NULL;
+ if (args[2]) {
+ if ((*args[2] == '"') && (args[2][strlen (args[2]) - 1] == '"'))
+ newdsn.description = g_strndup (args[2] + 1, strlen (args[2]) - 2);
+ else
+ newdsn.description = g_strdup (args[2]);
+ }
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
- res->u.model = list_all_dsn (data);
+ newdsn.cnc_string = real_cnc;
+ newdsn.auth_string = NULL;
+ if (user) {
+ gchar *tmp;
+ tmp = gda_rfc1738_encode (user);
+ newdsn.auth_string = g_strdup_printf ("USERNAME=%s", tmp);
+ g_free (tmp);
+ }
+ newdsn.is_system = FALSE;
+
+ if (!newdsn.provider) {
+ g_set_error (error, 0, 0,
+ _("Missing provider name"));
+ }
+ else if (gda_config_define_dsn (&newdsn, error)) {
+ res = g_new0 (GdaInternalCommandResult, 1);
+ res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ }
+
+ g_free (real_cnc);
+ g_free (real_provider);
+ g_free (user);
+ g_free (pass);
+ g_free (newdsn.description);
+
return res;
}
static GdaInternalCommandResult *
-extra_command_list_providers (GdaConnection *cnc, const gchar **args, GError **error, MainData *data)
+extra_command_remove_dsn (GdaConnection *cnc, const gchar **args, GError **error, MainData *data)
{
GdaInternalCommandResult *res;
-
+ gint i;
+
+ if (!args[0]) {
+ g_set_error (error, 0, 0,
+ _("Missing DSN name"));
+ return NULL;
+ }
+ for (i = 0; args [i]; i++) {
+ if (! gda_config_remove_dsn (args[i], error))
+ return NULL;
+ }
+
res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
- res->u.model = list_all_providers (data);
- return res;
+ res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ return res;
+}
+
+static GdaInternalCommandResult *
+extra_command_list_providers (GdaConnection *cnc, const gchar **args, GError **error, MainData *data)
+{
+ GdaInternalCommandResult *res;
+ GdaDataModel *prov_list, *model = NULL;
+ gint i, nrows;
+ GList *list = NULL;
+
+ prov_list = gda_config_list_providers ();
+ nrows = gda_data_model_get_n_rows (prov_list);
+
+ if (args[0]) {
+ /* details about a provider */
+ for (i = 0; i < nrows; i++) {
+ const GValue *value;
+ value = gda_data_model_get_value_at (prov_list, 0, i, error);
+ if (!value)
+ goto onerror;
+
+ if (!strcmp (g_value_get_string (value), args[0])) {
+ gint j;
+ model = gda_data_model_array_new_with_g_types (2,
+ G_TYPE_STRING,
+ G_TYPE_STRING);
+ gda_data_model_set_column_title (model, 0, _("Attribute"));
+ gda_data_model_set_column_title (model, 1, _("Value"));
+ g_object_set_data_full (G_OBJECT (model), "name",
+ g_strdup_printf (_("Provider '%s' description"), args[0]),
+ g_free);
+
+ for (j = 0; j < 5; j++) {
+ GValue *tmpvalue;
+ if (gda_data_model_append_row (model, error) == -1)
+ goto onerror;
+
+ g_value_set_string ((tmpvalue = gda_value_new (G_TYPE_STRING)),
+ gda_data_model_get_column_title (prov_list, j));
+ if (! gda_data_model_set_value_at (model, 0, j, tmpvalue, error))
+ goto onerror;
+ gda_value_free (tmpvalue);
+
+ value = gda_data_model_get_value_at (prov_list, j, i, error);
+ if (!value ||
+ ! gda_data_model_set_value_at (model, 1, j, value, error))
+ goto onerror;
+ }
+ res = g_new0 (GdaInternalCommandResult, 1);
+ res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
+ res->u.model = model;
+ g_object_unref (prov_list);
+ return res;
+ }
+ }
+ g_object_unref (prov_list);
+ g_set_error (error, 0, 0,
+ _("Could not find any provider named '%s'"), args[0]);
+ return NULL;
+ }
+ else {
+ model = gda_data_model_array_new_with_g_types (2,
+ G_TYPE_STRING,
+ G_TYPE_STRING);
+ gda_data_model_set_column_title (model, 0, _("Provider"));
+ gda_data_model_set_column_title (model, 1, _("Description"));
+ g_object_set_data (G_OBJECT (model), "name", _("Installed providers list"));
+
+ for (i =0; i < nrows; i++) {
+ const GValue *value;
+ list = NULL;
+ value = gda_data_model_get_value_at (prov_list, 0, i, error);
+ if (!value)
+ goto onerror;
+ list = g_list_append (list, gda_value_copy (value));
+ value = gda_data_model_get_value_at (prov_list, 1, i, error);
+ if (!value)
+ goto onerror;
+ list = g_list_append (list, gda_value_copy (value));
+
+ if (gda_data_model_append_values (model, list, error) == -1)
+ goto onerror;
+
+ g_list_foreach (list, (GFunc) gda_value_free, NULL);
+ g_list_free (list);
+ }
+
+ res = g_new0 (GdaInternalCommandResult, 1);
+ res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
+ res->u.model = model;
+ g_object_unref (prov_list);
+
+ return res;
+ }
+
+ onerror:
+ if (list) {
+ g_list_foreach (list, (GFunc) gda_value_free, NULL);
+ g_list_free (list);
+ }
+ g_object_unref (prov_list);
+ g_object_unref (model);
+ return NULL;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]