libgda r3260 - in trunk: . doc/C doc/C/tmpl libgda providers/jdbc providers/jdbc/doc tools
- From: vivien svn gnome org
- To: svn-commits-list gnome org
- Subject: libgda r3260 - in trunk: . doc/C doc/C/tmpl libgda providers/jdbc providers/jdbc/doc tools
- Date: Mon, 1 Dec 2008 19:56:29 +0000 (UTC)
Author: vivien
Date: Mon Dec 1 19:56:29 2008
New Revision: 3260
URL: http://svn.gnome.org/viewvc/libgda?rev=3260&view=rev
Log:
2008-12-01 Vivien Malerba <malerba gnome-db org>
* tools/gda-sql.c: simplified the result of the -L option (now only returns the
provider name and its description for each installed provider)
* tools/command-exec.c:
- corrections when listing tables or views
- if no object is found in the default "search path", then it is also
looked up in all the schemas
* tools/tools-input.c: correclty handle history
* providers/jdbc/*:
- JNI related bug fixes
- meta data now also retreives table's columns information
- added some code specific to Apache Derby
* libgda/gda-connection.c:
* libgda/gda-meta-struct.c: replace "='BASE TABLE'" with "LIKE '%TABLE%'"
* libgda/gda-meta-struct.[ch]: added gda_meta_struct_complement_all()
Added:
trunk/providers/jdbc/derby.java
Modified:
trunk/ChangeLog
trunk/doc/C/libgda-4.0-sections.txt
trunk/doc/C/tmpl/gda-meta-struct.sgml
trunk/libgda/gda-connection.c
trunk/libgda/gda-meta-struct.c
trunk/libgda/gda-meta-struct.h
trunk/providers/jdbc/GdaJMeta.c
trunk/providers/jdbc/GdaJValue.c
trunk/providers/jdbc/Makefile.am
trunk/providers/jdbc/doc/index.html
trunk/providers/jdbc/gda-jdbc-meta.c
trunk/providers/jdbc/gda-jdbc-recordset.c
trunk/providers/jdbc/h2.java
trunk/providers/jdbc/jni-globals.h
trunk/providers/jdbc/jni-wrapper.c
trunk/providers/jdbc/meta.java
trunk/providers/jdbc/provider.java
trunk/tools/command-exec.c
trunk/tools/gda-sql.c
trunk/tools/tools-input.c
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 Dec 1 19:56:29 2008
@@ -1353,6 +1353,7 @@
gda_meta_struct_complement
gda_meta_struct_complement_schema
gda_meta_struct_complement_default
+gda_meta_struct_complement_all
gda_meta_struct_complement_depend
GdaMetaSortType
gda_meta_struct_sort_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 Dec 1 19:56:29 2008
@@ -321,6 +321,16 @@
@Returns:
+<!-- ##### FUNCTION gda_meta_struct_complement_all ##### -->
+<para>
+
+</para>
+
+ mstruct:
+ error:
+ Returns:
+
+
<!-- ##### FUNCTION gda_meta_struct_complement_depend ##### -->
<para>
Modified: trunk/libgda/gda-connection.c
==============================================================================
--- trunk/libgda/gda-connection.c (original)
+++ trunk/libgda/gda-connection.c Mon Dec 1 19:56:29 2008
@@ -3167,7 +3167,7 @@
/* GDA_CONNECTION_META_TABLES */
key = g_new0 (MetaKey, 1);
key->meta_type = GDA_CONNECTION_META_TABLES;
- sql = "SELECT table_short_name, table_schema, table_full_name, table_owner, table_comments FROM _tables WHERE table_type='BASE TABLE'";
+ sql = "SELECT table_short_name, table_schema, table_full_name, table_owner, table_comments FROM _tables WHERE table_type LIKE '%TABLE%'";
stmt = gda_sql_parser_parse_string (parser, sql, NULL, NULL);
if (!stmt)
g_error ("Could not parse internal statement: %s\n", sql);
@@ -3177,7 +3177,7 @@
key->meta_type = GDA_CONNECTION_META_TABLES;
key->nb_filters = 1;
key->filters = name_array;
- sql = "SELECT table_short_name, table_schema, table_full_name, table_owner, table_comments FROM _tables WHERE table_type='BASE TABLE' AND table_short_name=##name::string";
+ sql = "SELECT table_short_name, table_schema, table_full_name, table_owner, table_comments FROM _tables WHERE table_type LIKE '%TABLE%' AND table_short_name=##name::string";
stmt = gda_sql_parser_parse_string (parser, sql, NULL, NULL);
if (!stmt)
g_error ("Could not parse internal statement: %s\n", sql);
Modified: trunk/libgda/gda-meta-struct.c
==============================================================================
--- trunk/libgda/gda-meta-struct.c (original)
+++ trunk/libgda/gda-meta-struct.c Mon Dec 1 19:56:29 2008
@@ -372,6 +372,33 @@
GValue **out_full_name, GValue **out_owner, const GValue *catalog,
const GValue *schema, const GValue *name);
static gchar *array_type_to_sql (GdaMetaStore *store, const GValue *specific_name);
+static gchar *
+get_user_obj_name (const GValue *catalog, const GValue *schema, const GValue *name)
+{
+ GString *string = NULL;
+ gchar *ret;
+ if (catalog && (G_VALUE_TYPE (catalog) != GDA_TYPE_NULL))
+ string = g_string_new (g_value_get_string (catalog));
+ if (schema && (G_VALUE_TYPE (schema) != GDA_TYPE_NULL)) {
+ if (string) {
+ g_string_append_c (string, '.');
+ g_string_append (string, g_value_get_string (schema));
+ }
+ else
+ string = g_string_new (g_value_get_string (schema));
+ }
+ if (name && (G_VALUE_TYPE (name) != GDA_TYPE_NULL)) {
+ if (string) {
+ g_string_append_c (string, '.');
+ g_string_append (string, g_value_get_string (name));
+ }
+ else
+ string = g_string_new (g_value_get_string (name));
+ }
+ ret = string->str;
+ g_string_free (string, FALSE);
+ return ret;
+}
/**
* gda_meta_struct_complement
@@ -440,15 +467,17 @@
g_value_take_string ((ischema = gda_value_new (G_TYPE_STRING)),
gda_sql_identifier_remove_quotes (g_value_dup_string (schema)));
- if (!catalog) {
- if (schema) {
- g_return_val_if_fail (schema && (G_VALUE_TYPE (schema) == G_TYPE_STRING), NULL);
+ if (!icatalog) {
+ if (ischema) {
+ g_return_val_if_fail (ischema && (G_VALUE_TYPE (ischema) == G_TYPE_STRING), NULL);
if (! determine_db_object_from_schema_and_name (mstruct, &real_type, &icatalog,
&short_name, &full_name, &owner,
ischema, iname)) {
+ gchar *tmp;
+ tmp = get_user_obj_name (catalog, schema, name);
g_set_error (error, GDA_META_STRUCT_ERROR, GDA_META_STRUCT_UNKNOWN_OBJECT_ERROR,
- _("Could not find object named '%s.%s'"),
- g_value_get_string (schema), g_value_get_string (name));
+ _("Could not find object named '%s'"), tmp);
+ g_free (tmp);
gda_value_free (ischema);
gda_value_free (iname);
return NULL;
@@ -459,8 +488,11 @@
if (! determine_db_object_from_short_name (mstruct, &real_type, &icatalog,
&ischema, &real_name,
&short_name, &full_name, &owner, iname)) {
+ gchar *tmp;
+ tmp = get_user_obj_name (catalog, schema, name);
g_set_error (error, GDA_META_STRUCT_ERROR, GDA_META_STRUCT_UNKNOWN_OBJECT_ERROR,
- _("Could not find object named '%s'"), g_value_get_string (name));
+ _("Could not find object named '%s'"), tmp);
+ g_free (tmp);
gda_value_free (iname);
return NULL;
}
@@ -473,9 +505,11 @@
else if (type == GDA_META_DB_UNKNOWN) {
if (! determine_db_object_from_missing_type (mstruct, &real_type, &short_name, &full_name, &owner,
icatalog, ischema, iname)) {
+ gchar *tmp;
+ tmp = get_user_obj_name (catalog, schema, name);
g_set_error (error, GDA_META_STRUCT_ERROR, GDA_META_STRUCT_UNKNOWN_OBJECT_ERROR,
- _("Could not find object named '%s.%s.%s'"), g_value_get_string (catalog),
- g_value_get_string (schema), g_value_get_string (name));
+ _("Could not find object named '%s'"), tmp);
+ g_free (tmp);
gda_value_free (icatalog);
gda_value_free (ischema);
gda_value_free (iname);
@@ -575,11 +609,17 @@
mv = GDA_META_VIEW (dbo);
cvalue = gda_data_model_get_value_at (model, 0, 0, error);
if (!cvalue) goto onerror;
- mv->view_def = g_value_dup_string (cvalue);
+ if (G_VALUE_TYPE (cvalue) != GDA_TYPE_NULL)
+ mv->view_def = g_value_dup_string (cvalue);
+ else
+ mv->view_def = g_strdup ("");
cvalue = gda_data_model_get_value_at (model, 1, 0, error);
if (!cvalue) goto onerror;
- mv->is_updatable = g_value_get_boolean (cvalue);
+ if (G_VALUE_TYPE (cvalue) != GDA_TYPE_NULL)
+ mv->is_updatable = g_value_get_boolean (cvalue);
+ else
+ mv->is_updatable = FALSE;
/* view's dependencies, from its definition */
if ((mstruct->priv->features & GDA_META_STRUCT_FEATURE_VIEW_DEPENDENCIES) &&
@@ -1050,7 +1090,7 @@
/* schema and catalog are known */
const gchar *sql1 = "SELECT table_name "
"FROM _tables WHERE table_short_name, table_full_name, table_owner, table_catalog = ##cat::string AND table_schema = ##schema::string "
- "AND table_type='BASE TABLE' "
+ "AND table_type LIKE '%TABLE%' "
"ORDER BY table_schema, table_name";
const gchar *sql2 = "SELECT table_short_name, table_full_name, table_owner, table_name "
"FROM _tables WHERE table_catalog = ##cat::string AND table_schema = ##schema::string "
@@ -1059,7 +1099,7 @@
/* schema is known, catalog unknown */
const gchar *sql3 = "SELECT table_short_name, table_full_name, table_owner, table_name, table_catalog, table_schema "
- "FROM _tables WHERE table_schema = ##schema::string AND table_type='BASE TABLE' "
+ "FROM _tables WHERE table_schema = ##schema::string AND table_type LIKE '%TABLE%' "
"ORDER BY table_schema, table_name";
const gchar *sql4 = "SELECT table_short_name, table_full_name, table_owner, table_name, table_catalog, table_schema "
"FROM _tables WHERE table_schema = ##schema::string AND table_type='VIEW' "
@@ -1067,7 +1107,7 @@
/* schema and catalog are unknown */
const gchar *sql5 = "SELECT table_short_name, table_full_name, table_owner, table_name, table_catalog, table_schema "
- "FROM _tables WHERE table_type='BASE TABLE' "
+ "FROM _tables WHERE table_type LIKE '%TABLE%' "
"ORDER BY table_schema, table_name";
const gchar *sql6 = "SELECT table_short_name, table_full_name, table_owner, table_name, table_catalog, table_schema "
"FROM _tables WHERE table_type='VIEW' "
@@ -1155,25 +1195,14 @@
return TRUE;
}
-/**
- * gda_meta_struct_complement_default
- * @mstruct: a #GdaMetaStruct object
- * @error: a place to store errors, or %NULL
- *
- * This method is similar to gda_meta_struct_complement() but creates #GdaMetaDbObject for all the
- * database object which are useable using only their short name (that is which do not need to be prefixed by
- * the schema in which they are to be used).
- *
- * Returns: TRUE if no error occurred
- */
-gboolean
-gda_meta_struct_complement_default (GdaMetaStruct *mstruct, GError **error)
+static gboolean
+real_gda_meta_struct_complement_all (GdaMetaStruct *mstruct, gboolean default_only, GError **error)
{
GdaDataModel *model;
gint i, nrows, k;
const GValue *cvalues[6];
const gchar *sql1 = "SELECT table_catalog, table_schema, table_name, table_short_name, table_full_name, table_owner "
- "FROM _tables WHERE table_short_name = table_name AND table_type='BASE TABLE' "
+ "FROM _tables WHERE table_short_name = table_name AND table_type LIKE '%TABLE%' "
"ORDER BY table_schema, table_name";
const gchar *sql2 = "SELECT table_catalog, table_schema, table_name, table_short_name, table_full_name, table_owner "
"FROM _tables WHERE table_short_name = table_name AND table_type='VIEW' "
@@ -1231,6 +1260,40 @@
}
/**
+ * gda_meta_struct_complement_default
+ * @mstruct: a #GdaMetaStruct object
+ * @error: a place to store errors, or %NULL
+ *
+ * This method is similar to gda_meta_struct_complement() and gda_meta_struct_complement_all()
+ * but creates #GdaMetaDbObject for all the
+ * database object which are useable using only their short name (that is which do not need to be prefixed by
+ * the schema in which they are to be used).
+ *
+ * Returns: TRUE if no error occurred
+ */
+gboolean
+gda_meta_struct_complement_default (GdaMetaStruct *mstruct, GError **error)
+{
+ return real_gda_meta_struct_complement_all (mstruct, TRUE, error);
+}
+
+/**
+ * gda_meta_struct_complement_all
+ * @mstruct: a #GdaMetaStruct object
+ * @error: a place to store errors, or %NULL
+ *
+ * This method is similar to gda_meta_struct_complement() and gda_meta_struct_complement_default()
+ * but creates #GdaMetaDbObject for all the database object.
+ *
+ * Returns: TRUE if no error occurred
+ */
+gboolean
+gda_meta_struct_complement_all (GdaMetaStruct *mstruct, GError **error)
+{
+ return real_gda_meta_struct_complement_all (mstruct, FALSE, error);
+}
+
+/**
* gda_meta_struct_complement_depend
* @mstruct: a #GdaMetaStruct object
* @dbo: a #GdaMetaDbObject part of @mstruct
@@ -1761,7 +1824,7 @@
}
case GDA_META_DB_TABLE: {
- const gchar *sql = "SELECT table_catalog, table_short_name, table_full_name, table_owner FROM _tables as t WHERE table_schema = ##ts::string AND table_short_name = ##tname::string AND table_name NOT IN (SELECT v.table_name FROM _views as v WHERE v.table_catalog=t.table_catalog AND v.table_schema=t.table_schema)";
+ const gchar *sql = "SELECT table_catalog, table_short_name, table_full_name, table_owner FROM _tables as t WHERE table_schema = ##ts::string AND table_name = ##tname::string AND table_name NOT IN (SELECT v.table_name FROM _views as v WHERE v.table_catalog=t.table_catalog AND v.table_schema=t.table_schema)";
gint nrows;
model = gda_meta_store_extract (mstruct->priv->store, sql, NULL, "ts", schema, "tname", name, NULL);
if (!model)
@@ -1793,7 +1856,7 @@
}
case GDA_META_DB_VIEW:{
- const gchar *sql = "SELECT table_catalog, table_short_name, table_full_name, table_owner FROM _tables NATURAL JOIN _views WHERE table_schema = ##ts::string AND table_short_name = ##tname::string";
+ const gchar *sql = "SELECT table_catalog, table_short_name, table_full_name, table_owner FROM _tables NATURAL JOIN _views WHERE table_schema = ##ts::string AND table_name = ##tname::string";
gint nrows;
model = gda_meta_store_extract (mstruct->priv->store, sql, NULL, "ts", schema, "tname", name, NULL);
if (!model)
Modified: trunk/libgda/gda-meta-struct.h
==============================================================================
--- trunk/libgda/gda-meta-struct.h (original)
+++ trunk/libgda/gda-meta-struct.h Mon Dec 1 19:56:29 2008
@@ -174,6 +174,7 @@
gboolean gda_meta_struct_complement_schema (GdaMetaStruct *mstruct,
const GValue *catalog, const GValue *schema, GError **error);
gboolean gda_meta_struct_complement_default (GdaMetaStruct *mstruct, GError **error);
+gboolean gda_meta_struct_complement_all (GdaMetaStruct *mstruct, GError **error);
gboolean gda_meta_struct_complement_depend (GdaMetaStruct *mstruct, GdaMetaDbObject *dbo,
GError **error);
Modified: trunk/providers/jdbc/GdaJMeta.c
==============================================================================
--- trunk/providers/jdbc/GdaJMeta.c (original)
+++ trunk/providers/jdbc/GdaJMeta.c Mon Dec 1 19:56:29 2008
@@ -11,6 +11,7 @@
JniWrapperMethod *GdaJMeta__getSchemas = NULL;
JniWrapperMethod *GdaJMeta__getTables = NULL;
JniWrapperMethod *GdaJMeta__getViews = NULL;
+JniWrapperMethod *GdaJMeta__getColumns = NULL;
JNIEXPORT void
JNICALL Java_GdaJMeta_initIDs (JNIEnv *env, jclass klass)
@@ -28,6 +29,7 @@
{"getSchemas", "(Ljava/lang/String;Ljava/lang/String;)LGdaJResultSet;", FALSE, &GdaJMeta__getSchemas},
{"getTables", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)LGdaJResultSet;", FALSE, &GdaJMeta__getTables},
{"getViews", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)LGdaJResultSet;", FALSE, &GdaJMeta__getViews},
+ {"getColumns", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)LGdaJResultSet;", FALSE, &GdaJMeta__getColumns},
};
for (i = 0; i < sizeof (methods) / sizeof (MethodSignature); i++) {
Modified: trunk/providers/jdbc/GdaJValue.c
==============================================================================
--- trunk/providers/jdbc/GdaJValue.c (original)
+++ trunk/providers/jdbc/GdaJValue.c Mon Dec 1 19:56:29 2008
@@ -46,11 +46,22 @@
{
GValue *value = gda_row_get_value (GDA_ROW ((gpointer) c_pointer), col);
gchar *tmp;
- gint len;
+ gint len, ulen;
len = (*jenv)->GetStringUTFLength (jenv, str);
+ if ((*jenv)->ExceptionCheck (jenv))
+ return;
+ ulen = (*jenv)->GetStringLength (jenv, str);
+ if ((*jenv)->ExceptionCheck (jenv))
+ return;
tmp = g_new (gchar, len + 1);
- (*jenv)->GetStringUTFRegion (jenv, str, 0, len, tmp);
+ tmp [len] = 0;
+ if (ulen > 0)
+ (*jenv)->GetStringUTFRegion (jenv, str, 0, ulen, tmp);
+ if ((*jenv)->ExceptionCheck (jenv)) {
+ g_free (tmp);
+ return;
+ }
g_value_init (value, G_TYPE_STRING);
g_value_take_string (value, tmp);
}
@@ -440,11 +451,22 @@
GdaNumeric *num;
GValue *value = gda_row_get_value (GDA_ROW ((gpointer) c_pointer), col);
gchar *tmp;
- gint len;
+ gint len, ulen;
len = (*jenv)->GetStringUTFLength (jenv, str);
+ if ((*jenv)->ExceptionCheck (jenv))
+ return;
+ ulen = (*jenv)->GetStringLength (jenv, str);
+ if ((*jenv)->ExceptionCheck (jenv))
+ return;
tmp = g_new (gchar, len + 1);
- (*jenv)->GetStringUTFRegion (jenv, str, 0, len, tmp);
+ tmp [len] = 0;
+ if (ulen > 0)
+ (*jenv)->GetStringUTFRegion (jenv, str, 0, ulen, tmp);
+ if ((*jenv)->ExceptionCheck (jenv)) {
+ g_free (tmp);
+ return;
+ }
num = g_new0 (GdaNumeric, 1);
num->number = tmp;
num->precision = precision;
Modified: trunk/providers/jdbc/Makefile.am
==============================================================================
--- trunk/providers/jdbc/Makefile.am (original)
+++ trunk/providers/jdbc/Makefile.am Mon Dec 1 19:56:29 2008
@@ -76,6 +76,7 @@
jdbcprov_sources = \
provider.java \
meta.java \
+ derby.java \
h2.java
jdbcprov_classes = GdaJConnection.class
Added: trunk/providers/jdbc/derby.java
==============================================================================
--- (empty file)
+++ trunk/providers/jdbc/derby.java Mon Dec 1 19:56:29 2008
@@ -0,0 +1,18 @@
+import java.sql.*;
+import java.util.*;
+import java.io.*;
+
+
+class org_apache_derbyMeta extends GdaJMeta {
+ public org_apache_derbyMeta (Connection cnc) throws Exception {
+ super (cnc);
+ ResultSet rs;
+ Statement stmt;
+ stmt = cnc.createStatement();
+ rs = stmt.executeQuery ("values current schema");
+ while (rs.next ()) {
+ schemaAddCurrent (rs.getString (1));
+ }
+ }
+}
+
Modified: trunk/providers/jdbc/doc/index.html
==============================================================================
--- trunk/providers/jdbc/doc/index.html (original)
+++ trunk/providers/jdbc/doc/index.html Mon Dec 1 19:56:29 2008
@@ -86,5 +86,16 @@
common (but not all) calls to JNI.
</p>
</div>
+
+<div>
+ <h1>Connection strings</h1>
+ <p>
+ <table>
+ <tr><th>Database</th><th>JDBC driver</th><th>Connection string template</th></tr>
+ <tr><td>H2</td><td>org.h2.Driver</td><td>URL=jdbc:h2:/path/to/h2db</td>
+ <tr><td>HSQLDB</td><td>org.hsqldb.jdbcDriver</td><td>URL=jdbc:hsqldb:/path/to/db</td>
+ </table>
+ </p>
+</div>
</body>
</html>
Modified: trunk/providers/jdbc/gda-jdbc-meta.c
==============================================================================
--- trunk/providers/jdbc/gda-jdbc-meta.c (original)
+++ trunk/providers/jdbc/gda-jdbc-meta.c Mon Dec 1 19:56:29 2008
@@ -349,7 +349,6 @@
if (!model)
goto out;
- gda_data_model_dump (model, stdout);
retval = gda_meta_store_modify_with_context (store, context, model, error);
out:
@@ -484,8 +483,7 @@
_gda_jdbc_meta__columns (GdaServerProvider *prov, GdaConnection *cnc,
GdaMetaStore *store, GdaMetaContext *context, GError **error)
{
- TO_IMPLEMENT;
- return TRUE;
+ return _gda_jdbc_meta_columns (prov, cnc, store, context, error, NULL, NULL, NULL);
}
gboolean
@@ -494,8 +492,80 @@
const GValue *table_catalog, const GValue *table_schema,
const GValue *table_name)
{
- TO_IMPLEMENT;
- return TRUE;
+ JdbcConnectionData *cdata;
+ GdaDataModel *model = NULL;
+ gboolean retval = FALSE;
+ gint error_code;
+ gchar *sql_state;
+ GValue *jexec_res;
+ GError *lerror = NULL;
+
+ JNIEnv *jenv = NULL;
+ gboolean jni_detach;
+
+ jstring catalog = NULL, schema = NULL, table = NULL;
+
+ /* Get private data */
+ cdata = (JdbcConnectionData*) gda_connection_internal_get_provider_data (cnc);
+ if (!cdata)
+ return FALSE;
+
+ jenv = _gda_jdbc_get_jenv (&jni_detach, error);
+ if (!jenv)
+ return FALSE;
+
+ if (! cdata->jmeta_obj && !init_meta_obj (cnc, jenv, cdata, error))
+ goto out;
+
+ if (table_catalog) {
+ catalog = (*jenv)->NewStringUTF (jenv, g_value_get_string (table_catalog));
+ if ((*jenv)->ExceptionCheck (jenv))
+ goto out;
+ }
+
+ if (table_schema) {
+ schema = (*jenv)->NewStringUTF (jenv, g_value_get_string (table_schema));
+ if ((*jenv)->ExceptionCheck (jenv))
+ goto out;
+ }
+
+ if (table_name) {
+ table = (*jenv)->NewStringUTF (jenv, g_value_get_string (table_name));
+ if ((*jenv)->ExceptionCheck (jenv))
+ goto out;
+ }
+
+ /* get data from JDBC */
+ jexec_res = jni_wrapper_method_call (jenv, GdaJMeta__getColumns,
+ cdata->jmeta_obj, &error_code, &sql_state, &lerror,
+ catalog, schema, table);
+ if (!jexec_res) {
+ if (error && lerror)
+ *error = g_error_copy (lerror);
+ _gda_jdbc_make_error (cnc, error_code, sql_state, lerror);
+ _gda_jdbc_release_jenv (jni_detach);
+ return FALSE;
+ }
+
+ model = (GdaDataModel *) gda_jdbc_recordset_new (cnc, NULL, NULL, jenv,
+ jexec_res, GDA_DATA_MODEL_ACCESS_RANDOM, NULL);
+ if (!model)
+ goto out;
+
+ retval = gda_meta_store_modify_with_context (store, context, model, error);
+
+ out:
+ if (catalog)
+ (*jenv)-> DeleteLocalRef (jenv, catalog);
+ if (schema)
+ (*jenv)-> DeleteLocalRef (jenv, schema);
+ if (table)
+ (*jenv)-> DeleteLocalRef (jenv, table);
+ if (model)
+ g_object_unref (model);
+ _gda_jdbc_release_jenv (jni_detach);
+
+ return retval;
}
gboolean
Modified: trunk/providers/jdbc/gda-jdbc-recordset.c
==============================================================================
--- trunk/providers/jdbc/gda-jdbc-recordset.c (original)
+++ trunk/providers/jdbc/gda-jdbc-recordset.c Mon Dec 1 19:56:29 2008
@@ -139,6 +139,7 @@
return type;
}
+/* Same as GdaJValue::jdbc_type_to_g_type */
static GType
jdbc_type_to_g_type (gint jdbc_type)
{
@@ -409,7 +410,7 @@
jexec_res = jni_wrapper_method_call (jenv, GdaJResultSet__fillNextRow,
model->priv->rs_value, &error_code, &sql_state, &lerror, (jlong) prow);
if (!jexec_res) {
- if (lerror)
+ if (error && lerror)
*error = g_error_copy (lerror);
_gda_jdbc_make_error (model->priv->cnc, error_code, sql_state, lerror);
return NULL;
Modified: trunk/providers/jdbc/h2.java
==============================================================================
--- trunk/providers/jdbc/h2.java (original)
+++ trunk/providers/jdbc/h2.java Mon Dec 1 19:56:29 2008
@@ -18,10 +18,6 @@
return cnc.getCatalog ();
}
- public GdaJResultSet getSchemas (String catalog, String schema) throws Exception {
- return new org_h2_DriverMetaSchemas (this, catalog, schema);
- }
-
public GdaJResultSet getTables (String catalog, String schema, String name) throws Exception {
return new org_h2_DriverMetaTables (this, catalog, schema, name);
}
@@ -50,62 +46,6 @@
}
/*
- * Meta data for schemas
- */
-class org_h2_DriverMetaSchemas extends GdaJMetaResultSet {
- ResultSet rs;
- String catalog = null;
- String schema = null;
-
- public org_h2_DriverMetaSchemas (GdaJMeta jm, String catalog, String schema) throws Exception {
- super (4, jm);
- meta_col_infos.add (new GdaJColumnInfos ("catalog_name", "catalog_name", java.sql.Types.VARCHAR));
- meta_col_infos.add (new GdaJColumnInfos ("schema_name", "schema_name", java.sql.Types.VARCHAR));
- meta_col_infos.add (new GdaJColumnInfos ("schema_owner", "owner", java.sql.Types.VARCHAR));
- meta_col_infos.add (new GdaJColumnInfos ("schema_internal", "is internal", java.sql.Types.BOOLEAN));
- rs = jm.md.getSchemas ();
- this.catalog = catalog;
- this.schema = schema;
- }
-
- protected void columnTypesDeclared () {
- GdaJValue cv = (GdaJValue) col_values.elementAt (0);
- cv.convert_lc = true;
- cv = (GdaJValue) col_values.elementAt (1);
- cv.convert_lc = true;
- cv = (GdaJValue) col_values.elementAt (3);
- cv.convert_lc = true;
- }
-
- public boolean fillNextRow (long c_pointer) throws Exception {
- if (! rs.next ())
- return false;
-
- GdaJValue cv;
-
- if (catalog != null) {
- String s = rs.getString (2);
- if (s != catalog)
- return fillNextRow (c_pointer);
- }
- if (schema != null) {
- String s = rs.getString (1);
- if (s != schema)
- return fillNextRow (c_pointer);
- }
-
- cv = (GdaJValue) col_values.elementAt (0);
- cv.setCValue (rs, 1, c_pointer);
- cv = (GdaJValue) col_values.elementAt (1);
- cv.setCValue (rs, 0, c_pointer);
- cv = (GdaJValue) col_values.elementAt (3);
- cv.setCBoolean (c_pointer, 3, false);
-
- return true;
- }
-}
-
-/*
* Meta data for tables
*/
class org_h2_DriverMetaTables extends GdaJMetaTables {
@@ -114,23 +54,6 @@
rs = md.getTables (catalog, schema, name, null);
}
- protected void columnTypesDeclared () {
- GdaJValue cv = (GdaJValue) col_values.elementAt (0);
- cv.convert_lc = true;
- cv = (GdaJValue) col_values.elementAt (1);
- cv.convert_lc = true;
- cv = (GdaJValue) col_values.elementAt (2);
- cv.convert_lc = true;
- cv = (GdaJValue) col_values.elementAt (3);
- cv.convert_lc = true;
- cv = (GdaJValue) col_values.elementAt (5);
- cv.convert_lc = true;
- cv = (GdaJValue) col_values.elementAt (6);
- cv.convert_lc = true;
- cv = (GdaJValue) col_values.elementAt (7);
- cv.convert_lc = true;
- }
-
public boolean fillNextRow (long c_pointer) throws Exception {
if (! rs.next ())
return false;
@@ -172,10 +95,9 @@
protected void columnTypesDeclared () {
GdaJValue cv = (GdaJValue) col_values.elementAt (0);
+ cv.no_null = true;
cv.convert_lc = true;
- cv = (GdaJValue) col_values.elementAt (1);
- cv.convert_lc = true;
- cv = (GdaJValue) col_values.elementAt (2);
- cv.convert_lc = true;
+ ((GdaJValue) col_values.elementAt (1)).convert_lc = true;
+ ((GdaJValue) col_values.elementAt (2)).convert_lc = true;
}
}
Modified: trunk/providers/jdbc/jni-globals.h
==============================================================================
--- trunk/providers/jdbc/jni-globals.h (original)
+++ trunk/providers/jdbc/jni-globals.h Mon Dec 1 19:56:29 2008
@@ -57,6 +57,7 @@
extern JniWrapperMethod *GdaJMeta__getSchemas;
extern JniWrapperMethod *GdaJMeta__getTables;
extern JniWrapperMethod *GdaJMeta__getViews;
+extern JniWrapperMethod *GdaJMeta__getColumns;
/* debug features */
Modified: trunk/providers/jdbc/jni-wrapper.c
==============================================================================
--- trunk/providers/jdbc/jni-wrapper.c (original)
+++ trunk/providers/jdbc/jni-wrapper.c Mon Dec 1 19:56:29 2008
@@ -122,7 +122,7 @@
if (g_getenv ("GDA_JAVA_OPTION")) {
const gchar *opt = g_getenv ("GDA_JAVA_OPTION");
- options[vm_args.nOptions].optionString = opt;
+ options[vm_args.nOptions].optionString = (gchar*) opt;
vm_args.nOptions++;
}
vm_args.version = JNI_VERSION_1_2;
@@ -361,7 +361,8 @@
g_free (res);
}
else {
- g_value_unset (res);
+ if (G_VALUE_TYPE (res) != 0) /* GDA_TYPE_NULL */
+ g_value_unset (res);
g_free (res);
goto fallback;
}
@@ -483,17 +484,28 @@
if (!strcmp (method->ret_type, "Ljava/lang/String;")) {
jstring string;
gchar *str;
- gint len;
if (method->is_static)
string = (*jenv)->CallStaticObjectMethodV (jenv, method->klass,
method->mid, args);
else
string = (*jenv)->CallObjectMethodV (jenv, jobj, method->mid, args);
if (string) {
+ gint len, ulen;
g_value_init (retval, G_TYPE_STRING);
len = (*jenv)->GetStringUTFLength (jenv, string);
+ if ((*jenv)->ExceptionCheck (jenv))
+ break;
+ ulen = (*jenv)->GetStringLength (jenv, string);
+ if ((*jenv)->ExceptionCheck (jenv))
+ break;
str = g_new (gchar, len + 1);
- (*jenv)->GetStringUTFRegion (jenv, string, 0, len, str);
+ str [len] = 0;
+ if (ulen > 0)
+ (*jenv)->GetStringUTFRegion (jenv, string, 0, ulen, str);
+ if ((*jenv)->ExceptionCheck (jenv)) {
+ g_free (str);
+ break;
+ }
g_value_take_string (retval, str);
(*jenv)-> DeleteLocalRef (jenv, string);
@@ -688,16 +700,28 @@
if (!strcmp (field->type, "Ljava/lang/String;")) {
jstring string;
gchar *str;
- gint len;
if (field->is_static)
string = (*jenv)->GetStaticObjectField (jenv, field->klass, field->fid);
else
string = (*jenv)->GetObjectField (jenv, jobj, field->fid);
if (string) {
+ gint len, ulen;
g_value_init (retval, G_TYPE_STRING);
len = (*jenv)->GetStringUTFLength (jenv, string);
+ if ((*jenv)->ExceptionCheck (jenv))
+ break;
+ ulen = (*jenv)->GetStringLength (jenv, string);
+ if ((*jenv)->ExceptionCheck (jenv))
+ break;
+
str = g_new (gchar, len + 1);
- (*jenv)->GetStringUTFRegion (jenv, string, 0, len, str);
+ str [len] = 0;
+ if (ulen > 0)
+ (*jenv)->GetStringUTFRegion (jenv, string, 0, ulen, str);
+ if ((*jenv)->ExceptionCheck (jenv)) {
+ g_free (str);
+ break;
+ }
g_value_take_string (retval, str);
(*jenv)-> DeleteLocalRef (jenv, string);
Modified: trunk/providers/jdbc/meta.java
==============================================================================
--- trunk/providers/jdbc/meta.java (original)
+++ trunk/providers/jdbc/meta.java Mon Dec 1 19:56:29 2008
@@ -46,6 +46,10 @@
return new GdaJMetaViews (this, catalog, schema, name);
}
+ public GdaJResultSet getColumns (String catalog, String schema, String tab_name) throws Exception {
+ return new GdaJMetaColumns (this, catalog, schema, tab_name);
+ }
+
// class initializer
static {
initIDs ();
@@ -102,16 +106,15 @@
* Meta data for schemas
*/
class GdaJMetaSchemas extends GdaJMetaResultSet {
- ResultSet rs;
String catalog = null;
String schema = null;
public GdaJMetaSchemas (GdaJMeta jm, String catalog, String schema) throws Exception {
super (4, jm);
- meta_col_infos.add (new GdaJColumnInfos ("catalog_name", "catalog_name", java.sql.Types.VARCHAR));
- meta_col_infos.add (new GdaJColumnInfos ("schema_name", "schema_name", java.sql.Types.VARCHAR));
- meta_col_infos.add (new GdaJColumnInfos ("schema_owner", "owner", java.sql.Types.VARCHAR));
- meta_col_infos.add (new GdaJColumnInfos ("schema_internal", "is internal", java.sql.Types.BOOLEAN));
+ meta_col_infos.add (new GdaJColumnInfos ("catalog_name", null, java.sql.Types.VARCHAR));
+ meta_col_infos.add (new GdaJColumnInfos ("schema_name", null, java.sql.Types.VARCHAR));
+ meta_col_infos.add (new GdaJColumnInfos ("schema_owner", null, java.sql.Types.VARCHAR));
+ meta_col_infos.add (new GdaJColumnInfos ("schema_internal", null, java.sql.Types.BOOLEAN));
rs = jm.md.getSchemas ();
this.catalog = catalog;
this.schema = schema;
@@ -180,6 +183,7 @@
// the catalog part cannot be NULL, but "" instead
GdaJValue cv = (GdaJValue) col_values.elementAt (0);
cv.no_null = true;
+ cv.convert_lc = true;
((GdaJValue) col_values.elementAt (1)).convert_lc = true;
((GdaJValue) col_values.elementAt (2)).convert_lc = true;
((GdaJValue) col_values.elementAt (6)).convert_lc = true;
@@ -240,6 +244,7 @@
// the catalog part cannot be NULL, but "" instead
GdaJValue cv = (GdaJValue) col_values.elementAt (0);
cv.no_null = true;
+ cv.convert_lc = true;
((GdaJValue) col_values.elementAt (1)).convert_lc = true;
((GdaJValue) col_values.elementAt (2)).convert_lc = true;
}
@@ -259,4 +264,93 @@
return true;
}
+}
+
+/*
+ * Meta data for table's columns
+ */
+class GdaJMetaColumns extends GdaJMetaResultSet {
+ protected GdaJMetaColumns (GdaJMeta jm) {
+ super (24, jm);
+ meta_col_infos.add (new GdaJColumnInfos ("table_catalog", null, java.sql.Types.VARCHAR));
+ meta_col_infos.add (new GdaJColumnInfos ("table_schema", null, java.sql.Types.VARCHAR));
+ meta_col_infos.add (new GdaJColumnInfos ("table_name", null, java.sql.Types.VARCHAR));
+ meta_col_infos.add (new GdaJColumnInfos ("column_name", null, java.sql.Types.VARCHAR));
+ meta_col_infos.add (new GdaJColumnInfos ("ordinal_position", null, java.sql.Types.INTEGER));
+ meta_col_infos.add (new GdaJColumnInfos ("column_default", null, java.sql.Types.VARCHAR));
+ meta_col_infos.add (new GdaJColumnInfos ("is_nullable", null, java.sql.Types.BOOLEAN));
+ meta_col_infos.add (new GdaJColumnInfos ("data_type", null, java.sql.Types.VARCHAR));
+ meta_col_infos.add (new GdaJColumnInfos ("array_spec", null, java.sql.Types.VARCHAR));
+ meta_col_infos.add (new GdaJColumnInfos ("gtype", null, java.sql.Types.VARCHAR));
+ meta_col_infos.add (new GdaJColumnInfos ("character_maximum_length", null, java.sql.Types.INTEGER));
+ meta_col_infos.add (new GdaJColumnInfos ("character_octet_length", null, java.sql.Types.INTEGER));
+ meta_col_infos.add (new GdaJColumnInfos ("numeric_precision", null, java.sql.Types.INTEGER));
+ meta_col_infos.add (new GdaJColumnInfos ("numeric_scale", null, java.sql.Types.INTEGER));
+ meta_col_infos.add (new GdaJColumnInfos ("datetime_precision", null, java.sql.Types.INTEGER));
+ meta_col_infos.add (new GdaJColumnInfos ("character_set_catalog", null, java.sql.Types.VARCHAR));
+ meta_col_infos.add (new GdaJColumnInfos ("character_set_schema", null, java.sql.Types.VARCHAR));
+ meta_col_infos.add (new GdaJColumnInfos ("character_set_name", null, java.sql.Types.VARCHAR));
+ meta_col_infos.add (new GdaJColumnInfos ("collation_catalog", null, java.sql.Types.VARCHAR));
+ meta_col_infos.add (new GdaJColumnInfos ("collation_schema", null, java.sql.Types.VARCHAR));
+ meta_col_infos.add (new GdaJColumnInfos ("collation_name", null, java.sql.Types.VARCHAR));
+ meta_col_infos.add (new GdaJColumnInfos ("extra", null, java.sql.Types.VARCHAR));
+ meta_col_infos.add (new GdaJColumnInfos ("is_updatable", null, java.sql.Types.VARCHAR));
+ meta_col_infos.add (new GdaJColumnInfos ("column_comments", null, java.sql.Types.VARCHAR));
+
+ md = jm.md;
+ }
+
+ public GdaJMetaColumns (GdaJMeta jm, String catalog, String schema, String tab_name) throws Exception {
+ this (jm);
+ rs = jm.md.getColumns (catalog, schema, tab_name, null);
+ }
+
+ protected void columnTypesDeclared () {
+ // the catalog part cannot be NULL, but "" instead
+ GdaJValue cv = (GdaJValue) col_values.elementAt (0);
+ cv.no_null = true;
+ cv.convert_lc = true;
+ ((GdaJValue) col_values.elementAt (1)).convert_lc = true;
+ ((GdaJValue) col_values.elementAt (2)).convert_lc = true;
+ ((GdaJValue) col_values.elementAt (3)).convert_lc = true;
+ ((GdaJValue) col_values.elementAt (7)).convert_lc = true;
+ ((GdaJValue) col_values.elementAt (15)).convert_lc = true;
+ ((GdaJValue) col_values.elementAt (16)).convert_lc = true;
+ ((GdaJValue) col_values.elementAt (17)).convert_lc = true;
+ ((GdaJValue) col_values.elementAt (18)).convert_lc = true;
+ ((GdaJValue) col_values.elementAt (19)).convert_lc = true;
+ ((GdaJValue) col_values.elementAt (20)).convert_lc = true;
+ }
+
+ public boolean fillNextRow (long c_pointer) throws Exception {
+ if (! rs.next ())
+ return false;
+
+ GdaJValue cv;
+ int i, r;
+
+ ((GdaJValue) col_values.elementAt (0)).setCValue (rs, 0, c_pointer);
+ ((GdaJValue) col_values.elementAt (1)).setCValue (rs, 1, c_pointer);
+ ((GdaJValue) col_values.elementAt (2)).setCValue (rs, 2, c_pointer);
+ ((GdaJValue) col_values.elementAt (3)).setCValue (rs, 3, c_pointer);
+ ((GdaJValue) col_values.elementAt (4)).setCValue (rs, 16, c_pointer);
+ ((GdaJValue) col_values.elementAt (5)).setCValue (rs, 12, c_pointer);
+ cv = (GdaJValue) col_values.elementAt (6);
+ i = rs.getInt (10);
+ if (i == DatabaseMetaData.columnNoNulls)
+ cv.setCBoolean (c_pointer, 6, false);
+ else
+ cv.setCBoolean (c_pointer, 6, true);
+ ((GdaJValue) col_values.elementAt (7)).setCValue (rs, 5, c_pointer);
+
+ ((GdaJValue) col_values.elementAt (9)).setCString (c_pointer, 9,
+ GdaJValue.jdbc_type_to_g_type (rs.getInt (5))); // gtype
+
+ ((GdaJValue) col_values.elementAt (11)).setCValue (rs, 15, c_pointer);
+ ((GdaJValue) col_values.elementAt (12)).setCValue (rs, 8, c_pointer); // numeric_precision
+
+ ((GdaJValue) col_values.elementAt (23)).setCValue (rs, 11, c_pointer); // comments
+
+ return true;
+ }
}
\ No newline at end of file
Modified: trunk/providers/jdbc/provider.java
==============================================================================
--- trunk/providers/jdbc/provider.java (original)
+++ trunk/providers/jdbc/provider.java Mon Dec 1 19:56:29 2008
@@ -37,7 +37,7 @@
catch (Exception e) {
// ignore exceptions, they mean some drivers are not available
}
-
+
java.util.Enumeration e = DriverManager.getDrivers();
String res = null;
while (e.hasMoreElements ()) {
@@ -228,14 +228,26 @@
String name= driver.replace (".", "_") + "Meta";
try {
Class<?> r = Class.forName (name);
- java.lang.reflect.Constructor c = r.getConstructor (new Class [] {Class.forName ("java.sql.Connection")});
+ java.lang.reflect.Constructor c =
+ r.getConstructor (new Class [] {Class.forName ("java.sql.Connection")});
jmeta = (GdaJMeta) c.newInstance (new Object [] {cnc});
}
catch (Exception e) {
- System.out.println ("Could not load Class " + name);
- e.printStackTrace ();
- jmeta = new GdaJMeta (cnc);
+ if (driver.contains ("org.apache.derby.jdbc")) {
+ try {
+ name = "org_apache_derbyMeta";
+ Class<?> r = Class.forName (name);
+ java.lang.reflect.Constructor c =
+ r.getConstructor (new Class [] {Class.forName ("java.sql.Connection")});
+ jmeta = (GdaJMeta) c.newInstance (new Object [] {cnc});
+ }
+ catch (Exception e1) {
+ // nothing
+ }
+ }
}
+ if (jmeta == null)
+ jmeta = new GdaJMeta (cnc);
}
return jmeta;
}
@@ -588,6 +600,71 @@
return cv;
}
+ // Same as gda-jdbc-recordset.c::jdbc_type_to_g_type
+ public static String jdbc_type_to_g_type (int type) {
+ switch (type) {
+ case java.sql.Types.VARCHAR:
+ return "gchararray";
+ case java.sql.Types.ARRAY:
+ return "GdaBinary";
+ case java.sql.Types.BIGINT:
+ return "int64";
+ case java.sql.Types.BINARY:
+ return "GdaBinary";
+ case java.sql.Types.BIT:
+ return "gboolean";
+ case java.sql.Types.BLOB:
+ return "GdaBlob";
+ case java.sql.Types.BOOLEAN:
+ return "gboolean";
+ case java.sql.Types.CHAR:
+ return "gchararray";
+ case java.sql.Types.CLOB:
+ case java.sql.Types.DATALINK:
+ return "GdaBinary";
+ case java.sql.Types.DATE:
+ return "GDate";
+ case java.sql.Types.DECIMAL:
+ return "GdaNumeric";
+ case java.sql.Types.DISTINCT:
+ return "GdaBinary";
+ case java.sql.Types.DOUBLE:
+ return "double";
+ case java.sql.Types.FLOAT:
+ return "float";
+ case java.sql.Types.INTEGER:
+ return "int";
+ case java.sql.Types.JAVA_OBJECT:
+ case java.sql.Types.LONGVARBINARY:
+ return "GdaBinary";
+ case java.sql.Types.LONGVARCHAR:
+ return "gchararray";
+ case java.sql.Types.NULL:
+ return null;
+ case java.sql.Types.NUMERIC:
+ return "GdaNumeric";
+ case java.sql.Types.OTHER:
+ return "GdaBinary";
+ case java.sql.Types.REAL:
+ return "float";
+ case java.sql.Types.REF:
+ return "GdaBinary";
+ case java.sql.Types.SMALLINT:
+ return "GdaStort";
+ case java.sql.Types.STRUCT:
+ return "GdaBinary";
+ case java.sql.Types.TIME:
+ return "GdaTime";
+ case java.sql.Types.TIMESTAMP:
+ return "GdaTimestamp";
+ case java.sql.Types.TINYINT:
+ return "gchar";
+ case java.sql.Types.VARBINARY:
+ default:
+ return "GdaBinary";
+ }
+ }
+
public static String toLower (String string) {
String s2 = string.toUpperCase();
if (s2 == string)
Modified: trunk/tools/command-exec.c
==============================================================================
--- trunk/tools/command-exec.c (original)
+++ trunk/tools/command-exec.c Mon Dec 1 19:56:29 2008
@@ -508,8 +508,8 @@
GValue *v;
const gchar *sql = "SELECT table_schema AS Schema, table_name AS Name, table_type as Type, "
"table_owner as Owner, table_comments as Description "
- "FROM _tables WHERE table_name=##tname::string AND "
- "table_type LIKE '%TABLE%' AND table_short_name = table_name "
+ "FROM _tables WHERE table_short_name=##tname::string AND "
+ "table_type LIKE '%TABLE%' "
"ORDER BY table_schema, table_name";
gchar *tmp = gda_sql_identifier_remove_quotes (g_strdup (args[0]));
@@ -520,7 +520,7 @@
else {
const gchar *sql = "SELECT table_schema AS Schema, table_name AS Name, table_type as Type, "
"table_owner as Owner, table_comments as Description "
- "FROM _tables WHERE table_type LIKE '%TABLE%' AND table_short_name = table_name "
+ "FROM _tables WHERE table_type LIKE '%TABLE%' "
"ORDER BY table_schema, table_name";
model = gda_meta_store_extract (gda_connection_get_meta_store (cnc), sql, error);
}
@@ -551,8 +551,8 @@
GValue *v;
const gchar *sql = "SELECT table_schema AS Schema, table_name AS Name, table_type as Type, "
"table_owner as Owner, table_comments as Description "
- "FROM _tables WHERE table_name=##tname::string AND "
- "table_type = 'VIEW' AND table_short_name = table_name "
+ "FROM _tables WHERE table_short_name=##tname::string AND "
+ "table_type = 'VIEW' "
"ORDER BY table_schema, table_name";
g_value_set_string (v = gda_value_new (G_TYPE_STRING), args[0]);
@@ -562,7 +562,7 @@
else {
const gchar *sql = "SELECT table_schema AS Schema, table_name AS Name, table_type as Type, "
"table_owner as Owner, table_comments as Description "
- "FROM _tables WHERE table_type='VIEW' AND table_short_name = table_name "
+ "FROM _tables WHERE table_type='VIEW' "
"ORDER BY table_schema, table_name";
model = gda_meta_store_extract (gda_connection_get_meta_store (cnc), sql, error);
}
@@ -631,9 +631,18 @@
mstruct = gda_meta_struct_new (store, GDA_META_STRUCT_FEATURE_ALL);
if (!args[0]) {
- /* use all tables or views */
+ GSList *list;
+ /* use all tables or views visible by default */
if (!gda_meta_struct_complement_default (mstruct, error))
goto onerror;
+ list = gda_meta_struct_get_all_db_objects (mstruct);
+ if (!list) {
+ /* use all tables or views visible or not by default */
+ if (!gda_meta_struct_complement_all (mstruct, error))
+ goto onerror;
+ }
+ else
+ g_slist_free (list);
}
for (index = 0, arg = args[0]; arg; index++, arg = args[index]) {
@@ -714,12 +723,21 @@
}
if (!args[0] || !*args[0]) {
+ /* FIXME: include indexes and sequences when they are present in the information schema */
/* displays all tables, views, indexes and sequences which are "directly visible" */
const gchar *sql = "SELECT table_schema AS Schema, table_name AS Name, table_type as Type, "
"table_owner as Owner FROM _tables WHERE table_short_name = table_name "
"ORDER BY table_schema, table_name";
- /* FIXME: include indexes and sequences when they are present in the information schema */
model = gda_meta_store_extract (gda_connection_get_meta_store (cnc), sql, error, NULL);
+
+ /* if no row, then return all the objects from all the schemas */
+ if (model && (gda_data_model_get_n_rows (model) == 0)) {
+ g_object_unref (model);
+ sql = "SELECT table_schema AS Schema, table_name AS Name, table_type as Type, "
+ "table_owner as Owner FROM _tables "
+ "ORDER BY table_schema, table_name";
+ model = gda_meta_store_extract (gda_connection_get_meta_store (cnc), sql, error, NULL);
+ }
res = g_new0 (GdaInternalCommandResult, 1);
res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
res->u.model = model;
@@ -764,7 +782,7 @@
val = gda_value_new (G_TYPE_STRING);
switch (dbo->obj_type) {
case GDA_META_DB_TABLE:
- g_value_set_string (val, "BASE TABLE");
+ g_value_set_string (val, "TABLE");
break;
case GDA_META_DB_VIEW:
g_value_set_string (val, "VIEW");
Modified: trunk/tools/gda-sql.c
==============================================================================
--- trunk/tools/gda-sql.c (original)
+++ trunk/tools/gda-sql.c Mon Dec 1 19:56:29 2008
@@ -1378,7 +1378,44 @@
static GdaDataModel *
list_all_providers (MainData *data)
{
- return gda_config_list_providers ();
+ GdaDataModel *prov_list, *model;
+ gint i, nrows;
+
+ prov_list = gda_config_list_providers ();
+
+ 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"));
+
+ nrows = gda_data_model_get_n_rows (prov_list);
+ for (i =0; i < nrows; i++) {
+ const GValue *value;
+ GList *list = NULL;
+ value = gda_data_model_get_value_at (prov_list, 0, i, NULL);
+ if (!value)
+ goto onerror;
+ list = g_list_append (list, gda_value_copy (value));
+ value = gda_data_model_get_value_at (prov_list, 1, i, NULL);
+ if (!value)
+ goto onerror;
+ list = g_list_append (list, gda_value_copy (value));
+
+ if (gda_data_model_append_values (model, list, NULL) == -1)
+ goto onerror;
+
+ g_list_foreach (list, (GFunc) gda_value_free, NULL);
+ g_list_free (list);
+ }
+ g_object_unref (prov_list);
+ return model;
+ onerror:
+ g_warning ("Could not obtain the list of database providers");
+ g_object_unref (prov_list);
+ g_object_unref (model);
+ return NULL;
}
static gchar **args_as_string_func (const gchar *str);
Modified: trunk/tools/tools-input.c
==============================================================================
--- trunk/tools/tools-input.c (original)
+++ trunk/tools/tools-input.c Mon Dec 1 19:56:29 2008
@@ -197,7 +197,7 @@
HIST_ENTRY *current;
- current = current_history ();
+ current = history_get (history_length);
if (current && current->line && !strcmp (current->line, txt))
return;
add_history (txt);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]