[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/geas/src/objectstore compare.c compare.h m...
From: |
Reinhard Mueller |
Subject: |
gnue/geas/src/objectstore compare.c compare.h m... |
Date: |
Sat, 15 Dec 2001 05:43:33 -0500 |
CVSROOT: /cvsroot/gnue
Module name: gnue
Changes by: Reinhard Mueller <address@hidden> 01/12/15 05:43:33
Modified files:
geas/src/objectstore: compare.c compare.h mysql.c objectstore.c
postgresql.c
Log message:
Changed the code to create the database tables to use the new parser.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/geas/src/objectstore/compare.c.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/geas/src/objectstore/compare.h.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/geas/src/objectstore/mysql.c.diff?tr1=1.8&tr2=1.9&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/geas/src/objectstore/objectstore.c.diff?tr1=1.68&tr2=1.69&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/geas/src/objectstore/postgresql.c.diff?tr1=1.13&tr2=1.14&r1=text&r2=text
Patches:
Index: gnue/geas/src/objectstore/compare.c
diff -c gnue/geas/src/objectstore/compare.c:1.4
gnue/geas/src/objectstore/compare.c:1.5
*** gnue/geas/src/objectstore/compare.c:1.4 Tue Sep 4 10:49:37 2001
--- gnue/geas/src/objectstore/compare.c Sat Dec 15 05:43:33 2001
***************
*** 19,25 ****
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
! $Id: compare.c,v 1.4 2001/09/04 14:49:37 reinhard Exp $
*/
#include "config.h"
--- 19,25 ----
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
! $Id: compare.c,v 1.5 2001/12/15 10:43:33 reinhard Exp $
*/
#include "config.h"
***************
*** 27,37 ****
#include <stdio.h>
#include <string.h>
#include <glib.h>
! #include "classdata.h"
#include "oql/oql.h"
- static DBchange *find_named_change (GList *l, char *name);
-
/* -------------------------------------------------------------------------
*\
*
\* -------------------------------------------------------------------------
*/
--- 27,35 ----
#include <stdio.h>
#include <string.h>
#include <glib.h>
! #include "classdef/classdef.h"
#include "oql/oql.h"
/* -------------------------------------------------------------------------
*\
*
\* -------------------------------------------------------------------------
*/
***************
*** 64,70 ****
{
c = (DatabaseColumn *) cl->data;
fprintf (fp, " Column %s\t%s [%d]\n", c->name,
! odl_datatype_name (c->datatype), c->datatype);
cl = g_list_next (cl);
}
fprintf (fp, "\n"); /* space between tables */
--- 62,68 ----
{
c = (DatabaseColumn *) cl->data;
fprintf (fp, " Column %s\t%s [%d]\n", c->name,
! geas_cd_datatype_name (c->datatype), c->datatype);
cl = g_list_next (cl);
}
fprintf (fp, "\n"); /* space between tables */
***************
*** 282,289 ****
*
\* -------------------------------------------------------------------------
*/
DatabaseColumn *
! add_database_column (DatabaseTable * table, const char *name,
! enum odl_datatype type)
{
DatabaseColumn *c = g_new0 (DatabaseColumn, 1);
g_assert (table != NULL);
--- 280,287 ----
*
\* -------------------------------------------------------------------------
*/
DatabaseColumn *
! add_database_column (DatabaseTable *table, const char *name,
! geas_cd_datatype type)
{
DatabaseColumn *c = g_new0 (DatabaseColumn, 1);
g_assert (table != NULL);
***************
*** 353,397 ****
}
c->name = g_strdup (p);
c->datatype = DT_unknown;
! c->format = NULL;
c->columns = NULL;
! c->notnull = FALSE;
dbchange->adds = g_list_append (dbchange->adds, c);
return (c);
}
/* -------------------------------------------------------------------------
*\
- *
- \* -------------------------------------------------------------------------
*/
- DBchange *
- dbchange_remove_table (DatabaseChange * dbchange, const char *name)
- {
- DBchange *c = g_new0 (DBchange, 1);
- g_assert (c != NULL);
- g_assert (dbchange != NULL);
- g_assert (name != NULL);
-
- if (!c)
- {
- return (NULL);
- }
- c->type = DBCH_REMOVE_TABLE;
- c->name = g_strdup (name);
- c->datatype = DT_unknown;
- c->format = NULL;
- c->columns = NULL;
- c->notnull = FALSE;
- dbchange->removes = g_list_append (dbchange->removes, c);
- return (c);
- }
-
- /* -------------------------------------------------------------------------
*\
* add or remove a column to/from a table
\* -------------------------------------------------------------------------
*/
DBchange *
dbchange_add_column (DBchange * change, const char *name,
! enum odl_datatype datatype, const char *format,
! gboolean notnull)
{
DBchange *c = g_new0 (DBchange, 1);
g_assert (c != NULL);
--- 351,369 ----
}
c->name = g_strdup (p);
c->datatype = DT_unknown;
! c->format = 0;
c->columns = NULL;
! c->notnull = 0;
dbchange->adds = g_list_append (dbchange->adds, c);
return (c);
}
/* -------------------------------------------------------------------------
*\
* add or remove a column to/from a table
\* -------------------------------------------------------------------------
*/
DBchange *
dbchange_add_column (DBchange * change, const char *name,
! geas_cd_datatype datatype, int format, int notnull)
{
DBchange *c = g_new0 (DBchange, 1);
g_assert (c != NULL);
***************
*** 405,420 ****
c->type = DBCH_ADD_COLUMN;
c->name = g_strdup (name);
c->datatype = datatype;
! if (format)
! {
! c->format = g_strdup (format);
! }
! else
! {
! c->format = NULL;
! }
c->columns = NULL;
! c->notnull = FALSE /* notnull */; /* FIXME !!! */
change->columns = g_list_append (change->columns, c);
return (c);
}
--- 377,385 ----
c->type = DBCH_ADD_COLUMN;
c->name = g_strdup (name);
c->datatype = datatype;
! c->format = format;
c->columns = NULL;
! c->notnull = 0 /* notnull */; /* FIXME !!! */
change->columns = g_list_append (change->columns, c);
return (c);
}
***************
*** 428,621 ****
return NULL;
}
-
- /* -------------------------------------------------------------------------
*\
- *
- \* -------------------------------------------------------------------------
*/
- DBchange *
- find_named_change (GList * l, char *name)
- {
- g_assert (name != NULL);
- while (l) /* if l == NULL, then return 'not in list' value */
- {
- if (g_strcasecmp (((DBchange *) l->data)->name, name) == 0)
- {
- return (l->data);
- }
- l = g_list_next (l);
- }
- return (NULL);
- }
-
- /* -------------------------------------------------------------------------
*\
- * scan a database definition and compare to the current class definitions
- * if there's a difference, produce a DatabaseChange object, which can be
- * used to make
- \* -------------------------------------------------------------------------
*/
- static gboolean
- is_class_required (GList * list, const char *name)
- {
- char *tmp;
- g_assert (list != NULL);
- g_assert (name != NULL);
- while (list)
- {
- if (!list || !list->data)
- {
- tmp = "??";
- }
- else
- {
- tmp = odl_mangle_qualified_name (list->data);
- }
- if (g_strcasecmp (name, tmp) == 0)
- {
- g_free (tmp);
- return (TRUE);
- }
- g_free (tmp);
- list = g_list_next (list);
- }
- return (FALSE);
- }
-
/* -------------------------------------------------------------------------
*\
* Make a complete list of needed changes in the database schema
\* -------------------------------------------------------------------------
*/
DatabaseChange *
! compare_classes_to_database (odl_tree * tree, GList * requiredclasses,
! DatabaseDefinition * database, DBType db)
{
! GList *l, *fl;
! DatabaseChange *c = create_database_change ();
! DatabaseTable *t;
! DBchange *ch;
! odl_class *cl;
! g_assert (tree != NULL);
! g_assert (requiredclasses != NULL);
! g_assert (database != NULL);
! g_assert (c != NULL);
! /* for each table found, if there isn't a matching required class, remove
! the table */
! if (!database)
! {
! return (NULL);
! }
! l = database->tables;
! while (l)
{
! if (is_class_required
! (requiredclasses, ((DatabaseTable *) l->data)->name) == FALSE)
{
! /* class matching this table isn't required */
! dbchange_remove_table (c, ((DatabaseTable *) l->data)->name);
}
! l = g_list_next (l);
! }
!
! /* for each class, if there isn't a matching table, add the table */
! l = requiredclasses;
! while (l)
! {
! char *tmp;
!
! tmp = oql_quote_column ((const char *) l->data, NULL, db);
! t = find_database_table (database, tmp, db);
!
! if (!t)
{
! GList *x;
! ch = dbchange_add_table (c, tmp);
!
! /* adding full table, so note the basic fields required */
! cl = odl_find_class (tree, (const char *) l->data, NULL);
! fl = odl_class_get_fields (cl, FT_basic); /* no inherited
fields */
!
! x = fl;
! while (x)
{
! odl_field *f = x->data;
! dbchange_add_column (ch,
! odl_field_get_name (f),
! odl_field_get_datatype (f),
! odl_field_get_format (f),
! odl_field_has_property (f,
! ODL_PROP_NOTNULL));
! x = g_list_next (x);
}
! odl_fieldlist_free (fl);
! }
!
! g_free (tmp);
! l = g_list_next (l);
! }
!
! /* for each column in an existing table: if the matching class doesn't
! have that field, remove it */
! l = database->tables;
! while (l)
! {
! /* find any fields in the table that don't match a column in the
! class (remove them) */
! /* TODO */
! l = g_list_next (l);
! }
!
! l = requiredclasses;
! while (l)
! {
! char *tmp;
!
! tmp = oql_quote_column ((const char *) l->data, NULL, db);
! t = find_database_table (database, tmp, db);
! g_free (tmp);
! tmp = NULL;
! cl = odl_find_class (tree, (const char *) l->data, NULL);
! if (t && cl)
! {
! GList *l2;
! /* find any fields in the class not matching columns in the
! table (add them) */
!
! fl = odl_class_get_fields (cl, FT_basic); /* no inherited
fields */
! l2 = fl;
! while (l2)
{
! odl_field *f = (odl_field *) l2->data;
! char *quoted = oql_quote_column (NULL, odl_field_get_name (f),
! db);
! if (!find_databasetable_field (t, quoted, db))
{
! ch = find_named_change (c->adds, t->name);
! if (!ch)
! {
! char *tmp;
! /* first change related to this table,
! so make the "add table" item */
! tmp = odl_mangle_qualified_name (l->data);
! ch = dbchange_add_table (c, tmp);
! g_free (tmp);
! ch->type = DBCH_MODIFY_TABLE;
! }
! if (ch)
! {
! dbchange_add_column (ch,
! odl_field_get_name (f),
! odl_field_get_datatype (f),
! odl_field_get_format (f),
! odl_field_has_property (f,
!
ODL_PROP_NOTNULL));
!
! }
}
! g_free (quoted);
! l2 = g_list_next (l2);
}
-
- odl_fieldlist_free (fl);
}
! l = g_list_next (l);
}
! return (c);
}
--- 393,460 ----
return NULL;
}
/* -------------------------------------------------------------------------
*\
* Make a complete list of needed changes in the database schema
\* -------------------------------------------------------------------------
*/
DatabaseChange *
! compare_classes_to_database (DatabaseDefinition * database, DBType db)
{
! DatabaseChange *result;
! DatabaseTable *table;
! DBchange *change;
! geas_cd_classlist *cl;
! geas_cd_class *c;
! geas_cd_fieldlist *fl;
! geas_cd_field *f;
! g_return_val_if_fail (database, NULL);
!
! result = create_database_change ();
!
! cl = geas_cd_classlist_new ();
! while ((c = geas_cd_classlist_next (cl)))
{
! change = NULL;
! table = find_database_table (database, geas_cd_class_get_name_db (c),
db);
! if (!table)
{
! change = dbchange_add_table (result, geas_cd_class_get_name_db (c));
}
! fl = geas_cd_class_fieldlist_new (c);
! while ((f = geas_cd_fieldlist_next (fl)))
{
! switch (geas_cd_field_get_datatype (f))
{
! case GEAS_CD_DATATYPE_REFERENCE:
! case GEAS_CD_DATATYPE_LIST:
! case GEAS_CD_DATATYPE_COMPOUND:
! /* skip fields that have no pendant in the db */
! continue;
! default:
! /* continue processing */
}
! if ((!table)
! || (!find_databasetable_field (table,
! geas_cd_field_get_name_db (f),
! db)))
{
! if (!change)
{
! change = dbchange_add_table (result,
! geas_cd_class_get_name_db (c));
! change->type = DBCH_MODIFY_TABLE;
}
! dbchange_add_column (change,
! geas_cd_field_get_name_db (f),
! geas_cd_field_get_datatype (f),
! geas_cd_field_get_format (f),
! geas_cd_field_prop_get (f,
!
GEAS_CD_FPROP_NOTNULL));
}
}
! geas_cd_fieldlist_free (fl);
}
! geas_cd_classlist_free (cl);
!
! return (result);
}
Index: gnue/geas/src/objectstore/compare.h
diff -c gnue/geas/src/objectstore/compare.h:1.2
gnue/geas/src/objectstore/compare.h:1.3
*** gnue/geas/src/objectstore/compare.h:1.2 Wed Jul 25 08:51:08 2001
--- gnue/geas/src/objectstore/compare.h Sat Dec 15 05:43:33 2001
***************
*** 19,25 ****
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
! $Id: compare.h,v 1.2 2001/07/25 12:51:08 reinhard Exp $
*/
/** \file classdata_database.h
--- 19,25 ----
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
! $Id: compare.h,v 1.3 2001/12/15 10:43:33 reinhard Exp $
*/
/** \file classdata_database.h
***************
*** 29,35 ****
*/
#include <glib.h>
! #include "classdata.h"
#include "oql/oql.h"
#ifndef CLASSDATA_DATABASE_H
--- 29,35 ----
*/
#include <glib.h>
! #include "classdef/classdef.h"
#include "oql/oql.h"
#ifndef CLASSDATA_DATABASE_H
***************
*** 49,57 ****
{
int type;
char *name;
! enum odl_datatype datatype;
! char *format;
! gboolean notnull;
GList *columns;
}
DBchange;
--- 49,57 ----
{
int type;
char *name;
! geas_cd_datatype datatype;
! int format;
! int notnull;
GList *columns;
}
DBchange;
***************
*** 66,72 ****
typedef struct
{
char *name;
! enum odl_datatype datatype; /** \brief GEAS datatype to store in
this column */
}
DatabaseColumn;
--- 66,72 ----
typedef struct
{
char *name;
! geas_cd_datatype datatype;
}
DatabaseColumn;
***************
*** 96,103 ****
int which);
DatabaseColumn *add_database_column (DatabaseTable * table,
const char *name,
! enum odl_fieldtype type);
!
DatabaseChange *create_database_change (void);
void free_database_change (DatabaseChange * change);
--- 96,102 ----
int which);
DatabaseColumn *add_database_column (DatabaseTable * table,
const char *name,
! geas_cd_datatype type);
DatabaseChange *create_database_change (void);
void free_database_change (DatabaseChange * change);
***************
*** 111,119 ****
/** \brief add a column to/from a table. */
DBchange *dbchange_add_column (DBchange * change,
const char *name,
! enum odl_fieldtype fieldtype,
! const char *format,
! gboolean notnull);
/** \brief Remove a column to/from a table. */
DBchange *dbchange_remove_column (DBchange * change,
const char *name);
--- 110,117 ----
/** \brief add a column to/from a table. */
DBchange *dbchange_add_column (DBchange * change,
const char *name,
! geas_cd_datatype datatype,
! int format, int notnull);
/** \brief Remove a column to/from a table. */
DBchange *dbchange_remove_column (DBchange * change,
const char *name);
***************
*** 121,129 ****
/** \brief Scan a database definition and compare to the current class
definitions. */
/* if there's a difference, produce a DatabaseChange object, which can be
used to make */
/* database specific commands to update the database definitions */
! DatabaseChange *compare_classes_to_database (odl_tree * tree,
! GList * requiredclasses,
! DatabaseDefinition *
database, DBType db);
#endif
--- 119,125 ----
/** \brief Scan a database definition and compare to the current class
definitions. */
/* if there's a difference, produce a DatabaseChange object, which can be
used to make */
/* database specific commands to update the database definitions */
! DatabaseChange *compare_classes_to_database (DatabaseDefinition *
database, DBType db);
#endif
Index: gnue/geas/src/objectstore/mysql.c
diff -c gnue/geas/src/objectstore/mysql.c:1.8
gnue/geas/src/objectstore/mysql.c:1.9
*** gnue/geas/src/objectstore/mysql.c:1.8 Sun Sep 2 02:49:16 2001
--- gnue/geas/src/objectstore/mysql.c Sat Dec 15 05:43:33 2001
***************
*** 20,26 ****
along with GEAS; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
! $Id: mysql.c,v 1.8 2001/09/02 06:49:16 reinhard Exp $
*/
#include "config.h"
--- 20,26 ----
along with GEAS; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
! $Id: mysql.c,v 1.9 2001/12/15 10:43:33 reinhard Exp $
*/
#include "config.h"
***************
*** 479,486 ****
for (i = 0; i < count_database_tables (db); i++)
{
DatabaseTable *tab = get_database_table (db, i);
! /* DatabaseColumn *c; */
! enum odl_fieldtype type;
int err;
/* get list of fields and types */
--- 479,485 ----
for (i = 0; i < count_database_tables (db); i++)
{
DatabaseTable *tab = get_database_table (db, i);
! geas_cd_datatype type;
int err;
/* get list of fields and types */
***************
*** 526,556 ****
/* ie: accuracy is not critical */
/* except when display will be too confusing */
if (g_strcasecmp (row[1], "varchar") == 0)
! type = DT_char;
! else if (g_strcasecmp (row[1], "smallint") == 0)
! type = DT_int16;
! else if (g_strcasecmp (row[1], "int") == 0)
! type = DT_int32;
! else if (g_strcasecmp (row[1], "bigint") == 0)
! type = DT_int64;
else if (g_strcasecmp (row[1], "tinytext") == 0)
! type = DT_text;
else if (g_strcasecmp (row[1], "text") == 0)
! type = DT_text;
else if (g_strcasecmp (row[1], "mediumtext") == 0)
! type = DT_text;
else if (g_strcasecmp (row[1], "longtext") == 0)
! type = DT_text;
else if (g_strcasecmp (row[1], "date") == 0)
! type = DT_date;
else if (g_strcasecmp (row[1], "time") == 0)
! type = DT_time;
else if (g_strcasecmp (row[1], "datetime") == 0)
! type = DT_datetime;
! else if (g_strcasecmp (row[1], "double") == 0)
! type = DT_float;
else
! type = DT_unknown;
name = row[0];
if (name[0] == '_' && name[1] == '_')
--- 525,555 ----
/* ie: accuracy is not critical */
/* except when display will be too confusing */
if (g_strcasecmp (row[1], "varchar") == 0)
! type = GEAS_CD_DATATYPE_CHAR;
else if (g_strcasecmp (row[1], "tinytext") == 0)
! type = GEAS_CD_DATATYPE_TEXT;
else if (g_strcasecmp (row[1], "text") == 0)
! type = GEAS_CD_DATATYPE_TEXT;
else if (g_strcasecmp (row[1], "mediumtext") == 0)
! type = GEAS_CD_DATATYPE_TEXT;
else if (g_strcasecmp (row[1], "longtext") == 0)
! type = GEAS_CD_DATATYPE_TEXT;
! else if (g_strcasecmp (row[1], "smallint") == 0)
! type = GEAS_CD_DATATYPE_INT16;
! else if (g_strcasecmp (row[1], "int") == 0)
! type = GEAS_CD_DATATYPE_INT32;
! else if (g_strcasecmp (row[1], "bigint") == 0)
! type = GEAS_CD_DATATYPE_INT64;
! else if (g_strcasecmp (row[1], "double") == 0)
! type = GEAS_CD_DATATYPE_FLOAT;
else if (g_strcasecmp (row[1], "date") == 0)
! type = GEAS_CD_DATATYPE_DATE;
else if (g_strcasecmp (row[1], "time") == 0)
! type = GEAS_CD_DATATYPE_TIME;
else if (g_strcasecmp (row[1], "datetime") == 0)
! type = GEAS_CD_DATATYPE_DATETIME;
else
! type = GEAS_CD_DATATYPE_UNKNOWN;
name = row[0];
if (name[0] == '_' && name[1] == '_')
***************
*** 570,576 ****
{
char *name;
DBchange *c;
- int len;
while (l)
{
--- 569,574 ----
***************
*** 579,650 ****
g_string_append (buf, name);
g_free (name);
g_string_append (buf, " ");
switch (c->datatype)
{
! case DT_char:
g_string_sprintfa (buf, "VARCHAR");
if (c->format)
! g_string_sprintfa (buf, "(%s)", c->format);
else
g_string_sprintfa (buf, "(1)");
break;
! case DT_int16:
g_string_sprintfa (buf, "SMALLINT");
break;
! case DT_int32:
! case DT_int:
g_string_sprintfa (buf, "INT");
break;
! case DT_int64:
g_string_sprintfa (buf, "BIGINT");
break;
! case DT_boolean:
! case DT_bool:
! g_string_sprintfa (buf, "CHAR(1)");
break;
! case DT_text:
! if (!c->format)
! g_string_sprintfa (buf, "TEXT"); /* <= 64k characters */
! else
! {
! len = atoi (c->format);
! if (len < 256)
! g_string_sprintfa (buf, "TINYTEXT");
! else if (len < 65536)
! g_string_sprintfa (buf, "TEXT");
! else if (len < 16777216)
! g_string_sprintfa (buf, "MEDIUMTEXT");
! else
! g_string_sprintfa (buf, "LONGTEXT");
! }
break;
! case DT_date:
g_string_sprintfa (buf, "DATE");
break;
! case DT_time:
g_string_sprintfa (buf, "TIME");
break;
! case DT_datetime:
g_string_sprintfa (buf, "DATETIME");
break;
- case DT_float:
- g_string_sprintfa (buf, "DOUBLE");
- break;
- case DT_unsignedint:
- g_string_sprintfa (buf, "INT UNSIGNED");
- break;
- case DT_object:
- g_string_sprintfa (buf, "CHAR(32)");
- break;
default:
! /* g_critical ("unknown data type: %d %s", c->datatype,
! odl_datatype_name (c->datatype)); */
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
! "unknown data type: %d %s", c->datatype,
! odl_datatype_name (c->datatype));
g_string_sprintfa (buf, "UNKNOWN_TYPE");
break;
}
if (c->notnull)
g_string_append (buf, " NOT NULL");
else
--- 577,630 ----
g_string_append (buf, name);
g_free (name);
g_string_append (buf, " ");
+
switch (c->datatype)
{
! case GEAS_CD_DATATYPE_ID:
! g_string_sprintfa (buf, "CHAR(32)");
! break;
! case GEAS_CD_DATATYPE_CHAR:
g_string_sprintfa (buf, "VARCHAR");
if (c->format)
! g_string_sprintfa (buf, "(%d)", c->format);
else
g_string_sprintfa (buf, "(1)");
break;
! case GEAS_CD_DATATYPE_TEXT:
! g_string_sprintfa (buf, "TEXT"); /* <= 64k characters */
! break;
! case GEAS_CD_DATATYPE_INT16:
g_string_sprintfa (buf, "SMALLINT");
break;
! case GEAS_CD_DATATYPE_INT32:
g_string_sprintfa (buf, "INT");
break;
! case GEAS_CD_DATATYPE_INT64:
g_string_sprintfa (buf, "BIGINT");
break;
! case GEAS_CD_DATATYPE_FLOAT:
! g_string_sprintfa (buf, "DOUBLE");
break;
! case GEAS_CD_DATATYPE_BOOL:
! g_string_sprintfa (buf, "CHAR(1)");
break;
! case GEAS_CD_DATATYPE_DATE:
g_string_sprintfa (buf, "DATE");
break;
! case GEAS_CD_DATATYPE_TIME:
g_string_sprintfa (buf, "TIME");
break;
! case GEAS_CD_DATATYPE_DATETIME:
g_string_sprintfa (buf, "DATETIME");
break;
default:
! /* g_critical ("unknown data type: %d", c->datatype); */
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
! "unknown data type: %d", c->datatype);
g_string_sprintfa (buf, "UNKNOWN_TYPE");
break;
}
+
if (c->notnull)
g_string_append (buf, " NOT NULL");
else
***************
*** 662,668 ****
char *name;
GString *buf = NULL;
DatabaseChange *changes = NULL;
- GList *required = NULL;
GList *tmp;
/* GList *l; */
DatabaseDefinition *database = NULL;
--- 642,647 ----
***************
*** 681,693 ****
if (errormsg)
*errormsg = NULL;
! /* make a list of required classnames in this database */
! required = odl_tree_list_classes (all_classes);
! /* currently only a single SQL database is allowed at one time */
! /* so all classes are required */
! /* TODO: remove names from list if not required in */
!
! /* read current table definitions from database */
database = MySQL_read_database_definition (h);
/* show_database_definition( database ); */
--- 660,666 ----
if (errormsg)
*errormsg = NULL;
! /* read current table definitions from database */
database = MySQL_read_database_definition (h);
/* show_database_definition( database ); */
***************
*** 696,705 ****
/* if column doesn't match a class field, report it as unnecessary */
/* if class doesn't match a table, record the table as required */
/* if data field doesn't match a column, record the column as required */
! changes = compare_classes_to_database (all_classes, required, database,
! OQL_DBTYPE_MYSQL);
! odl_namelist_free (required);
! required = NULL;
if (!changes)
{
--- 669,675 ----
/* if column doesn't match a class field, report it as unnecessary */
/* if class doesn't match a table, record the table as required */
/* if data field doesn't match a column, record the column as required */
! changes = compare_classes_to_database (database, OQL_DBTYPE_MYSQL);
if (!changes)
{
Index: gnue/geas/src/objectstore/objectstore.c
diff -c gnue/geas/src/objectstore/objectstore.c:1.68
gnue/geas/src/objectstore/objectstore.c:1.69
*** gnue/geas/src/objectstore/objectstore.c:1.68 Wed Jun 20 18:26:23 2001
--- gnue/geas/src/objectstore/objectstore.c Sat Dec 15 05:43:33 2001
***************
*** 19,25 ****
along with GEAS; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
! $Id: objectstore.c,v 1.68 2001/06/20 22:26:23 reinhard Exp $
*/
--- 19,25 ----
along with GEAS; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
! $Id: objectstore.c,v 1.69 2001/12/15 10:43:33 reinhard Exp $
*/
***************
*** 698,719 ****
g_string_append (buf, ((DBchange *) l->data)->name);
g_string_append (buf, " ");
g_string_append (buf,
! odl_datatype_name (((DBchange *) l->data)->
datatype));
if (((DBchange *) l->data)->format)
{
! g_string_append (buf, "[");
! g_string_append (buf, ((DBchange *) l->data)->format);
! g_string_append (buf, "]");
}
! fprintf (fp, " %s (%s%s%s)\n",
((DBchange *) l->data)->name,
! odl_datatype_name (((DBchange *) l->data)->datatype),
! ((DBchange *) l->data)->format !=
! NULL ? " : " : "",
! ((DBchange *) l->data)->format !=
! NULL ? ((DBchange *) l->data)->format : "");
l = g_list_next (l);
if (l)
--- 698,725 ----
g_string_append (buf, ((DBchange *) l->data)->name);
g_string_append (buf, " ");
g_string_append (buf,
! geas_cd_datatype_name (((DBchange *) l->data)->
datatype));
if (((DBchange *) l->data)->format)
{
! char *f;
! f = g_strdup_printf ("[%d]", ((DBchange *)l->data)->format);
! g_string_append (buf, f);
! g_free (f);
}
! if (((DBchange *) l->data)->format)
! {
! fprintf (fp, " %s (%s[%d])\n",
((DBchange *) l->data)->name,
! geas_cd_datatype_name (((DBchange
*)l->data)->datatype),
! ((DBchange *) l->data)->format);
! }
! else
! {
! fprintf (fp, " %s (%s)\n", ((DBchange *) l->data)->name,
! geas_cd_datatype_name (((DBchange
*)l->data)->datatype));
! }
l = g_list_next (l);
if (l)
Index: gnue/geas/src/objectstore/postgresql.c
diff -c gnue/geas/src/objectstore/postgresql.c:1.13
gnue/geas/src/objectstore/postgresql.c:1.14
*** gnue/geas/src/objectstore/postgresql.c:1.13 Wed Nov 14 16:17:14 2001
--- gnue/geas/src/objectstore/postgresql.c Sat Dec 15 05:43:33 2001
***************
*** 20,26 ****
along with GEAS; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
! $Id: postgresql.c,v 1.13 2001/11/14 21:17:14 reinhard Exp $
*/
#include "config.h"
--- 20,26 ----
along with GEAS; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
! $Id: postgresql.c,v 1.14 2001/12/15 10:43:33 reinhard Exp $
*/
#include "config.h"
***************
*** 630,636 ****
for (i = 0; i < count_database_tables (db); i++)
{
DatabaseTable *tab = get_database_table (db, i);
! enum odl_fieldtype type;
/* get list of fields and types */
/* printf( "handling table '%s'\n" , tab->name ); */
--- 630,636 ----
for (i = 0; i < count_database_tables (db); i++)
{
DatabaseTable *tab = get_database_table (db, i);
! geas_cd_datatype type;
/* get list of fields and types */
/* printf( "handling table '%s'\n" , tab->name ); */
***************
*** 661,690 ****
{
char *name;
! if (g_strcasecmp (PQgetvalue (res, row, 1), "VARCHAR") == 0)
! type = DT_char;
else if (g_strcasecmp (PQgetvalue (res, row, 1), "INT2") == 0)
! type = DT_int16;
else if (g_strcasecmp (PQgetvalue (res, row, 1), "INT4") == 0)
! type = DT_int32;
else if (g_strcasecmp (PQgetvalue (res, row, 1), "INT8") == 0)
! type = DT_int64;
else if (g_strcasecmp (PQgetvalue (res, row, 1), "BOOL") == 0)
! type = DT_boolean;
! else if (g_strcasecmp (PQgetvalue (res, row, 1), "TEXT") == 0)
! type = DT_text;
else if (g_strcasecmp (PQgetvalue (res, row, 1), "DATE") == 0)
! type = DT_date;
else if (g_strcasecmp (PQgetvalue (res, row, 1), "TIME") == 0)
! type = DT_time;
else if (g_strcasecmp (PQgetvalue (res, row, 1), "DATETIME") == 0)
! type = DT_datetime;
! else if (g_strcasecmp (PQgetvalue (res, row, 1), "FLOAT8") == 0)
! type = DT_float;
! else if (g_strcasecmp (PQgetvalue (res, row, 1), "CHAR") == 0)
! type = DT_object;
else
! type = DT_unknown;
name = g_strdup (PQgetvalue (res, row, 0));
add_database_column (tab, name, type);
--- 661,690 ----
{
char *name;
! if (g_strcasecmp (PQgetvalue (res, row, 1), "CHAR") == 0)
! type = GEAS_CD_DATATYPE_ID;
! else if (g_strcasecmp (PQgetvalue (res, row, 1), "VARCHAR") == 0)
! type = GEAS_CD_DATATYPE_CHAR;
! else if (g_strcasecmp (PQgetvalue (res, row, 1), "TEXT") == 0)
! type = GEAS_CD_DATATYPE_TEXT;
else if (g_strcasecmp (PQgetvalue (res, row, 1), "INT2") == 0)
! type = GEAS_CD_DATATYPE_INT16;
else if (g_strcasecmp (PQgetvalue (res, row, 1), "INT4") == 0)
! type = GEAS_CD_DATATYPE_INT32;
else if (g_strcasecmp (PQgetvalue (res, row, 1), "INT8") == 0)
! type = GEAS_CD_DATATYPE_INT64;
! else if (g_strcasecmp (PQgetvalue (res, row, 1), "FLOAT8") == 0)
! type = GEAS_CD_DATATYPE_FLOAT;
else if (g_strcasecmp (PQgetvalue (res, row, 1), "BOOL") == 0)
! type = GEAS_CD_DATATYPE_BOOL;
else if (g_strcasecmp (PQgetvalue (res, row, 1), "DATE") == 0)
! type = GEAS_CD_DATATYPE_DATE;
else if (g_strcasecmp (PQgetvalue (res, row, 1), "TIME") == 0)
! type = GEAS_CD_DATATYPE_TIME;
else if (g_strcasecmp (PQgetvalue (res, row, 1), "DATETIME") == 0)
! type = GEAS_CD_DATATYPE_DATETIME;
else
! type = GEAS_CD_DATATYPE_UNKNOWN;
name = g_strdup (PQgetvalue (res, row, 0));
add_database_column (tab, name, type);
***************
*** 713,769 ****
g_string_append (buf, name);
g_free (name);
g_string_append (buf, " ");
switch (c->datatype)
{
! case DT_char:
g_string_sprintfa (buf, "VARCHAR");
if (c->format)
! g_string_sprintfa (buf, "(%s)", c->format);
else
g_string_sprintfa (buf, "(1)");
break;
! case DT_int16:
g_string_sprintfa (buf, "INT2");
break;
! case DT_int32:
! case DT_int:
! case DT_unsignedint:
g_string_sprintfa (buf, "INT4");
break;
! case DT_int64:
g_string_sprintfa (buf, "INT8");
break;
! case DT_boolean:
! case DT_bool:
! g_string_sprintfa (buf, "BOOL");
break;
! case DT_text:
! g_string_sprintfa (buf, "TEXT");
break;
! case DT_date:
g_string_sprintfa (buf, "DATE");
break;
! case DT_time:
g_string_sprintfa (buf, "TIME");
break;
! case DT_datetime:
g_string_sprintfa (buf, "DATETIME");
break;
- case DT_float:
- g_string_sprintfa (buf, "FLOAT8");
- break;
- case DT_object:
- g_string_sprintfa (buf, "CHAR(32)");
- break;
default:
! /* g_critical ("unknown data type: %d %s", c->datatype,
! odl_datatype_name (c->datatype)); */
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
! "unknown data type: %d %s", c->datatype,
! odl_datatype_name (c->datatype));
g_string_sprintfa (buf, "UNKNOWN_TYPE");
break;
}
if (c->notnull)
g_string_append (buf, " NOT NULL");
else
--- 713,766 ----
g_string_append (buf, name);
g_free (name);
g_string_append (buf, " ");
+
switch (c->datatype)
{
! case GEAS_CD_DATATYPE_ID:
! g_string_sprintfa (buf, "CHAR(32)");
! break;
! case GEAS_CD_DATATYPE_CHAR:
g_string_sprintfa (buf, "VARCHAR");
if (c->format)
! g_string_sprintfa (buf, "(%d)", c->format);
else
g_string_sprintfa (buf, "(1)");
break;
! case GEAS_CD_DATATYPE_TEXT:
! g_string_sprintfa (buf, "TEXT");
! break;
! case GEAS_CD_DATATYPE_INT16:
g_string_sprintfa (buf, "INT2");
break;
! case GEAS_CD_DATATYPE_INT32:
g_string_sprintfa (buf, "INT4");
break;
! case GEAS_CD_DATATYPE_INT64:
g_string_sprintfa (buf, "INT8");
break;
! case GEAS_CD_DATATYPE_FLOAT:
! g_string_sprintfa (buf, "FLOAT8");
break;
! case GEAS_CD_DATATYPE_BOOL:
! g_string_sprintfa (buf, "BOOL");
break;
! case GEAS_CD_DATATYPE_DATE:
g_string_sprintfa (buf, "DATE");
break;
! case GEAS_CD_DATATYPE_TIME:
g_string_sprintfa (buf, "TIME");
break;
! case GEAS_CD_DATATYPE_DATETIME:
g_string_sprintfa (buf, "DATETIME");
break;
default:
! /* g_critical ("unknown data type: %d %s", c->datatype); */
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
! "unknown data type: %d", c->datatype);
g_string_sprintfa (buf, "UNKNOWN_TYPE");
break;
}
+
if (c->notnull)
g_string_append (buf, " NOT NULL");
else
***************
*** 785,791 ****
char *name;
GString *buf;
DatabaseChange *changes = NULL;
- GList *required = NULL;
GList *tmp;
char tmpport[20];
DatabaseDefinition *database = NULL;
--- 782,787 ----
***************
*** 804,828 ****
if (errormsg)
*errormsg = NULL;
- /* make a list of required classnames in this database */
- required = odl_tree_list_classes (all_classes);
- /* currently only a single SQL database is allowed at one time */
- /* so all classes are required */
- /* TODO: remove names from list if not required in */
-
/* read current table definitions from database */
database = postgresql_read_database_definition (hnd);
- /* show_database_definition( database ); */
/* compare to current classes for this database */
/* if table doesn't match a class, report the table as unnecessary */
/* if column doesn't match a class field, report it as unnecessary */
/* if class doesn't match a table, record the table as required */
/* if data field doesn't match a column, record the column as required */
! changes = compare_classes_to_database (all_classes, required, database,
! OQL_DBTYPE_POSTGRESQL);
! odl_namelist_free (required);
! required = NULL;
if (!changes)
{
--- 800,814 ----
if (errormsg)
*errormsg = NULL;
/* read current table definitions from database */
database = postgresql_read_database_definition (hnd);
/* compare to current classes for this database */
/* if table doesn't match a class, report the table as unnecessary */
/* if column doesn't match a class field, report it as unnecessary */
/* if class doesn't match a table, record the table as required */
/* if data field doesn't match a column, record the column as required */
! changes = compare_classes_to_database (database, OQL_DBTYPE_POSTGRESQL);
if (!changes)
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- gnue/geas/src/objectstore compare.c compare.h m...,
Reinhard Mueller <=