From: Marco van Wieringen Date: Sat, 20 Feb 2010 20:03:40 +0000 (+0100) Subject: Added patch from Stefan Reddig -- added some checks, db test prog X-Git-Tag: Release-5.0.1~29 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=3e7c99cf10f4c860e1734bcbf29369b7a4d880d1;p=bacula%2Fbacula Added patch from Stefan Reddig -- added some checks, db test prog Conflicts: bacula/src/cats/ingres.c bacula/src/cats/myingres.c --- diff --git a/bacula/src/cats/ingres.c b/bacula/src/cats/ingres.c index 681c209061..2d2f5a3ee5 100755 --- a/bacula/src/cats/ingres.c +++ b/bacula/src/cats/ingres.c @@ -515,17 +515,48 @@ int my_ingres_query(B_DB *mdb, const char *query) if (mdb->status == ING_COMMAND_OK) { Dmsg1(500, "we have a result\n", query); - // how many fields in the set? - mdb->num_fields = (int)INGnfields(mdb->result); - Dmsg1(500, "we have %d fields\n", mdb->num_fields); - - mdb->num_rows = INGntuples(mdb->result); - Dmsg1(500, "we have %d rows\n", mdb->num_rows); - - mdb->status = 0; /* succeed */ - } else { - Dmsg1(50, "Result status failed: %s\n", query); - goto bail_out; + if ((cols = INGgetCols(query)) == 0) + { + Dmsg0(500,"my_ingres_query (non SELECT) starting...\n"); + /* non SELECT */ + mdb->num_rows = INGexec(mdb->db, query); + if(INGcheck()) + { + Dmsg0(500,"my_ingres_query (non SELECT) went wrong\n"); + mdb->status = 1; + } + else + { + Dmsg0(500,"my_ingres_query (non SELECT) seems ok\n"); + mdb->status = 0; + } + } + else if ( cols > 0) + { + /* SELECT */ + mdb->result = INGquery(mdb->db, query); + if ( mdb->result != NULL ) + { + Dmsg1(500, "we have a result\n", query); + + // how many fields in the set? + mdb->num_fields = (int)INGnfields(mdb->result); + Dmsg1(500, "we have %d fields\n", mdb->num_fields); + + mdb->num_rows = INGntuples(mdb->result); + Dmsg1(500, "we have %d rows\n", mdb->num_rows); + + mdb->status = 0; /* succeed */ + } + else + { + Dmsg0(500, "No resultset...\n"); + mdb->status = 1; /* failed */ + } + } + else + { + mdb->status = 1; /* failed */ } Dmsg0(500, "my_ingres_query finishing\n"); diff --git a/bacula/src/cats/myingres.c b/bacula/src/cats/myingres.c index 17d94fef46..4ed2fdae40 100644 --- a/bacula/src/cats/myingres.c +++ b/bacula/src/cats/myingres.c @@ -353,10 +353,9 @@ short INGftype(const INGresult *res, int column_number) } INGresult *INGexec(INGconn *conn, const char *query) { - /* TODO: error handling -> res->status? */ - IISQLDA *desc = NULL; - INGresult *res = NULL; - int cols = -1; +/* # line 374 "myingres.sc" */ + + long rowcount; char stmt[2000]; strncpy(stmt,query,strlen(query)); stmt[strlen(query)]='\0'; @@ -375,9 +374,30 @@ INGresult *INGexec(INGconn *conn, const char *query) IIsqExImmed(stmt); IIsyncup((char *)0,0); } -/* # line 401 "myingres.sc" */ /* host code */ - } - else +/* # line 383 "myingres.sc" */ /* host code */ + INGcheck(); +/* # line 385 "myingres.sc" */ /* inquire_ingres */ + { + IILQisInqSqlio((short *)0,1,30,sizeof(rowcount),&rowcount,8); + } +/* # line 386 "myingres.sc" */ /* host code */ + INGcheck(); + return (int)(sqlca.sqlerrd[2]); +} +INGresult *INGquery(INGconn *conn, const char *query) +{ + /* TODO: error handling */ + IISQLDA *desc = NULL; + INGresult *res = NULL; + int cols = -1; +/* # line 398 "myingres.sc" */ + + char stmt[2000]; +/* # line 400 "myingres.sc" */ + + strncpy(stmt,query,strlen(query)); + stmt[strlen(query)]='\0'; + if ((cols = INGgetCols(query)) > 0) { DEBB(1) printf("INGexec: select\n"); diff --git a/bacula/src/tools/Makefile.in b/bacula/src/tools/Makefile.in index 19e638aa13..f98845f989 100644 --- a/bacula/src/tools/Makefile.in +++ b/bacula/src/tools/Makefile.in @@ -35,7 +35,7 @@ EXTRAOBJS = @OBJLIST@ DIRCONFOBJS = ../dird/dird_conf.o ../dird/run_conf.o ../dird/inc_conf.o NODIRTOOLS = bsmtp -DIRTOOLS = bsmtp dbcheck drivetype fstype testfind testls bregex bwild bbatch bregtest bvfs_test +DIRTOOLS = bsmtp dbcheck drivetype fstype testfind testls bregex bwild bbatch bregtest bvfs_test ing_test TOOLS = $(@DIR_TOOLS@) INSNODIRTOOLS = bsmtp @@ -107,6 +107,10 @@ bvfs_test: Makefile ../findlib/libbacfind$(DEFAULT_ARCHIVE_TYPE) ../lib/libbac$( $(LIBTOOL_LINK) $(CXX) -g $(LDFLAGS) -L../cats -L. -L../lib -L../findlib -o $@ bvfs_test.o \ -lbacsql -lbacfind -lbac -lm $(DB_LIBS) $(LIBS) $(GETTEXT_LIBS) $(OPENSSL_LIBS) +ing_test: Makefile ../findlib/libbacfind$(DEFAULT_ARCHIVE_TYPE) ../lib/libbac$(DEFAULT_ARCHIVE_TYPE) ../cats/libbacsql$(DEFAULT_ARCHIVE_TYPE) ing_test.o + $(LIBTOOL_LINK) $(CXX) -g $(LDFLAGS) -L../cats -L. -L../lib -L../findlib -o $@ ing_test.o \ + -lbacsql -lbacfind -lbac -lm $(DB_LIBS) $(LIBS) $(GETTEXT_LIBS) $(OPENSSL_LIBS) + gigaslam.o: gigaslam.c $(CC) $(CFLAGS) -c $< diff --git a/bacula/src/tools/ing_test.c b/bacula/src/tools/ing_test.c new file mode 100644 index 0000000000..362018d592 --- /dev/null +++ b/bacula/src/tools/ing_test.c @@ -0,0 +1,217 @@ +/* + Bacula® - The Network Backup Solution + + Copyright (C) 2009-2009 Free Software Foundation Europe e.V. + + The main author of Bacula is Kern Sibbald, with contributions from + many others, a complete list can be found in the file AUTHORS. + This program is Free Software; you can redistribute it and/or + modify it under the terms of version two of the GNU General Public + License as published by the Free Software Foundation and included + in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + Bacula® is a registered trademark of Kern Sibbald. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. +*/ +/* + * + * Program to test Ingres DB routines + * + * Stefan Reddig, February 2010 + * + * reusing code from 'bvfs_test.c' by + * Eric Bollengier, August 2009 + * + * + */ + +#include "bacula.h" +#include "cats/cats.h" +#include "cats/bvfs.h" +#include "findlib/find.h" + +/* Local variables */ +static B_DB *db; +static const char *file = "COPYRIGHT"; +static DBId_t fnid=0; +static const char *db_name = "bacula"; +static const char *db_user = "bacula"; +static const char *db_password = ""; +static const char *db_host = NULL; + +static void usage() +{ + fprintf(stderr, _( +PROG_COPYRIGHT +"\nVersion: %s (%s)\n" +" -d set debug level to \n" +" -dt print timestamp in debug output\n" +" -n specify the database name (default bacula)\n" +" -u specify database user name (default bacula)\n" +" -P specify database host (default NULL)\n" +" -w specify working directory\n" +" -j specify jobids\n" +" -p specify path\n" +" -f specify file\n" +" -l maximum tuple to fetch\n" +" -T truncate cache table before starting\n" +" -v verbose\n" +" -? print this message\n\n"), 2001, VERSION, BDATE); + exit(1); +} + + + +/* number of thread started */ + +int main (int argc, char *argv[]) +{ + int ch; + char *jobids = (char *)"1"; + char *path=NULL, *client=NULL; + uint64_t limit=0; + bool clean=false; + setlocale(LC_ALL, ""); + bindtextdomain("bacula", LOCALEDIR); + textdomain("bacula"); + init_stack_dump(); + + Dmsg0(0, "Starting ing_test tool\n"); + + my_name_is(argc, argv, "ing_test"); + init_msg(NULL, NULL); + + OSDependentInit(); + + while ((ch = getopt(argc, argv, "h:c:l:d:n:P:Su:vf:w:?j:p:f:T")) != -1) { + switch (ch) { + case 'd': /* debug level */ + if (*optarg == 't') { + dbg_timestamp = true; + } else { + debug_level = atoi(optarg); + if (debug_level <= 0) { + debug_level = 1; + } + } + break; + case 'l': + limit = str_to_int64(optarg); + break; + + case 'c': + client = optarg; + break; + + case 'h': + db_host = optarg; + break; + + case 'n': + db_name = optarg; + break; + + case 'w': + working_directory = optarg; + break; + + case 'u': + db_user = optarg; + break; + + case 'P': + db_password = optarg; + break; + + case 'v': + verbose++; + break; + + case 'p': + path = optarg; + break; + + case 'f': + file = optarg; + break; + + case 'j': + jobids = optarg; + break; + + case 'T': + clean = true; + break; + + case '?': + default: + usage(); + + } + } + argc -= optind; + argv += optind; + + if (argc != 0) { + Pmsg0(0, _("Wrong number of arguments: \n")); + usage(); + } + + if ((db=db_init_database(NULL, db_name, db_user, db_password, + db_host, 0, NULL, 0)) == NULL) { + Emsg0(M_ERROR_TERM, 0, _("Could not init Bacula database\n")); + } + Dmsg1(0, "db_type=%s\n", db_get_type()); + + if (!db_open_database(NULL, db)) { + Emsg0(M_ERROR_TERM, 0, db_strerror(db)); + } + Dmsg0(200, "Database opened\n"); + if (verbose) { + Pmsg2(000, _("Using Database: %s, User: %s\n"), db_name, db_user); + } + + Dmsg0(200, "DB-Statement: CREATE TABLE t1 ( c1 integer, c2 varchar(29))\n"); + if (!db_sql_query(db, "CREATE TABLE t1 ( c1 integer, c2 varchar(29))", NULL, NULL)) + { + Emsg0(M_ERROR_TERM, 0, _("CREATE-Stmt went wrong\n")); + } + + Dmsg0(200, "DB-Statement: INSERT INTO t1 VALUES (1, 'foo')\n"); + if (!db_sql_query(db, "INSERT INTO t1 VALUES (1, 'foo')", NULL, NULL)) + { + Emsg0(M_ERROR_TERM, 0, _("INSERT-Stmt went wrong\n")); + } + + Dmsg0(200, "DB-Statement: DROP TABLE t1\n"); + if (!db_sql_query(db, "DROP TABLE t1", NULL, NULL)) + { + Emsg0(M_ERROR_TERM, 0, _("DROP-Stmt went wrong\n")); + } + +/* + if (clean) { + Pmsg0(0, "Clean old table\n"); + db_sql_query(db, "DELETE FROM PathHierarchy", NULL, NULL); + db_sql_query(db, "UPDATE Job SET HasCache=0", NULL, NULL); + db_sql_query(db, "DELETE FROM PathVisibility", NULL, NULL); + } +*/ + db_close_database(NULL, db); + Dmsg0(200, "Database closed\n"); + + return 0; +}