From: Andrea Zagli Date: Sat, 25 Jul 2009 19:10:22 +0000 (+0200) Subject: Initial commit. X-Git-Tag: 0.1.0~10 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=43ae46dfa055b96d4a9f2c874850c05c4d608775;p=libgdaex Initial commit. --- 43ae46dfa055b96d4a9f2c874850c05c4d608775 diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..ad1de0f --- /dev/null +++ b/AUTHORS @@ -0,0 +1 @@ +Andrea Zagli diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..5a74dd4 --- /dev/null +++ b/ChangeLog @@ -0,0 +1,27 @@ +2006-11-01: Andrea Zagli + + * gdaobj.c: added function gdao_get_chr_quoting to solve a problem about + quoting reserved words + +2006-09-06 Andrea Zagli + + * gdaobj.c: some bugfixes + +2006-09-03 Andrea Zagli + + * gdaobj.c: gdao_strescape(): escaped ' with a double ' + +2006-08-19 Andrea Zagli + + * libgdaobj.h: + * gdaobj.c: converted GdaO into a GObject + +2006-08-18 Andrea Zagli + + * libgdaobj.h: + * gdaobj.c: added function gdao_strescape + * configure.ac: some improvement + +2006-07-28 Andrea Zagli + + * gdaobj.c: added trap for gdao NULL into gdao_query diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..a4e8fbd --- /dev/null +++ b/Makefile.am @@ -0,0 +1,8 @@ +DISTCHECK_CONFIGURE_FLAGS = --enable-gtk-doc + +SUBDIRS = src docs + +EXTRA_DIST = libgdaobj.pc.in + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = libgdaobj.pc diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..e69de29 diff --git a/README b/README new file mode 100644 index 0000000..e69de29 diff --git a/TODO b/TODO new file mode 100644 index 0000000..c1cac31 --- /dev/null +++ b/TODO @@ -0,0 +1 @@ +- gdao_free() diff --git a/config.h.in b/config.h.in new file mode 100644 index 0000000..7f52201 --- /dev/null +++ b/config.h.in @@ -0,0 +1,64 @@ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the header file. */ +#undef HAVE_DLFCN_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the `strcasecmp' function. */ +#undef HAVE_STRCASECMP + +/* Define to 1 if you have the `strchr' function. */ +#undef HAVE_STRCHR + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_UNISTD_H + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Version number of package */ +#undef VERSION + +/* Define to empty if `const' does not conform to ANSI C. */ +#undef const diff --git a/config.h.in~ b/config.h.in~ new file mode 100644 index 0000000..7f52201 --- /dev/null +++ b/config.h.in~ @@ -0,0 +1,64 @@ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the header file. */ +#undef HAVE_DLFCN_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the `strcasecmp' function. */ +#undef HAVE_STRCASECMP + +/* Define to 1 if you have the `strchr' function. */ +#undef HAVE_STRCHR + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_UNISTD_H + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Version number of package */ +#undef VERSION + +/* Define to empty if `const' does not conform to ANSI C. */ +#undef const diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..9780547 --- /dev/null +++ b/configure.ac @@ -0,0 +1,51 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ(2.59) +AC_INIT([libgdaobj], [0.0.2], [azagli@libero.it]) +AC_CONFIG_SRCDIR([src/gdaobj.c]) +AM_CONFIG_HEADER([config.h]) + +AM_INIT_AUTOMAKE +AM_MAINTAINER_MODE + +AC_LIBTOOL_WIN32_DLL + +AC_CANONICAL_SYSTEM + +# Checks for programs. +AC_PROG_CXX +AC_PROG_CC +AC_PROG_CPP +AC_PROG_INSTALL +AC_PROG_LN_S +AC_PROG_MAKE_SET +AC_PROG_LIBTOOL + +GTK_DOC_CHECK(1.0) + +# Checks for libraries. +PKG_CHECK_MODULES(GDAOBJ, [libgda >= 1.2.0]) + +AC_SUBST(GDAOBJ_CFLAGS) +AC_SUBST(GDAOBJ_LIBS) + +# Checks for header files. +AC_HEADER_STDC +AC_CHECK_HEADERS([string.h]) + +# Checks for typedefs, structures, and compiler characteristics. +AC_C_CONST + +# Checks for library functions. +AC_CHECK_FUNCS([strchr strcasecmp]) + +AC_CONFIG_FILES([ + libgdaobj.pc + Makefile + src/Makefile + docs/Makefile + docs/reference/Makefile + docs/reference/version.xml +]) +AC_OUTPUT diff --git a/docs/Makefile.am b/docs/Makefile.am new file mode 100644 index 0000000..f3ddc22 --- /dev/null +++ b/docs/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = reference diff --git a/docs/reference/Makefile.am b/docs/reference/Makefile.am new file mode 100644 index 0000000..63eaa8a --- /dev/null +++ b/docs/reference/Makefile.am @@ -0,0 +1,78 @@ +## Process this file with automake to produce Makefile.in + +# We require automake 1.6 at least. +AUTOMAKE_OPTIONS = 1.6 + +# This is a blank Makefile.am for using gtk-doc. +# Copy this to your project's API docs directory and modify the variables to +# suit your project. See the GTK+ Makefiles in gtk+/docs/reference for examples +# of using the various options. + +# The name of the module, e.g. 'glib'. +DOC_MODULE=libgdaoj + +# The top-level SGML file. You can change this if you want to. +DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.sgml + +# The directory containing the source code. Relative to $(srcdir). +# gtk-doc will search all .c & .h files beneath here for inline comments +# documenting the functions and macros. +# e.g. DOC_SOURCE_DIR=../../../gtk +DOC_SOURCE_DIR=../../src + +# Extra options to pass to gtkdoc-scangobj. Not normally needed. +SCANGOBJ_OPTIONS= + +# Extra options to supply to gtkdoc-scan. +# e.g. SCAN_OPTIONS=--deprecated-guards="GTK_DISABLE_DEPRECATED" +SCAN_OPTIONS= + +# Extra options to supply to gtkdoc-mkdb. +# e.g. MKDB_OPTIONS=--sgml-mode --output-format=xml +MKDB_OPTIONS=--sgml-mode --output-format=xml + +# Extra options to supply to gtkdoc-mktmpl +# e.g. MKTMPL_OPTIONS=--only-section-tmpl +MKTMPL_OPTIONS= + +# Extra options to supply to gtkdoc-fixref. Not normally needed. +# e.g. FIXXREF_OPTIONS=--extra-dir=../gdk-pixbuf/html --extra-dir=../gdk/html +FIXXREF_OPTIONS= + +# Used for dependencies. The docs will be rebuilt if any of these change. +# e.g. HFILE_GLOB=$(top_srcdir)/gtk/*.h +# e.g. CFILE_GLOB=$(top_srcdir)/gtk/*.c +HFILE_GLOB=$(top_srcdir)/src/*.h +CFILE_GLOB=$(top_srcdir)/src/*.c + +# Header files to ignore when scanning. +# e.g. IGNORE_HFILES=gtkdebug.h gtkintl.h +IGNORE_HFILES= + +# Images to copy into HTML directory. +# e.g. HTML_IMAGES=$(top_srcdir)/gtk/stock-icons/stock_about_24.png +HTML_IMAGES= + +# Extra SGML files that are included by $(DOC_MAIN_SGML_FILE). +# e.g. content_files=running.sgml building.sgml changes-2.0.sgml +content_files=version.xml + +# SGML files where gtk-doc abbrevations (#GtkWidget) are expanded +# These files must be listed here *and* in content_files +# e.g. expand_content_files=running.sgml +expand_content_files= + +# CFLAGS and LDFLAGS for compiling gtkdoc-scangobj with your library. +# Only needed if you are using gtkdoc-scangobj to dynamically query widget +# signals and properties. +# e.g. INCLUDES=-I$(top_srcdir) -I$(top_builddir) $(GTK_DEBUG_FLAGS) +# e.g. GTKDOC_LIBS=$(top_builddir)/gtk/$(gtktargetlib) +INCLUDES=-I$(top_srcdir)/src $(GDAOBJ_CFLAGS) +GTKDOC_LIBS=$(top_builddir)/src/libgdaobj.la $(GDAOBJ_LIBS) + +# This includes the standard gtk-doc make rules, copied by gtkdocize. +include $(top_srcdir)/gtk-doc.make + +# Other files to distribute +# e.g. EXTRA_DIST += version.xml.in +EXTRA_DIST += version.xml.in diff --git a/docs/reference/libgdaoj-docs.sgml b/docs/reference/libgdaoj-docs.sgml new file mode 100644 index 0000000..3655b24 --- /dev/null +++ b/docs/reference/libgdaoj-docs.sgml @@ -0,0 +1,16 @@ + + +]> + + + libgdaobj Reference Manual + for libgdaobj &version; + + + + libgdaobj + + + diff --git a/docs/reference/libgdaoj-overrides.txt b/docs/reference/libgdaoj-overrides.txt new file mode 100644 index 0000000..e69de29 diff --git a/docs/reference/libgdaoj-sections.txt b/docs/reference/libgdaoj-sections.txt new file mode 100644 index 0000000..5a6b590 --- /dev/null +++ b/docs/reference/libgdaoj-sections.txt @@ -0,0 +1,29 @@ +
+libgdaobj +GdaO +gdao_new +gdao_new_from_string +gdao_new_from_connection +gdao_get_gdaclient +gdao_get_gdaconnection +gdao_get_provider +gdao_query +gdao_data_model_get_field_value_stringify_at +gdao_data_model_get_field_value_integer_at +gdao_data_model_get_field_value_float_at +gdao_data_model_get_field_value_double_at +gdao_data_model_get_field_value_boolean_at +gdao_data_model_get_field_value_gdate_at +gdao_data_model_get_value_stringify_at +gdao_data_model_get_value_integer_at +gdao_data_model_get_value_float_at +gdao_data_model_get_value_double_at +gdao_data_model_get_value_boolean_at +gdao_data_model_get_value_gdate_at +gdao_begin +gdao_execute +gdao_commit +gdao_rollback +gdao_free +
+ diff --git a/docs/reference/libgdaoj-undocumented.txt b/docs/reference/libgdaoj-undocumented.txt new file mode 100644 index 0000000..7e74d4d --- /dev/null +++ b/docs/reference/libgdaoj-undocumented.txt @@ -0,0 +1,30 @@ +30% symbol docs coverage. +8 symbols documented. +3 symbols incomplete. +19 not documented. + + +GdaO +gdao_begin (Returns) +gdao_commit (Returns) +gdao_data_model_get_field_value_boolean_at +gdao_data_model_get_field_value_double_at +gdao_data_model_get_field_value_float_at +gdao_data_model_get_field_value_gdate_at +gdao_data_model_get_field_value_integer_at +gdao_data_model_get_field_value_stringify_at +gdao_data_model_get_value_boolean_at +gdao_data_model_get_value_double_at +gdao_data_model_get_value_float_at +gdao_data_model_get_value_gdate_at +gdao_data_model_get_value_integer_at +gdao_data_model_get_value_stringify_at +gdao_free +gdao_get_gdaclient +gdao_get_gdaconnection +gdao_get_provider +gdao_new_from_string +gdao_rollback (Returns) + + +libgdaobj:Short_Description diff --git a/docs/reference/tmpl/libgdaobj.sgml b/docs/reference/tmpl/libgdaobj.sgml new file mode 100644 index 0000000..85c7342 --- /dev/null +++ b/docs/reference/tmpl/libgdaobj.sgml @@ -0,0 +1,272 @@ + +libgdaobj + + + + + + + + + + + + + + + + + + + + + + +@parent: + + + + + + +@gda_client: +@datasource: +@username: +@password: +@Returns: + + + + + + + +@gda_client: +@provider_id: +@cnc_string: +@Returns: + + + + + + + +@conn: +@Returns: + + + + + + + +@gdao: +@Returns: + + + + + + + +@gdao: +@Returns: + + + + + + + +@gdao: +@Returns: + + + + + + + +@gdao: +@sql: +@Returns: + + + + + + + +@data_model: +@row: +@field_name: +@Returns: + + + + + + + +@data_model: +@row: +@field_name: +@Returns: + + + + + + + +@data_model: +@row: +@field_name: +@Returns: + + + + + + + +@data_model: +@row: +@field_name: +@Returns: + + + + + + + +@data_model: +@row: +@field_name: +@Returns: + + + + + + + +@data_model: +@row: +@field_name: +@Returns: + + + + + + + +@data_model: +@row: +@col: +@Returns: + + + + + + + +@data_model: +@row: +@col: +@Returns: + + + + + + + +@data_model: +@row: +@col: +@Returns: + + + + + + + +@data_model: +@row: +@col: +@Returns: + + + + + + + +@data_model: +@row: +@col: +@Returns: + + + + + + + +@data_model: +@row: +@col: +@Returns: + + + + + + + +@gdao: +@Returns: + + + + + + + +@gdao: +@sql: +@Returns: + + + + + + + +@gdao: +@Returns: + + + + + + + +@gdao: +@Returns: + + + + + + + +@gdao: + + diff --git a/docs/reference/tmpl/libgdaoj-unused.sgml b/docs/reference/tmpl/libgdaoj-unused.sgml new file mode 100644 index 0000000..e69de29 diff --git a/docs/reference/version.xml.in b/docs/reference/version.xml.in new file mode 100644 index 0000000..a24f987 --- /dev/null +++ b/docs/reference/version.xml.in @@ -0,0 +1 @@ +@PACKAGE_VERSION@ diff --git a/libgdaobj.pc.in b/libgdaobj.pc.in new file mode 100644 index 0000000..b18ca85 --- /dev/null +++ b/libgdaobj.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: @PACKAGE_NAME@ +Description: A libgda's "subclass" +Version: @PACKAGE_VERSION@ +Requires: libgda +Libs: -L${libdir} -lgdaobj +Cflags: -I${includedir} diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..0e22032 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,12 @@ +AM_CPPFLAGS = -I$(top_srcdir) \ + $(GDAOBJ_CFLAGS) + +LIBS = $(GDAOBJ_LIBS) + +lib_LTLIBRARIES = libgdaobj.la + +libgdaobj_la_SOURCES = gdaobj.c + +libgdaobj_la_LDFLAGS = -no-undefined + +include_HEADERS = libgdaobj.h diff --git a/src/gdaobj.c b/src/gdaobj.c new file mode 100644 index 0000000..bb258f8 --- /dev/null +++ b/src/gdaobj.c @@ -0,0 +1,888 @@ +/* + * gdaobj.c + * + * Copyright (C) 2005-2006 Andrea Zagli + * + * This file is part of libgdaobj. + * + * libgdaobj is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * libgdaobj is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with libgdaobj; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H + #include +#endif + +#include + +#include "libgdaobj.h" + +static void gdao_class_init (GdaOClass *klass); +static void gdao_init (GdaO *gdao); + +static void gdao_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void gdao_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static void get_errors (GdaConnection *connection); + +#define GDAO_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_GDAO, GdaOPrivate)) + +typedef struct _GdaOPrivate GdaOPrivate; +struct _GdaOPrivate + { + GdaClient *gda_client; + GdaConnection *gda_conn; + GdaTransaction *gda_trans; + }; + +GType +gdao_get_type (void) +{ + static GType gdao_type = 0; + + if (!gdao_type) + { + static const GTypeInfo gdao_info = + { + sizeof (GdaOClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) gdao_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (GdaO), + 0, /* n_preallocs */ + (GInstanceInitFunc) gdao_init, + NULL + }; + + gdao_type = g_type_register_static (G_TYPE_OBJECT, "GdaO", + &gdao_info, 0); + } + + return gdao_type; +} + +static void +gdao_class_init (GdaOClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (GdaOPrivate)); + + object_class->set_property = gdao_set_property; + object_class->get_property = gdao_get_property; +} + +static void +gdao_init (GdaO *gdao) +{ + GdaOPrivate *priv = GDAO_GET_PRIVATE (gdao); + + priv->gda_trans = NULL; +} + +static GdaO +*gdao_new_ (GdaClient *gda_client) +{ + GdaO *gdao = GDAO (g_object_new (gdao_get_type (), NULL)); + + GdaOPrivate *priv = GDAO_GET_PRIVATE (gdao); + + if (gda_client == NULL) + { + /* create a new GdaClient */ + priv->gda_client = gda_client_new (); + if (priv->gda_client == NULL) + { + g_warning ("Unable to create a libgda's client."); + return NULL; + } + } + else + { + priv->gda_client = gda_client; + } + + return gdao; +} + +/** + * gdao_new: + * @gda_client: a #GdaClient object. If it's %NULL, it will be created a new one. + * @datasource: GDA data source name to connect to. + * @username: user name to use to connect. + * @password: password for @username. + * + * If @username and @password are both NULL or empty, it will be used those + * defined into datasource. + * + * Return value: the newly created #GdaO. + */ +GdaO +*gdao_new (GdaClient *gda_client, + const gchar *datasource, + const gchar *username, + const gchar *password) +{ + GdaO *gdao; + GdaOPrivate *priv; + + if (datasource == NULL || strcmp (g_strstrip (g_strdup (datasource)), "") == 0) + { + /* TO DO */ + g_warning ("datasource must not be empty."); + return NULL; + } + + gdao = gdao_new_ (gda_client); + if (gdao == NULL) + { + /* TO DO */ + return NULL; + } + + priv = GDAO_GET_PRIVATE (gdao); + + /* open database connection */ + priv->gda_conn = gda_client_open_connection (priv->gda_client, + datasource, + username, + password, + 0); + if (priv->gda_conn == NULL) + { + g_warning ("Unable to create the connection."); + return NULL; + } + + return gdao; +} + +/** + * gdao_new_from_string: + * @gda_client: a #GdaClient object. If it's %NULL, it will be created a new one. + * @provider_id: the provider id. + * @cnc_string: the connection string. + * + * Return value: the newly created #GdaO. + */ +GdaO +*gdao_new_from_string (GdaClient *gda_client, + const gchar *provider_id, + const gchar *cnc_string) +{ + GdaO *gdao; + GdaOPrivate *priv; + + if (provider_id == NULL || strcmp (g_strstrip (g_strdup (provider_id)), "") == 0) + { + /* TO DO */ + g_warning ("provider_id must not be empty."); + return NULL; + } + + if (cnc_string == NULL || strcmp (g_strstrip (g_strdup (cnc_string)), "") == 0) + { + /* TO DO */ + g_warning ("cnc_string must not be empty."); + return NULL; + } + + gdao = gdao_new_ (gda_client); + if (gdao == NULL) + { + /* TO DO */ + return NULL; + } + + priv = GDAO_GET_PRIVATE (gdao); + + /* open database connection */ + priv->gda_conn = gda_client_open_connection_from_string (priv->gda_client, + provider_id, + cnc_string, + 0); + if (priv->gda_conn == NULL) + { + g_warning ("Unable to create the connection.\n" + "provider_id: %s\tcnc_string: %s\n", + provider_id, cnc_string); + return NULL; + } + + return gdao; +} + +/** + * gdao_new_from_connection: + * @conn: a #GdaConnection. + * + * Returns a #GdaO from an existing #GdaConnection. + * + * Return value: the newly created #GdaO. + */ +GdaO +*gdao_new_from_connection (GdaConnection *conn) +{ + GdaO *gdao; + + if (conn == NULL) return NULL; + + gdao = gdao_new_ (gda_connection_get_client (conn)); + + return gdao; +} + +/** + * gdao_get_gdaclient: + * @gdao: a #GdaO object. + * + * Return value: the #GdaClient associated to the #GdaO. + */ +const GdaClient +*gdao_get_gdaclient (GdaO *gdao) +{ + if (gdao == NULL) + { + return NULL; + } + else + { + GdaOPrivate *priv = GDAO_GET_PRIVATE (gdao); + return priv->gda_client; + } +} + +/** + * gdao_get_gdaconnection: + * @gdao: a #GdaO object. + * + * Return value: the #GdaConnection associated to the #GdaO. + */ +const GdaConnection +*gdao_get_gdaconnection (GdaO *gdao) +{ + if (gdao == NULL) + { + return NULL; + } + else + { + GdaOPrivate *priv = GDAO_GET_PRIVATE (gdao); + return priv->gda_conn; + } +} + +/** + * gdao_get_provider: + * @gdao: a #GdaO object. + * + * Return value: the provider id associated to the #GdaO. + */ +const gchar +*gdao_get_provider (GdaO *gdao) +{ + GdaOPrivate *priv = GDAO_GET_PRIVATE (gdao); + return gda_connection_get_provider (priv->gda_conn); +} + +/** + * gdao_query: + * @gdao: a #GdaO object. + * @sql: the sql text. + * + * Execute a selection query (SELECT). + * + * Return value: a #GdaDataModel, or NULL if query fails. + */ +GdaDataModel +*gdao_query (GdaO *gdao, const gchar *sql) +{ + if (gdao == NULL) return NULL; + + GdaOPrivate *priv = GDAO_GET_PRIVATE (gdao); + + GdaCommand *gda_comm = gda_command_new (sql, GDA_COMMAND_TYPE_SQL, GDA_COMMAND_OPTION_STOP_ON_ERRORS); + GdaDataModel *dm = gda_connection_execute_single_command (priv->gda_conn, gda_comm, NULL); + + if (dm == NULL) + { + g_fprintf (stderr, "SQL: %s\n", sql); + get_errors (priv->gda_conn); + } + + gda_command_free (gda_comm); + + return dm; +} + +/* TO DO - define as macro */ +/* TO DO - catch error for gda_data_model_get_column_position */ +/** + * return the field_name's GdaValue as gchar (stringify) + */ +gchar +*gdao_data_model_get_field_value_stringify_at (GdaDataModel *data_model, + gint row, + const gchar *field_name) +{ + gchar *value = ""; + gint col; + + col = gda_data_model_get_column_position (data_model, field_name); + + if (col >= 0) + { + value = gdao_data_model_get_value_stringify_at (data_model, row, col); + } + + return value; +} + +/* TO DO - define as macro */ +/* TO DO - catch error for gda_data_model_get_column_position */ +/** + * return the field_name's GdaValue as gint + */ +gint +gdao_data_model_get_field_value_integer_at (GdaDataModel *data_model, + gint row, + const gchar *field_name) +{ + gint value = 0; + gint col; + + col = gda_data_model_get_column_position (data_model, field_name); + + if (col >= 0) + { + value = gdao_data_model_get_value_integer_at (data_model, row, col); + } + + return value; +} + +/* TO DO - define as macro */ +/* TO DO - catch error for gda_data_model_get_column_position */ +/** + * return the field_name's GdaValue as gfloat + */ +gfloat +gdao_data_model_get_field_value_float_at (GdaDataModel *data_model, + gint row, + const gchar *field_name) +{ + gfloat value = 0.0f; + gint col; + + col = gda_data_model_get_column_position (data_model, field_name); + + if (col >= 0) + { + value = gdao_data_model_get_value_float_at (data_model, row, col); + } + + return value; +} + +/* TO DO - define as macro */ +/* TO DO - catch error for gda_data_model_get_column_position */ +/** + * return the field_name's GdaValue as gdouble + */ +gdouble +gdao_data_model_get_field_value_double_at (GdaDataModel *data_model, + gint row, + const gchar *field_name) +{ + gdouble value = 0.0; + gint col; + + col = gda_data_model_get_column_position (data_model, field_name); + + if (col >= 0) + { + value = gdao_data_model_get_value_double_at (data_model, row, col); + } + + return value; +} + +/* TO DO - define as macro */ +/* TO DO - catch error for gda_data_model_get_column_position */ +/** + * return the field_name's GdaValue as gboolean + */ +gboolean +gdao_data_model_get_field_value_boolean_at (GdaDataModel *data_model, + gint row, + const gchar *field_name) +{ + gboolean value = FALSE; + gint col; + + col = gda_data_model_get_column_position (data_model, field_name); + + if (col >= 0) + { + value = gdao_data_model_get_value_boolean_at (data_model, row, col); + } + + return value; +} + +/* TO DO - define as macro */ +/* TO DO - catch error for gda_data_model_get_column_position */ +/** + * return the field_name's GdaValue as GDate + */ +GDate +*gdao_data_model_get_field_value_gdate_at (GdaDataModel *data_model, + gint row, + const gchar *field_name) +{ + GDate *value = NULL; + gint col; + + col = gda_data_model_get_column_position (data_model, field_name); + + if (col >= 0) + { + value = gdao_data_model_get_value_gdate_at (data_model, row, col); + } + + return value; +} + +/** + * gdao_data_model_get_value_stringify_at: + * @data_model: a #GdaDataModel object. + * @row: row number. + * @col: col number. + * + * Return value: the #GdaValue as #gchar (stringify). + */ +gchar +*gdao_data_model_get_value_stringify_at (GdaDataModel *data_model, gint row, gint col) +{ + gchar *ret = ""; + + GdaValue *v = (GdaValue *)gda_data_model_get_value_at (data_model, col, row); + if (!gda_value_is_null (v)) + { + ret = g_strdup (gda_value_stringify (v)); + } + + return ret; +} + +/** + * gdao_data_model_get_value_integer_at: + * @data_model: a #GdaDataModel object. + * @row: row number. + * @col: col number. + * + * Return value: the #GdaValue as #gint. + */ +gint +gdao_data_model_get_value_integer_at (GdaDataModel *data_model, gint row, gint col) +{ + gint ret = 0; + + GdaValue *v = (GdaValue *)gda_data_model_get_value_at (data_model, col, row); + if (v == NULL) + { + /* TO DO */ + /* trap errors */ + } + else if (!gda_value_is_null (v)) + { + if (gda_value_isa (v, GDA_VALUE_TYPE_INTEGER)) + { + ret = gda_value_get_integer (v); + } + else + { + ret = atol (gda_value_stringify (v)); + } + } + + return ret; +} + +/** + * gdao_data_model_get_value_float_at: + * @data_model: a #GdaDataModel object. + * @row: row number. + * @col: col number. + * + * Return value: the #GdaValue as #gfloat. + */ +gfloat +gdao_data_model_get_value_float_at (GdaDataModel *data_model, gint row, gint col) +{ + gfloat ret = 0.0f; + + GdaValue *v = (GdaValue *)gda_data_model_get_value_at (data_model, col, row); + if (!gda_value_is_null (v)) + { + ret = gda_value_get_single (v); + } + + return ret; +} + +/** + * gdao_data_model_get_value_double_at: + * @data_model: a #GdaDataModel object. + * @row: row number. + * @col: col number. + * + * Return value: the #GdaValue as #gdouble. + */ +gdouble +gdao_data_model_get_value_double_at (GdaDataModel *data_model, gint row, gint col) +{ + gdouble ret = 0.0; + + GdaValue *v = (GdaValue *)gda_data_model_get_value_at (data_model, col, row); + if (!gda_value_is_null (v)) + { + ret = gda_value_get_double (v); + } + + return ret; +} + +/** + * gdao_data_model_get_value_boolean_at: + * @data_model: a #GdaDataModel object. + * @row: row number. + * @col: col number. + * + * Return value: the #GdaValue as #gboolean. + */ +gboolean +gdao_data_model_get_value_boolean_at (GdaDataModel *data_model, gint row, gint col) +{ + gboolean ret = FALSE; + + GdaValue *v = (GdaValue *)gda_data_model_get_value_at (data_model, col, row); + if (v == NULL) + { + /* TO DO */ + /* trap errors */ + } + else if (!gda_value_is_null (v)) + { + if (gda_value_isa (v, GDA_VALUE_TYPE_BOOLEAN)) + { + ret = gda_value_get_boolean (v); + } + else + { + gchar *vstr = g_strstrip (gda_value_stringify (v)); + if (strcasecmp (vstr, "true") == 0 || + strcasecmp (vstr, "t") == 0 || + strcasecmp (vstr, "yes") == 0 || + strcasecmp (vstr, "y") == 0 || + atol (vstr) != 0) + { + ret = TRUE; + } + } + } + + return ret; +} + +/** + * gdao_data_model_get_value_gdate_at: + * @data_model: a #GdaDataModel object. + * @row: row number. + * @col: col number. + * + * Return value: the #GdaValue as #GDate. + */ +GDate +*gdao_data_model_get_value_gdate_at (GdaDataModel *data_model, gint row, gint col) +{ + GDate *ret = NULL; + const GdaDate *gdadate; + + GdaValue *v = (GdaValue *)gda_data_model_get_value_at (data_model, col, row); + if (!gda_value_is_null (v)) + { + gdadate = gda_value_get_date (v); + if (g_date_valid_dmy ((GDateDay)gdadate->day, (GDateMonth)gdadate->month, (GDateYear)gdadate->year)) + { + ret = g_date_new_dmy ((GDateDay)gdadate->day, (GDateMonth)gdadate->month, (GDateYear)gdadate->year); + } + } + + return ret; +} + +/** + * gdao_begin: + * @gdao: a #GdaO object. + * + * Begin a new transaction. + */ +gboolean +gdao_begin (GdaO *gdao) +{ + if (gdao == NULL) return FALSE; + + GdaOPrivate *priv = GDAO_GET_PRIVATE (gdao); + + priv->gda_trans = gda_transaction_new ("gdao"); + gda_transaction_set_isolation_level (priv->gda_trans, + GDA_TRANSACTION_ISOLATION_SERIALIZABLE); + + return gda_connection_begin_transaction (priv->gda_conn, priv->gda_trans); +} + +/** + * gdao_execute: + * @gdao: a #GdaO object. + * @sql: the sql text. + * + * Execute a command query (INSERT, UPDATE, DELETE). + * + * Return value: number of records affected by the query execution. + */ +gint +gdao_execute (GdaO *gdao, const gchar *sql) +{ + GdaCommand *gda_comm; + gint nrecs; + + if (gdao == NULL) return -1; + + GdaOPrivate *priv = GDAO_GET_PRIVATE (gdao); + + gda_comm = gda_command_new (sql, GDA_COMMAND_TYPE_SQL, GDA_COMMAND_OPTION_STOP_ON_ERRORS); + if (priv->gda_trans != NULL) + { + gda_command_set_transaction (gda_comm, priv->gda_trans); + } + nrecs = gda_connection_execute_non_query (priv->gda_conn, gda_comm, NULL); + + if (nrecs == -1) + { + g_fprintf (stderr, "SQL: %s\n", sql); + get_errors (priv->gda_conn); + } + + gda_command_free (gda_comm); + + return nrecs; +} + +/** + * gdao_commit: + * @gdao: a #GdaO object. + * + * Commit a transaction. + */ +gboolean +gdao_commit (GdaO *gdao) +{ + gboolean ret; + + if (gdao == NULL) return FALSE; + + GdaOPrivate *priv = GDAO_GET_PRIVATE (gdao); + + if (priv->gda_trans == NULL) + { + ret = FALSE; + } + else + { + ret = gda_connection_commit_transaction (priv->gda_conn, priv->gda_trans); + g_object_unref (priv->gda_trans); + priv->gda_trans = NULL; + } + + return ret; +} + +/** + * gdao_rollback: + * @gdao: a #GdaO object. + * + * Rollback a transaction. + */ +gboolean +gdao_rollback (GdaO *gdao) +{ + gboolean ret; + + if (gdao == NULL) return FALSE; + + GdaOPrivate *priv = GDAO_GET_PRIVATE (gdao); + + if (priv->gda_trans == NULL) + { + ret = FALSE; + } + else + { + ret = gda_connection_rollback_transaction (priv->gda_conn, priv->gda_trans); + g_object_unref (priv->gda_trans); + priv->gda_trans = NULL; + } + + return ret; +} + +/* TO DO */ +void +gdao_free (GdaO *gdao) +{ + if (gdao == NULL) return; + + GdaOPrivate *priv = GDAO_GET_PRIVATE (gdao); + + /* close connection */ + if (gda_connection_is_open (priv->gda_conn)) + { + gda_connection_close (priv->gda_conn); + } + + /*g_free (gdao);*/ +} + +/* UTILITY'S FUNCTIONS */ +/** + * gdao_strescape: + * @source: a string to escape. + * @exceptions: a string of characters not to escape in @source. + * + * As g_strescape(), but it escapes also '. + */ +gchar +*gdao_strescape (const gchar *source, const gchar *exceptions) +{ + gchar *ret = "", *nsource; + gint l = strlen (source); + + if (source == NULL || l == 0) return ""; + + nsource = g_strescape (g_strstrip (g_strdup (source)), exceptions); + + /* escape di ' */ + if (strchr (nsource, '\'') != NULL) + { + while (*nsource) + { + if (*nsource == '\'') + { + ret = g_strconcat (ret, "'", g_strdup_printf ("%c", *nsource), NULL); + } + else + { + ret = g_strconcat (ret, g_strdup_printf ("%c", *nsource), NULL); + } + + *nsource++; + } + + return g_strdup (ret); + } + else + { + return g_strdup (nsource); + } +} + +/** + * gdao_get_chr_quoting: + * @gdao: a #GdaO object. + * + */ +gchar +gdao_get_chr_quoting (GdaO *gdao) +{ + gchar chr = '\"'; + + const gchar *provider = gdao_get_provider (gdao); + + if (strcmp (provider, "MySQL") == 0) + { + chr = '`'; + } + + return chr; +} + +/* PRIVATE */ +static void +get_errors (GdaConnection *connection) +{ + GList *list; + GList *node; + GdaError *error; + + list = (GList *) gda_connection_get_errors (connection); + + for (node = g_list_first (list); node != NULL; node = g_list_next (node)) + { + error = (GdaError *) node->data; + g_fprintf (stderr, "Error no: %d\t", gda_error_get_number (error)); + g_fprintf (stderr, "desc: %s\t", gda_error_get_description (error)); + g_fprintf (stderr, "source: %s\t", gda_error_get_source (error)); + g_fprintf (stderr, "sqlstate: %s\n", gda_error_get_sqlstate (error)); + } +} + +static void +gdao_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) +{ + GdaO *gdao = GDAO (object); + + GdaOPrivate *priv = GDAO_GET_PRIVATE (gdao); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +gdao_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) +{ + GdaO *gdao = GDAO (object); + + GdaOPrivate *priv = GDAO_GET_PRIVATE (gdao); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} diff --git a/src/libgdaobj.h b/src/libgdaobj.h new file mode 100644 index 0000000..0ca57bd --- /dev/null +++ b/src/libgdaobj.h @@ -0,0 +1,127 @@ +/* + * libgdaobj.h + * + * Copyright (C) 2005-2006 Andrea Zagli + * + * This file is part of libgdaobj. + * + * libgdaobj is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * libgdaobj is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with libgdaobj; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include +#include +#include + +#ifndef __GDAO_H__ +#define __GDAO_H__ + +G_BEGIN_DECLS + + +#define TYPE_GDAO (gdao_get_type ()) +#define GDAO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GDAO, GdaO)) +#define GDAO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GDAO, GdaOClass)) +#define IS_GDAO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GDAO)) +#define IS_GDAO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GDAO)) +#define GDAO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_GDAO, GdaOClass)) + + +typedef struct _GdaO GdaO; +typedef struct _GdaOClass GdaOClass; + +struct _GdaO + { + GObject parent; + }; + +struct _GdaOClass + { + GObjectClass parent_class; + }; + +GType gdao_get_type (void) G_GNUC_CONST; + + +GdaO *gdao_new (GdaClient *gda_client, + const gchar *datasource, + const gchar *username, + const gchar *password); +GdaO *gdao_new_from_string (GdaClient *gda_client, + const gchar *provider_id, + const gchar *cnc_string); +GdaO *gdao_new_from_connection (GdaConnection *conn); + +const GdaClient *gdao_get_gdaclient (GdaO *gdao); +const GdaConnection *gdao_get_gdaconnection (GdaO *gdao); +const gchar *gdao_get_provider (GdaO *gdao); + +GdaDataModel *gdao_query (GdaO *gdao, const gchar *sql); + +gchar *gdao_data_model_get_field_value_stringify_at (GdaDataModel *data_model, + gint row, + const gchar *field_name); +gint gdao_data_model_get_field_value_integer_at (GdaDataModel *data_model, + gint row, + const gchar *field_name); +gfloat gdao_data_model_get_field_value_float_at (GdaDataModel *data_model, + gint row, + const gchar *field_name); +gdouble gdao_data_model_get_field_value_double_at (GdaDataModel *data_model, + gint row, + const gchar *field_name); +gboolean gdao_data_model_get_field_value_boolean_at (GdaDataModel *data_model, + gint row, + const gchar *field_name); +GDate *gdao_data_model_get_field_value_gdate_at (GdaDataModel *data_model, + gint row, + const gchar *field_name); + +gchar *gdao_data_model_get_value_stringify_at (GdaDataModel *data_model, + gint row, + gint col); +gint gdao_data_model_get_value_integer_at (GdaDataModel *data_model, + gint row, + gint col); +gfloat gdao_data_model_get_value_float_at (GdaDataModel *data_model, + gint row, + gint col); +gdouble gdao_data_model_get_value_double_at (GdaDataModel *data_model, + gint row, + gint col); +gboolean gdao_data_model_get_value_boolean_at (GdaDataModel *data_model, + gint row, + gint col); +GDate *gdao_data_model_get_value_gdate_at (GdaDataModel *data_model, + gint row, + gint col); + +gboolean gdao_begin (GdaO *gdao); + +gint gdao_execute (GdaO *gdao, const gchar *sql); + +gboolean gdao_commit (GdaO *gdao); +gboolean gdao_rollback (GdaO *gdao); + +void gdao_free (GdaO *gdao); + +gchar *gdao_strescape (const gchar *source, const gchar *exceptions); + +gchar gdao_get_chr_quoting (GdaO *gdao); + + +G_END_DECLS + +#endif /* __GDAO_H__ */