From e1ca33e6dd1cbd85a4b2271522493874f6e6b638 Mon Sep 17 00:00:00 2001 From: Marco van Wieringen Date: Mon, 30 Aug 2010 10:38:04 +0200 Subject: [PATCH] Fix the insert_autokey_record functions to be 64bit compliant. This fixes a long standing bug in the postgresql code where the id was converted using atoi which is now changed into a str_to_int64. --- bacula/src/cats/cats.h | 12 ++++++------ bacula/src/cats/dbi.c | 2 +- bacula/src/cats/mysql.c | 2 +- bacula/src/cats/postgresql.c | 8 ++++---- bacula/src/cats/sqlite.c | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/bacula/src/cats/cats.h b/bacula/src/cats/cats.h index e180cef198..aaf0e58e9a 100644 --- a/bacula/src/cats/cats.h +++ b/bacula/src/cats/cats.h @@ -198,7 +198,7 @@ SQL_ROW my_sqlite_fetch_row(B_DB *mdb); int my_sqlite_query(B_DB *mdb, const char *cmd); void my_sqlite_field_seek(B_DB *mdb, int field); SQL_FIELD *my_sqlite_fetch_field(B_DB *mdb); -int my_sqlite_insert_autokey_record(B_DB *mdb, const char *query, const char *table_name); +int64_t my_sqlite_insert_autokey_record(B_DB *mdb, const char *query, const char *table_name); extern const char* my_sqlite_batch_lock_query; extern const char* my_sqlite_batch_unlock_query; extern const char* my_sqlite_batch_fill_filename_query; @@ -326,7 +326,7 @@ SQL_ROW my_sqlite_fetch_row(B_DB *mdb); int my_sqlite_query(B_DB *mdb, const char *cmd); void my_sqlite_field_seek(B_DB *mdb, int field); SQL_FIELD *my_sqlite_fetch_field(B_DB *mdb); -int my_sqlite_insert_autokey_record(B_DB *mdb, const char *query, const char *table_name); +int64_t my_sqlite_insert_autokey_record(B_DB *mdb, const char *query, const char *table_name); extern const char* my_sqlite_batch_lock_query; extern const char* my_sqlite_batch_unlock_query; extern const char* my_sqlite_batch_fill_filename_query; @@ -414,7 +414,7 @@ extern const char* my_mysql_batch_unlock_tables_query; extern const char* my_mysql_batch_fill_filename_query; extern const char* my_mysql_batch_fill_path_query; extern void my_mysql_free_result(B_DB *mdb); -extern int my_mysql_insert_autokey_record(B_DB *mdb, const char *query, const char *table_name); +extern int64_t my_mysql_insert_autokey_record(B_DB *mdb, const char *query, const char *table_name); #else @@ -485,7 +485,7 @@ void my_postgresql_free_result(B_DB *mdb); POSTGRESQL_ROW my_postgresql_fetch_row (B_DB *mdb); int my_postgresql_query (B_DB *mdb, const char *query); void my_postgresql_data_seek (B_DB *mdb, int row); -int my_postgresql_insert_autokey_record (B_DB *mdb, const char *query, const char *table_name); +int64_t my_postgresql_insert_autokey_record (B_DB *mdb, const char *query, const char *table_name); void my_postgresql_field_seek (B_DB *mdb, int row); POSTGRESQL_FIELD * my_postgresql_fetch_field(B_DB *mdb); @@ -596,7 +596,7 @@ void my_ingres_data_seek (B_DB *mdb, int row); void my_ingres_field_seek (B_DB *mdb, int row); INGRES_FIELD * my_ingres_fetch_field(B_DB *mdb); void my_ingres_close (B_DB *mdb); -int my_ingres_insert_autokey_record (B_DB *mdb, const char *query, const char *table_name); +int64_t my_ingres_insert_autokey_record (B_DB *mdb, const char *query, const char *table_name); bool my_ingres_batch_start(JCR *jcr, B_DB *mdb); bool my_ingres_batch_end(JCR *jcr, B_DB *mdb, const char *error); @@ -725,7 +725,7 @@ const char * my_dbi_strerror (B_DB *mdb); int my_dbi_getisnull (dbi_result *result, int row_number, int column_number); char * my_dbi_getvalue (dbi_result *result, int row_number, unsigned int column_number); //int my_dbi_getvalue (dbi_result *result, int row_number, unsigned int column_number, char *value); -int my_dbi_insert_autokey_record(B_DB *mdb, const char *query, const char *table_name); +int64_t my_dbi_insert_autokey_record(B_DB *mdb, const char *query, const char *table_name); int my_dbi_batch_start(JCR *jcr, B_DB *mdb); int my_dbi_batch_end(JCR *jcr, B_DB *mdb, const char *error); diff --git a/bacula/src/cats/dbi.c b/bacula/src/cats/dbi.c index be21ae2297..b4b0f6500a 100644 --- a/bacula/src/cats/dbi.c +++ b/bacula/src/cats/dbi.c @@ -1275,7 +1275,7 @@ static int my_dbi_sequence_last(B_DB *mdb, const char *table_name) return id; } -int my_dbi_insert_autokey_record(B_DB *mdb, const char *query, const char *table_name) +int64_t my_dbi_insert_autokey_record(B_DB *mdb, const char *query, const char *table_name) { /* * First execute the insert query and then retrieve the currval. diff --git a/bacula/src/cats/mysql.c b/bacula/src/cats/mysql.c index c25d18c783..5b31d2b728 100644 --- a/bacula/src/cats/mysql.c +++ b/bacula/src/cats/mysql.c @@ -411,7 +411,7 @@ void my_mysql_free_result(B_DB *mdb) db_unlock(mdb); } -int my_mysql_insert_autokey_record(B_DB *mdb, const char *query, const char *table_name) +int64_t my_mysql_insert_autokey_record(B_DB *mdb, const char *query, const char *table_name) { /* * First execute the insert query and then retrieve the currval. diff --git a/bacula/src/cats/postgresql.c b/bacula/src/cats/postgresql.c index a5e90c7238..bcd1466b9e 100644 --- a/bacula/src/cats/postgresql.c +++ b/bacula/src/cats/postgresql.c @@ -650,7 +650,7 @@ void my_postgresql_free_result(B_DB *mdb) db_unlock(mdb); } -static int my_postgresql_currval(B_DB *mdb, const char *table_name) +static int64_t my_postgresql_currval(B_DB *mdb, const char *table_name) { // Obtain the current value of the sequence that // provides the serial value for primary key of the table. @@ -671,7 +671,7 @@ static int my_postgresql_currval(B_DB *mdb, const char *table_name) char sequence[NAMEDATALEN-1]; char query [NAMEDATALEN+50]; PGresult *result; - int id = 0; + int64_t id = 0; if (strcasecmp(table_name, "basefiles") == 0) { bstrncpy(sequence, "basefiles_baseid", sizeof(sequence)); @@ -702,7 +702,7 @@ static int my_postgresql_currval(B_DB *mdb, const char *table_name) if (PQresultStatus(result) == PGRES_TUPLES_OK) { Dmsg0(500, "getting value"); - id = atoi(PQgetvalue(result, 0, 0)); + id = str_to_int64(PQgetvalue(result, 0, 0)); Dmsg2(500, "got value '%s' which became %d\n", PQgetvalue(result, 0, 0), id); } else { Dmsg1(50, "Result status failed: %s\n", query); @@ -715,7 +715,7 @@ bail_out: return id; } -int my_postgresql_insert_autokey_record(B_DB *mdb, const char *query, const char *table_name) +int64_t my_postgresql_insert_autokey_record(B_DB *mdb, const char *query, const char *table_name) { /* * First execute the insert query and then retrieve the currval. diff --git a/bacula/src/cats/sqlite.c b/bacula/src/cats/sqlite.c index 90e18011b1..ccfa9f4c73 100644 --- a/bacula/src/cats/sqlite.c +++ b/bacula/src/cats/sqlite.c @@ -556,7 +556,7 @@ SQL_FIELD *my_sqlite_fetch_field(B_DB *mdb) } } -int my_sqlite_insert_autokey_record(B_DB *mdb, const char *query, const char *table_name) +int64_t my_sqlite_insert_autokey_record(B_DB *mdb, const char *query, const char *table_name) { /* * First execute the insert query and then retrieve the currval. -- 2.39.5