From: Stefan Reddig Date: Fri, 29 Jan 2010 14:32:19 +0000 (+0100) Subject: - fixed the database/table scripts - db_user was missing - updated database schema... X-Git-Tag: Release-7.0.0~2291 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=7939b1abe5b70087137e26cf1dfe50d52a0d50aa;p=bacula%2Fbacula - fixed the database/table scripts - db_user was missing - updated database schema - fixed missing statements in sql*.h - since there is a db_type for Ingres now, there have to be 5, not 4, members in the arrays - worked alot on myingres.c - queries seems to be working, but the first INSERT fails with a segfault --- diff --git a/bacula/src/cats/cats.h b/bacula/src/cats/cats.h index 7712c5c622..f9e84bdea6 100644 --- a/bacula/src/cats/cats.h +++ b/bacula/src/cats/cats.h @@ -640,6 +640,7 @@ extern const char* my_ingres_batch_fill_path_query; #define SQL_ROW INGRES_ROW #define SQL_FIELD INGRES_FIELD +#define SQL_MATCH "~" #else @@ -742,12 +743,12 @@ typedef int (*custom_function_insert_t)(void*, const char*, int); typedef char* (*custom_function_error_t)(void*); typedef int (*custom_function_end_t)(void*, const char*); -extern const char* my_dbi_batch_lock_path_query[4]; -extern const char* my_dbi_batch_lock_filename_query[4]; -extern const char* my_dbi_batch_unlock_tables_query[4]; -extern const char* my_dbi_batch_fill_filename_query[4]; -extern const char* my_dbi_batch_fill_path_query[4]; -extern const char* my_dbi_match[4]; +extern const char* my_dbi_batch_lock_path_query[5]; +extern const char* my_dbi_batch_lock_filename_query[5]; +extern const char* my_dbi_batch_unlock_tables_query[5]; +extern const char* my_dbi_batch_fill_filename_query[5]; +extern const char* my_dbi_batch_fill_path_query[5]; +extern const char* my_dbi_match[5]; /* "Generic" names for easier conversion */ #define sql_store_result(x) (x)->result diff --git a/bacula/src/cats/create_bacula_database.in b/bacula/src/cats/create_bacula_database.in index 16008698ba..d28508d121 100644 --- a/bacula/src/cats/create_bacula_database.in +++ b/bacula/src/cats/create_bacula_database.in @@ -11,7 +11,7 @@ else echo "Creating MySQL database" @scriptdir@/create_mysql_database $* elif test xingres = x@DB_TYPE@ ; then - echo "Creating Ingres database" + echo "Creating Ingres database with $*" @scriptdir@/create_ingres_database $* else echo "Creating PostgreSQL database" diff --git a/bacula/src/cats/create_ingres_database.in b/bacula/src/cats/create_ingres_database.in index a287352f86..8694391bd5 100755 --- a/bacula/src/cats/create_ingres_database.in +++ b/bacula/src/cats/create_ingres_database.in @@ -5,6 +5,7 @@ bindir=@SQL_BINDIR@ db_name=@db_name@ +db_user=@db_user@ # use SQL_ASCII to be able to put any filename into # the database even those created with unusual character sets @@ -20,7 +21,7 @@ ENCODING="ENCODING 'SQL_ASCII'" # #ENCODING="ENCODING 'UTF8'" -if createdb $* ${db_name} +if createdb $* -u${db_user} ${db_name} then echo "Creation of ${db_name} database succeeded." else diff --git a/bacula/src/cats/dbi.c b/bacula/src/cats/dbi.c index e532f4a5c4..0b1472b48b 100644 --- a/bacula/src/cats/dbi.c +++ b/bacula/src/cats/dbi.c @@ -1255,7 +1255,7 @@ int my_dbi_sql_insert_id(B_DB *mdb, char *table_name) } #ifdef HAVE_BATCH_FILE_INSERT -const char *my_dbi_batch_lock_path_query[4] = { +const char *my_dbi_batch_lock_path_query[5] = { /* Mysql */ "LOCK TABLES Path write, batch write, Path as p write", /* Postgresql */ @@ -1263,9 +1263,12 @@ const char *my_dbi_batch_lock_path_query[4] = { /* SQLite */ "BEGIN", /* SQLite3 */ - "BEGIN"}; + "BEGIN", + /* Ingres (TODO) */ + "BEGIN" +}; -const char *my_dbi_batch_lock_filename_query[4] = { +const char *my_dbi_batch_lock_filename_query[5] = { /* Mysql */ "LOCK TABLES Filename write, batch write, Filename as f write", /* Postgresql */ @@ -1273,9 +1276,12 @@ const char *my_dbi_batch_lock_filename_query[4] = { /* SQLite */ "BEGIN", /* SQLite3 */ - "BEGIN"}; + "BEGIN", + /* Ingres (TODO) */ + "BEGIN" +}; -const char *my_dbi_batch_unlock_tables_query[4] = { +const char *my_dbi_batch_unlock_tables_query[5] = { /* Mysql */ "UNLOCK TABLES", /* Postgresql */ @@ -1283,9 +1289,12 @@ const char *my_dbi_batch_unlock_tables_query[4] = { /* SQLite */ "COMMIT", /* SQLite3 */ - "COMMIT"}; + "COMMIT", + /* Ingres */ + "COMMIT" +}; -const char *my_dbi_batch_fill_path_query[4] = { +const char *my_dbi_batch_fill_path_query[5] = { /* Mysql */ "INSERT INTO Path (Path) " "SELECT a.Path FROM " @@ -1303,9 +1312,15 @@ const char *my_dbi_batch_fill_path_query[4] = { /* SQLite3 */ "INSERT INTO Path (Path)" " SELECT DISTINCT Path FROM batch" - " EXCEPT SELECT Path FROM Path"}; + " EXCEPT SELECT Path FROM Path", + /* Ingres (TODO) */ + "INSERT INTO Path (Path) " + "SELECT a.Path FROM " + "(SELECT DISTINCT Path FROM batch) AS a " + "WHERE NOT EXISTS (SELECT Path FROM Path WHERE Path = a.Path) " +}; -const char *my_dbi_batch_fill_filename_query[4] = { +const char *my_dbi_batch_fill_filename_query[5] = { /* Mysql */ "INSERT INTO Filename (Name) " "SELECT a.Name FROM " @@ -1324,7 +1339,14 @@ const char *my_dbi_batch_fill_filename_query[4] = { /* SQLite3 */ "INSERT INTO Filename (Name)" " SELECT DISTINCT Name FROM batch " - " EXCEPT SELECT Name FROM Filename"}; + " EXCEPT SELECT Name FROM Filename", + /* Ingres (TODO) */ + "INSERT INTO Filename (Name) " + "SELECT a.Name FROM " + "(SELECT DISTINCT Name FROM batch) as a " + "WHERE NOT EXISTS " + "(SELECT Name FROM Filename WHERE Name = a.Name)" +}; #endif /* HAVE_BATCH_FILE_INSERT */ diff --git a/bacula/src/cats/drop_ingres_database.in b/bacula/src/cats/drop_ingres_database.in index 23c75fe287..c4d6e017f5 100755 --- a/bacula/src/cats/drop_ingres_database.in +++ b/bacula/src/cats/drop_ingres_database.in @@ -5,8 +5,9 @@ bindir=@SQL_BINDIR@ db_name=@db_name@ +db_user=@db_user@ -if destroydb ${db_name} +if destroydb -u${db_user} ${db_name} then echo "Drop of ${db_name} database succeeded." else diff --git a/bacula/src/cats/drop_ingres_tables.in b/bacula/src/cats/drop_ingres_tables.in index ad7f23caa8..5b20c50108 100755 --- a/bacula/src/cats/drop_ingres_tables.in +++ b/bacula/src/cats/drop_ingres_tables.in @@ -4,6 +4,7 @@ bindir=@SQL_BINDIR@ db_name=@db_name@ +db_user=@db_user@ sql -u${db_user} ${db_name} $* < 0 " "AND Path.PathId=File.PathId AND Filename.FilenameId=File.FilenameId " - "AND Filename.Name='%s' ORDER BY StartTime DESC LIMIT 20"}; + "AND Filename.Name='%s' ORDER BY StartTime DESC LIMIT 20", + /* Ingres */ + "SELECT Job.JobId as JobId," + "Path.Path||Filename.Name as Name, " + "StartTime,Type as JobType,JobStatus,JobFiles,JobBytes " + "FROM Client,Job,File,Filename,Path WHERE Client.Name='%s' " + "AND Client.ClientId=Job.ClientId " + "AND Job.JobId=File.JobId AND File.FileIndex > 0 " + "AND Path.PathId=File.PathId AND Filename.FilenameId=File.FilenameId " + "AND Filename.Name='%s' ORDER BY StartTime DESC LIMIT 20" + }; -const char *uar_create_temp[4] = { +const char *uar_create_temp[5] = { /* Mysql */ "CREATE TEMPORARY TABLE temp (" "JobId INTEGER UNSIGNED NOT NULL," @@ -735,9 +776,23 @@ const char *uar_create_temp[4] = { "VolumeName TEXT," "StartFile INTEGER UNSIGNED," "VolSessionId INTEGER UNSIGNED," - "VolSessionTime INTEGER UNSIGNED)"}; + "VolSessionTime INTEGER UNSIGNED)", + /* Ingres */ + "DECLARE GLOBAL TEMPORARY TABLE temp (" + "JobId INTEGER NOT NULL," + "JobTDate BIGINT," + "ClientId INTEGER," + "Level CHAR," + "JobFiles INTEGER," + "JobBytes BIGINT," + "StartTime TEXT," + "VolumeName TEXT," + "StartFile INTEGER," + "VolSessionId INTEGER," + "VolSessionTime INTEGER)" + }; -const char *uar_create_temp1[4] = { +const char *uar_create_temp1[5] = { /* Mysql */ "CREATE TEMPORARY TABLE temp1 (" "JobId INTEGER UNSIGNED NOT NULL," @@ -753,7 +808,12 @@ const char *uar_create_temp1[4] = { /* SQLite3 */ "CREATE TEMPORARY TABLE temp1 (" "JobId INTEGER UNSIGNED NOT NULL," - "JobTDate BIGINT UNSIGNED)"}; + "JobTDate BIGINT UNSIGNED)", + /* Ingres */ + "DECLARE GLOBAL TEMPORARY TABLE temp1 (" + "JobId INTEGER NOT NULL," + "JobTDate BIGINT)" + }; /* Query to get all files in a directory -- no recursing * Note, for PostgreSQL since it respects the "Single Value @@ -762,7 +822,7 @@ const char *uar_create_temp1[4] = { * for each time it was backed up. */ -const char *uar_jobid_fileindex_from_dir[4] = { +const char *uar_jobid_fileindex_from_dir[5] = { /* Mysql */ "SELECT Job.JobId,File.FileIndex FROM Job,File,Path,Filename,Client " "WHERE Job.JobId IN (%s) " @@ -801,9 +861,19 @@ const char *uar_jobid_fileindex_from_dir[4] = { "AND Job.ClientId=Client.ClientId " "AND Path.PathId=File.Pathid " "AND Filename.FilenameId=File.FilenameId " - "GROUP BY File.FileIndex "}; + "GROUP BY File.FileIndex ", + /* Ingres */ + "SELECT Job.JobId,File.FileIndex FROM Job,File,Path,Filename,Client " + "WHERE Job.JobId IN (%s) " + "AND Job.JobId=File.JobId " + "AND Path.Path='%s' " + "AND Client.Name='%s' " + "AND Job.ClientId=Client.ClientId " + "AND Path.PathId=File.Pathid " + "AND Filename.FilenameId=File.FilenameId" + }; -const char *sql_get_max_connections[4] = { +const char *sql_get_max_connections[5] = { /* Mysql */ "SHOW VARIABLES LIKE 'max_connections'", /* Postgresql */ @@ -811,11 +881,13 @@ const char *sql_get_max_connections[4] = { /* SQLite */ "SELECT 0", /* SQLite3 */ + "SELECT 0", + /* Ingres (TODO) */ "SELECT 0" }; /* Row number of the max_connections setting */ -const uint32_t sql_get_max_connections_index[4] = { +const uint32_t sql_get_max_connections_index[5] = { /* Mysql */ 1, /* Postgresql */ @@ -823,5 +895,7 @@ const uint32_t sql_get_max_connections_index[4] = { /* SQLite */ 0, /* SQLite3 */ + 0, + /* Ingres (TODO) */ 0 }; diff --git a/bacula/src/cats/sql_cmds.h b/bacula/src/cats/sql_cmds.h index 10cf606f28..d17fdbd453 100644 --- a/bacula/src/cats/sql_cmds.h +++ b/bacula/src/cats/sql_cmds.h @@ -73,13 +73,13 @@ extern const char CATS_IMP_EXP *uar_jobids_fileindex; extern const char CATS_IMP_EXP *uar_jobid_fileindex_from_table; extern const char CATS_IMP_EXP *uar_sel_jobid_temp; -extern const char CATS_IMP_EXP *select_recent_version[4]; -extern const char CATS_IMP_EXP *select_recent_version_with_basejob[4]; -extern const char CATS_IMP_EXP *create_deltabs[4]; +extern const char CATS_IMP_EXP *select_recent_version[5]; +extern const char CATS_IMP_EXP *select_recent_version_with_basejob[5]; +extern const char CATS_IMP_EXP *create_deltabs[5]; -extern const char CATS_IMP_EXP *uar_file[4]; -extern const char CATS_IMP_EXP *uar_create_temp[4]; -extern const char CATS_IMP_EXP *uar_create_temp1[4]; -extern const char CATS_IMP_EXP *uar_jobid_fileindex_from_dir[4]; -extern const char CATS_IMP_EXP *sql_get_max_connections[4]; -extern const uint32_t CATS_IMP_EXP sql_get_max_connections_index[4]; +extern const char CATS_IMP_EXP *uar_file[5]; +extern const char CATS_IMP_EXP *uar_create_temp[5]; +extern const char CATS_IMP_EXP *uar_create_temp1[5]; +extern const char CATS_IMP_EXP *uar_jobid_fileindex_from_dir[5]; +extern const char CATS_IMP_EXP *sql_get_max_connections[5]; +extern const uint32_t CATS_IMP_EXP sql_get_max_connections_index[5]; diff --git a/bacula/src/cats/sql_create.c b/bacula/src/cats/sql_create.c index c7c7e71070..a635861e41 100644 --- a/bacula/src/cats/sql_create.c +++ b/bacula/src/cats/sql_create.c @@ -225,6 +225,7 @@ db_create_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr) stat = true; } db_unlock(mdb); + Dmsg0(500, "Create Pool: done\n"); return stat; } @@ -1097,7 +1098,7 @@ bool db_write_batch_file_records(JCR *jcr) /* List of SQL commands to create temp table and indicies */ -const char *create_temp_basefile[4] = { +const char *create_temp_basefile[5] = { /* MySQL */ "CREATE TEMPORARY TABLE basefile%lld (" // "CREATE TABLE basefile%lld (" @@ -1118,7 +1119,12 @@ const char *create_temp_basefile[4] = { /* SQLite3 */ "CREATE TEMPORARY TABLE basefile%lld (" "Path TEXT," - "Name TEXT)" + "Name TEXT)", + + /* Ingres */ + "DECLARE GLOBAL TEMPORARY TABLE basefile%lld (" + "Path TEXT NOT NULL," + "Name TEXT NOT NULL)" }; /*