Thread: [Refdb-cvs] CVS: refdb/src dbfncs.c,1.15.2.13,1.15.2.14 dbfncs.h,1.6.2.4,1.6.2.5
Status: Beta
Brought to you by:
mhoenicka
From: Markus H. <mho...@us...> - 2005-09-11 19:58:18
|
Update of /cvsroot/refdb/refdb/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4898 Modified Files: Tag: Release_0_9_5_stable dbfncs.c dbfncs.h Log Message: new function my_dbi_result_get_short_idval() Index: dbfncs.c =================================================================== RCS file: /cvsroot/refdb/refdb/src/dbfncs.c,v retrieving revision 1.15.2.13 retrieving revision 1.15.2.14 diff -u -U2 -r1.15.2.13 -r1.15.2.14 --- dbfncs.c 7 Sep 2005 23:35:38 -0000 1.15.2.13 +++ dbfncs.c 11 Sep 2005 19:58:10 -0000 1.15.2.14 @@ -480,5 +480,4 @@ "refdb_title_series TEXT," "refdb_address TEXT," - "refdb_url TEXT," "refdb_issn VARCHAR(255)," "refdb_pyother_info VARCHAR(255)," @@ -493,8 +492,4 @@ "refdb_misc2 VARCHAR(255)," "refdb_misc3 VARCHAR(255)," - "refdb_linkpdf TEXT," - "refdb_linkfull TEXT," - "refdb_linkrel TEXT," - "refdb_linkimg TEXT," "PRIMARY KEY (refdb_id))"); @@ -712,4 +707,31 @@ dbi_result_free(dbires); + /* create the link table */ + + /* this will implicitly create a SEQUENCE t_link_link_id_seq */ + dbires = dbi_conn_query(conn, "CREATE TABLE t_link (" + "link_id BIGSERIAL," + "link_url TEXT NOT NULL," + "PRIMARY KEY (link_id))"); + + + if (!dbires) { + LOG_PRINT(LOG_ERR, get_status_msg(257)); + return 257; + } + + dbi_result_free(dbires); + + /* create link_url index */ + dbires = dbi_conn_query(conn, "CREATE INDEX i_link_url ON t_link (link_url)"); + + + if (!dbires) { + LOG_PRINT(LOG_ERR, get_status_msg(257)); + return 257; + } + + dbi_result_free(dbires); + /* create the author xtable */ /* this will implicitly create a SEQUENCE t_xauthor_xauthor_id_seq */ @@ -879,4 +901,63 @@ dbi_result_free(dbires); + /* create the links xtable */ + /* this will implicitly create a SEQUENCE t_xlink_xlink_id_seq */ + dbires = dbi_conn_query(conn, "CREATE TABLE t_xlink (" + "xlink_id BIGSERIAL," + "link_id BIGINT NOT NULL," + "xref_id BIGINT NOT NULL," + "xlink_type VARCHAR(11) DEFAULT \'URL\'," + "xlink_source VARCHAR(11) DEFAULT \'REFERENCE\'," + "PRIMARY KEY (xlink_id))"); + + + if (!dbires) { + LOG_PRINT(LOG_ERR, get_status_msg(258)); + return 258; + } + + dbi_result_free(dbires); + + /* create x_link indices */ + dbires = dbi_conn_query(conn, "CREATE INDEX i_xlink_link_id ON t_xlink (link_id)"); + + + if (!dbires) { + LOG_PRINT(LOG_ERR, get_status_msg(258)); + return 258; + } + + dbi_result_free(dbires); + + dbires = dbi_conn_query(conn, "CREATE INDEX i_xlink_xref_id ON t_xlink (xref_id)"); + + + if (!dbires) { + LOG_PRINT(LOG_ERR, get_status_msg(258)); + return 258; + } + + dbi_result_free(dbires); + + dbires = dbi_conn_query(conn, "CREATE INDEX i_xlink_xlink_type ON t_xlink (xlink_type)"); + + + if (!dbires) { + LOG_PRINT(LOG_ERR, get_status_msg(258)); + return 258; + } + + dbi_result_free(dbires); + + dbires = dbi_conn_query(conn, "CREATE INDEX i_xlink_xlink_source ON t_xlink (xlink_source)"); + + + if (!dbires) { + LOG_PRINT(LOG_ERR, get_status_msg(258)); + return 258; + } + + dbi_result_free(dbires); + /* create user permissions */ /* PostgreSQL uses table-based permissions, so it is easier to create @@ -897,5 +978,5 @@ } - sprintf(buffer, "GRANT SELECT, INSERT, UPDATE, DELETE ON t_meta, t_refdb, t_author, t_keyword, t_periodical, t_user, t_note, t_xauthor, t_xkeyword, t_xuser, t_xnote, t_refdb_refdb_id_seq, t_author_author_id_seq, t_keyword_keyword_id_seq, t_periodical_periodical_id_seq, t_user_user_id_seq, t_note_note_id_seq, t_xauthor_xauthor_id_seq, t_xkeyword_xkeyword_id_seq, t_xuser_xuser_id_seq, t_xnote_xnote_id_seq TO GROUP %suser", ptr_clrequest->argument); + sprintf(buffer, "GRANT SELECT, INSERT, UPDATE, DELETE ON t_meta, t_refdb, t_author, t_keyword, t_periodical, t_user, t_note, t_link, t_xauthor, t_xkeyword, t_xuser, t_xnote, t_xlink, t_refdb_refdb_id_seq, t_author_author_id_seq, t_keyword_keyword_id_seq, t_periodical_periodical_id_seq, t_user_user_id_seq, t_note_note_id_seq, t_link_link_id_seq, t_xauthor_xauthor_id_seq, t_xkeyword_xkeyword_id_seq, t_xuser_xuser_id_seq, t_xnote_xnote_id_seq, t_xlink_xlink_id_seq TO GROUP %suser", ptr_clrequest->argument); LOG_PRINT(LOG_DEBUG, buffer); @@ -951,5 +1032,4 @@ "refdb_title_series TEXT," "refdb_address TEXT," - "refdb_url TEXT," "refdb_issn TEXT," "refdb_pyother_info TEXT," @@ -963,9 +1043,5 @@ "refdb_misc1 TEXT," "refdb_misc2 TEXT," - "refdb_misc3 TEXT," - "refdb_linkpdf TEXT," - "refdb_linkfull TEXT," - "refdb_linkrel TEXT," - "refdb_linkimg TEXT)"); + "refdb_misc3 TEXT)"); @@ -1181,4 +1257,28 @@ dbi_result_free(dbires); + /* create the link table */ + dbires = dbi_conn_query(conn, "CREATE TABLE t_link (" + "link_id INTEGER PRIMARY KEY," + "link_url TEXT NOT NULL)"); + + + if (!dbires) { + LOG_PRINT(LOG_ERR, get_status_msg(257)); + return 257; + } + + dbi_result_free(dbires); + + /* create t_link table index */ + dbires = dbi_conn_query(conn, "CREATE INDEX i_link_url ON t_link (link_url)"); + + + if (!dbires) { + LOG_PRINT(LOG_ERR, get_status_msg(257)); + return 257; + } + + dbi_result_free(dbires); + /* create the author xtable */ dbires = dbi_conn_query(conn, "CREATE TABLE t_xauthor (" @@ -1340,4 +1440,61 @@ dbi_result_free(dbires); + /* create the links xtable */ + dbires = dbi_conn_query(conn, "CREATE TABLE t_xlink (" + "xlink_id INTEGER PRIMARY KEY," + "link_id INTEGER NOT NULL," + "xref_id INTEGER NOT NULL," + "xlink_type TEXT DEFAULT \'URL\'," + "xlink_source TEXT DEFAULT \'REFERENCE\')"); + + + if (!dbires) { + LOG_PRINT(LOG_ERR, get_status_msg(258)); + return 258; + } + + dbi_result_free(dbires); + + /* create t_xlink table indexes */ + dbires = dbi_conn_query(conn, "CREATE INDEX i_xlink_linkid ON t_xlink (link_id)"); + + + if (!dbires) { + LOG_PRINT(LOG_ERR, get_status_msg(258)); + return 258; + } + + dbi_result_free(dbires); + + dbires = dbi_conn_query(conn, "CREATE INDEX i_xlink_xrefid ON t_xlink (xref_id)"); + + + if (!dbires) { + LOG_PRINT(LOG_ERR, get_status_msg(258)); + return 258; + } + + dbi_result_free(dbires); + + dbires = dbi_conn_query(conn, "CREATE INDEX i_xlink_xlinktype ON t_xlink (xlink_type)"); + + + if (!dbires) { + LOG_PRINT(LOG_ERR, get_status_msg(258)); + return 258; + } + + dbi_result_free(dbires); + + dbires = dbi_conn_query(conn, "CREATE INDEX i_xlink_xlinksource ON t_xlink (xlink_source)"); + + + if (!dbires) { + LOG_PRINT(LOG_ERR, get_status_msg(258)); + return 258; + } + + dbi_result_free(dbires); + return 0; } @@ -1382,5 +1539,4 @@ "refdb_title_series TEXT," "refdb_address TEXT," - "refdb_url TEXT," "refdb_issn TEXT," "refdb_pyother_info TEXT," @@ -1394,9 +1550,5 @@ "refdb_misc1 TEXT," "refdb_misc2 TEXT," - "refdb_misc3 TEXT," - "refdb_linkpdf TEXT," - "refdb_linkfull TEXT," - "refdb_linkrel TEXT," - "refdb_linkimg TEXT)"); + "refdb_misc3 TEXT)"); @@ -1612,4 +1764,28 @@ dbi_result_free(dbires); + /* create the link table */ + dbires = dbi_conn_query(conn, "CREATE TABLE t_link (" + "link_id INTEGER PRIMARY KEY," + "link_url TEXT NOT NULL)"); + + + if (!dbires) { + LOG_PRINT(LOG_ERR, get_status_msg(257)); + return 257; + } + + dbi_result_free(dbires); + + /* create t_link table index */ + dbires = dbi_conn_query(conn, "CREATE INDEX i_link_url ON t_link (link_url)"); + + + if (!dbires) { + LOG_PRINT(LOG_ERR, get_status_msg(257)); + return 257; + } + + dbi_result_free(dbires); + /* create the author xtable */ dbires = dbi_conn_query(conn, "CREATE TABLE t_xauthor (" @@ -1771,4 +1947,61 @@ dbi_result_free(dbires); + /* create the links xtable */ + dbires = dbi_conn_query(conn, "CREATE TABLE t_xlink (" + "xlink_id INTEGER PRIMARY KEY," + "link_id BIGINT NOT NULL," + "xref_id BIGINT NOT NULL," + "xlink_type TEXT DEFAULT \'URL\'," + "xlink_source TEXT DEFAULT \'REFERENCE\')"); + + + if (!dbires) { + LOG_PRINT(LOG_ERR, get_status_msg(258)); + return 258; + } + + dbi_result_free(dbires); + + /* create t_xlink table indexes */ + dbires = dbi_conn_query(conn, "CREATE INDEX i_xlink_linkid ON t_xlink (link_id)"); + + + if (!dbires) { + LOG_PRINT(LOG_ERR, get_status_msg(258)); + return 258; + } + + dbi_result_free(dbires); + + dbires = dbi_conn_query(conn, "CREATE INDEX i_xlink_xrefid ON t_xlink (xref_id)"); + + + if (!dbires) { + LOG_PRINT(LOG_ERR, get_status_msg(258)); + return 258; + } + + dbi_result_free(dbires); + + dbires = dbi_conn_query(conn, "CREATE INDEX i_xlink_xlinktype ON t_xlink (xlink_type)"); + + + if (!dbires) { + LOG_PRINT(LOG_ERR, get_status_msg(258)); + return 258; + } + + dbi_result_free(dbires); + + dbires = dbi_conn_query(conn, "CREATE INDEX i_xlink_xlinksource ON t_xlink (xlink_source)"); + + + if (!dbires) { + LOG_PRINT(LOG_ERR, get_status_msg(258)); + return 258; + } + + dbi_result_free(dbires); + return 0; } @@ -2227,4 +2460,45 @@ /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + my_dbi_result_get_short_idval(): returns an id value by field name. Takes + care of the fact that some db servers use + longlongs where ints are expected + + unsigned int my_dbi_result_get_short_idval returns an id value + + dbi_result dbires result of a previous query + + const char* fieldname name of the field to retrieve + + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +unsigned int my_dbi_result_get_short_idval(dbi_result dbires, const char* fieldname) { + dbi_conn conn; + char buffer[512]; + const char *fakeid; + unsigned int field_attrib; + unsigned int the_uint; + unsigned long long the_ulonglong; + + conn = dbi_result_get_conn(dbires); + + field_attrib = dbi_result_get_field_attrib(dbires, fieldname, DBI_INTEGER_SIZE4, DBI_INTEGER_SIZE4); +/* printf("field_type went to %d\n", (int)field_type); */ + + if (field_attrib) { + /* value is a 4-byte integer */ + the_uint = dbi_result_get_uint(dbires, fieldname); +/* sprintf(buffer, "ulong: u %u<< lu %lu<< llu %llu", the_ulong, the_ulong, the_ulong); */ +/* LOG_PRINT(LOG_DEBUG, buffer); */ + return the_uint; + } + else { + /* value is an 8-byte integer. Cast to uint */ + the_ulonglong = dbi_result_get_ulonglong(dbires, fieldname); +/* sprintf(buffer, "ulonglong: u %u<< lu %lu<< llu %llu", the_ulonglong, the_ulonglong, the_ulonglong); */ +/* LOG_PRINT(LOG_DEBUG, buffer); */ + return (unsigned int)the_ulonglong; + } +} + +/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ my_dbi_conn_get_versioninfo(): retrieves the version info of a db engine Index: dbfncs.h =================================================================== RCS file: /cvsroot/refdb/refdb/src/dbfncs.h,v retrieving revision 1.6.2.4 retrieving revision 1.6.2.5 diff -u -U2 -r1.6.2.4 -r1.6.2.5 --- dbfncs.h 26 Jul 2005 20:21:45 -0000 1.6.2.4 +++ dbfncs.h 11 Sep 2005 19:58:10 -0000 1.6.2.5 @@ -59,4 +59,5 @@ unsigned long long my_dbi_result_get_idval(dbi_result dbires, const char* fieldname); unsigned long long my_dbi_result_get_idval_idx(dbi_result dbires, unsigned int idx); +unsigned int my_dbi_result_get_short_idval(dbi_result dbires, const char* fieldname); int my_dbi_conn_get_versioninfo(dbi_conn conn, struct VERSIONINFO* ptr_ver); |