📄 dbgather.c
字号:
GList *db_getallviewnames() { DbDatabaseDef *db; int i; GList *views = NULL; db = globaldb; for (i = 0; i < db->numview; i++) { g_assert(db->view[i]); views = g_list_append(views, db->view[i]->name); } return views; }GList *db_get_fields(gchar * tablename) { DbDatabaseDef *db; int i; GList *fields = NULL; db = globaldb; g_assert(tablename); for (i = 0; i < db->numtable; i++) fields = g_list_append(fields, db->table[i]->name); return fields; }DbTableDef *db_findtable(gchar * table) { DbDatabaseDef *db; int i; db = globaldb; g_assert(table); for (i = 0; i < db->numtable; i++) if (strcmp(db->table[i]->name, table) == 0) return db->table[i]; for (i = 0; i < db->numview; i++) if (strcmp(db->view[i]->name, table) == 0) return db->view[i]; return NULL; }gintdb_getfieldposintable(DbTableDef * table, gchar * field) { int i; g_assert(field); g_assert(table); for (i = 0; i < table->num; i++) { g_assert(table->field[i]->name); if (strcmp(table->field[i]->name, field) == 0) return i; } warningmsg("Unable to find field %s in table %s", field, table->name); return -1; }/* build the definiation of how Object*s relate to other Object*s in the database */gintdb_buildrelationdef(DbDatabaseDef * db) { int i; for (i = 0; i < db->numtable; i++) db_buildsubtabledef(db, db->table[i]); for (i = 0; i < db->numview; i++) db_buildsubtabledef(db, db->view[i]); return 0; }/* find all the sub table references for lovely list... */gintdb_buildsubtabledef(DbDatabaseDef * db, DbTableDef * table) { gint i; /* error checking */ g_assert(table); g_assert(db); if (table->subtable != NULL) { errormsg("sub table is already set, can't set again"); return -1; } /* look for references to this table though the views */ for (i = 0; i < db->numview; i++) { g_assert(db->view[i]); g_assert(db->view[i]->query); if (db_sql_reftotable(db->view[i]->query, table->name) > 0) if (strcmp(db->view[i]->name, table->name) != 0) table->subtable = g_list_append(table->subtable, db->view[i]); } return 0; }/* Find all the tables used by the view */gintdb_extracttablesinfields(DbDatabaseDef * db, DbTableDef * table) { gint i, j, match = -1; if (table->fromtable != NULL) { errormsg("cant create from table glist twice"); return -1; } for (i = 0; i < table->num; i++) { /* skip if this is the same oid as last time */ if (match == table->field[i]->tableoid) continue; match = -1; for (j = 0; j < db->numtable; j++) if (db->table[j]->oid == table->field[i]->tableoid) { match = j; break; } if (match == -1) continue; if (table->fromtable != NULL) if (g_list_find(table->fromtable, db->table[match]) != NULL) continue; table->fromtable = g_list_append(table->fromtable, db->table[match]); } return 0; }/* internal function */gintdb_isview(DbDatabaseDef * db, gint tableoid, gchar ** retstr) { int i; g_assert(db); for (i = 0; i < db->numview; i++) { if (db->view[i]->oid == tableoid) { *retstr = db->view[i]->name; return 1; } } for (i = 0; i < db->numtable; i++) { if (db->table[i]->oid == tableoid) { *retstr = db->table[i]->name; return 0; } } return -1; }/* find out how the view was made and all the source for each field */voiddb_tablesourceforallfields(DbDatabaseDef * db) { gint i, j, oid; for (i = 0; i < db->numview; i++) { for (j = 0; j < db->view[i]->num; j++) { /* see if we can find a tablesource for this individual field */ oid = db_tablesourceforfield(db, db->view[i]->field[j]->name, db->view[i]->oid, db->view[i]->query); if (oid != -1) db->view[i]->field[j]->tableoid = oid; } /* build a list of what tables are used for this view */ db_extracttablesinfields(db, db->view[i]); } }/* does a view correspond to this name, if so return it. */gintdb_viewforthis(gchar * viewname) { gint i; DbDatabaseDef *db = globaldb; g_assert(viewname); for (i = 0; i < db->numview; i++) if (strcasecmp(db->view[i]->name, viewname) == 0) return i; return -1; }DbFieldDef *db_findfield(DbTableDef * dt, gchar * field) { gint i; gchar *suggestfield; for (i = 0; i < dt->num; i++) if (strcmp(field, dt->field[i]->name) == 0) return dt->field[i]; /* ok can't find it here, so lets try again by being a bit more agressive */ suggestfield = db_sqlparse_suggestfield(field); if (suggestfield != NULL) { for (i = 0; i < dt->num; i++) if (strcmp(suggestfield, dt->field[i]->name) == 0) { mem_free(suggestfield); return dt->field[i]; } mem_free(suggestfield); } return NULL; }/** * db_default_isitafunction: * * Find out if the default value is actually a function to call from db * Not sure what value1 or value2 is, someone please fill us all in. */gintdb_default_isitafunction(gchar * value1, gchar * value2) { gint i, num, matchcount = 0, cont = 0; gint retval = 0; gchar compare[10] = "FUNC"; /* debugmsg("got %s and %s",value1,value2); */ /* HELLLLLOO WORLD! */ g_assert(value1); g_assert(value2); num = strlen(value1); /* go through and find first bracket */ for (i = 0; i < num; i++) if (value1[i] == '(') retval = 1; /* find closing off bracket */ if (retval == 1) { for (i = 0; i < num; i++) if (value1[i] == ')') retval = 2; /* make it once less if u get what i mean */ retval--; } /* ok now check value2, which is the adbin field in postgresql for the clause FUNC */ if (retval == 1) { num = strlen(value2); for (i = 0; i < num; i++) { if (value2[i] == compare[matchcount]) { matchcount++; cont = 1; if (matchcount == strlen(compare)) { /* finished here, we have a match */ retval = 2; cont = 0; break; } } /* reset matchcount cause of non-consitent match */ else if (cont == 1) { cont = 0; matchcount = 0; } } retval--; } if (retval == 0) { num = strlen(value1); /* looking for x::y in value1 */ for (i=1;i<num-2;i++) { if (value1[i]==':' && value1[i+1]==':') { retval = 1; break; } } } /* ps. i'm really drunk at moment if you didnt notice and i am having problems typing. drinking vodkaa. with friends while watching exocides. expect 3 of 5 of us have fallen asleep on flloor. So ummm. I'm here coding. Man I'm typing well at moment. excuess me fro any really bad coding styles I may while in this state */ /* debugmsg("returning %d . yeah. for %s",retval,value1); */ return retval; }/** * This was added by Francis. The purpose is to provide local way to access * current database rather than using: extern DbDatabaseDef *db */DbDatabaseDef *db_get_current_database (){ return globaldb;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -