Changeset 35
- Timestamp:
- May 19, 2006, 8:35:34 PM (19 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sql_init/samhain.postgres.init
r1 r35 1 1 CREATE SEQUENCE log_log_index_seq START 1; 2 2 CREATE TABLE log ( 3 log_index INTEGER NOT NULL DEFAULT NEXTVAL('log_log_index_seq'),3 log_index INTEGER NOT NULL, 4 4 log_ref BIGINT NULL, 5 5 log_host VARCHAR(64) NOT NULL DEFAULT 'localhost', -
trunk/src/sh_database.c
r30 r35 870 870 PGresult * res; 871 871 unsigned int i; 872 const char * params[1]; 873 char id_param[32]; 872 874 static SH_TIMEOUT sh_timer = { 0, 3600, S_TRUE }; 873 875 … … 940 942 941 943 942 /* do the insert943 */ 944 res = PQexec(conn, query);945 if (PQresultStatus(res) != PGRES_ COMMAND_OK)944 /* get the unique row index 945 */ 946 res = PQexec(conn, _("SELECT NEXTVAL('log_log_index_seq')")); 947 if (PQresultStatus(res) != PGRES_TUPLES_OK) 946 948 { 947 949 PQclear(res); 948 950 goto err_out; 949 951 } 952 953 *id = atoi (PQgetvalue(res, 0, 0)); 950 954 PQclear(res); 951 955 952 /* get the unique row index 953 */ 954 res = PQexec(conn, _("SELECT last_value FROM log_log_index_seq")); 955 if (PQresultStatus(res) != PGRES_TUPLES_OK) 956 sl_snprintf(id_param, 32, "%ld", *id); 957 params[0] = id_param; 958 959 /* do the insert 960 */ 961 res = PQexecParams(conn, query, 1, NULL, params, NULL, NULL, 1); 962 if (PQresultStatus(res) != PGRES_COMMAND_OK) 956 963 { 957 964 PQclear(res); 958 965 goto err_out; 959 966 } 960 961 *id = atoi (PQgetvalue(res, 0, 0));962 963 967 PQclear(res); 968 964 969 if (S_FALSE == sh_persistent_dbconn) 965 970 { … … 1244 1249 /*@+bufferoverflowhigh@*/ 1245 1250 1246 #if def WITH_ORACLE1251 #if defined(WITH_ORACLE) 1247 1252 /* Oracle needs some help for the time format (fix by Michael Somers) 1248 1253 */ … … 1257 1262 (db_entry->msg[0] == '\0' ? _("NULL") : db_entry->msg), 1258 1263 '\''); 1264 (void) sl_snprintf (columns, 1023, 1265 _("(log_ref,log_host,log_time,log_sev,log_msg")); 1266 #elif defined(WITH_POSTGRES) 1267 /* Prepare query for PQexecParams 1268 */ 1269 (void) 1270 sl_snprintf (values, SH_QUERY_MAX, 1271 _("($1,%s,%c%s%c,%c%s%c,%c%s%c,%c%s%c"), 1272 id >= 0 ? num : _("NULL"), 1273 '\'', db_entry->host,'\'', 1274 '\'', db_entry->time,'\'', 1275 '\'', db_entry->sev, '\'', 1276 '\'', 1277 (db_entry->msg[0] == '\0' ? _("NULL") : db_entry->msg), 1278 '\''); 1279 (void) sl_snprintf (columns, 1023, 1280 _("(log_index,log_ref,log_host,log_time,log_sev,log_msg")); 1259 1281 #else 1260 1282 (void) … … 1267 1289 (db_entry->msg[0] == '\0' ? _("NULL") : db_entry->msg), 1268 1290 '\''); 1269 #endif1270 1271 1291 (void) sl_snprintf (columns, 1023, 1272 1292 _("(log_ref,log_host,log_time,log_sev,log_msg")); 1293 #endif 1294 1273 1295 1274 1296 /*@-type@*//* byte* versus char[..] */ … … 1666 1688 /* recursively enter linked list of messages into database, last first 1667 1689 */ 1668 int sh_database_insert_rec (dbins * curr, unsignedint depth)1669 { 1670 long id = 0;1690 long sh_database_insert_rec (dbins * curr, int depth) 1691 { 1692 unsigned long id = 0; 1671 1693 dbins * prev; 1672 1694 … … 1700 1722 SH_FREE(curr); 1701 1723 1702 SL_RETURN(id, _("sh_database_insert "));1724 SL_RETURN(id, _("sh_database_insert_rec")); 1703 1725 } 1704 1726
Note:
See TracChangeset
for help on using the changeset viewer.