]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/tools/ing_test.c
Tweak fix MySQL quoting again :-(
[bacula/bacula] / bacula / src / tools / ing_test.c
index d8b050574958b4083462e04525f231b3b5703d41..e5ed08c9843ef0a894880f94e37ec460c350473b 100644 (file)
@@ -6,7 +6,7 @@
    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
+   modify it under the terms of version three of the GNU Affero General Public
    License as published by the Free Software Foundation and included
    in the file LICENSE.
 
@@ -15,7 +15,7 @@
    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
+   You should have received a copy of the GNU Affero 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.
@@ -77,7 +77,7 @@ PROG_COPYRIGHT
  */
 static int test_handler(void *ctx, int num_fields, char **row)
 {
-   Dmsg2(200, "   Values are %d, %s\n", str_to_int64(row[0]), row[1]);
+   Pmsg2(0, "   Values are %d, %s\n", str_to_int64(row[0]), row[1]);
    return 0;
 }
 
@@ -86,7 +86,7 @@ static int test_handler(void *ctx, int num_fields, char **row)
  */
 static int string_handler(void *ctx, int num_fields, char **row)
 {
-   Dmsg1(200, "   Value is >>%s<<\n", row[0]);
+   Pmsg1(0, "   Value is >>%s<<\n", row[0]);
    return 0;
 }
 
@@ -199,75 +199,110 @@ int main (int argc, char *argv[])
    if (verbose) {
       Pmsg2(000, _("Using Database: %s, User: %s\n"), db_name, db_user);
    }
-   
-
-   /* simple CRUD test including create/drop table */
 
+   /*
+    * simple CRUD test including create/drop table
+    */
    Pmsg0(0, "\nsimple CRUD test...\n\n");
-
-   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: SELECT c1,c2 FROM t1 (should be 1, foo)\n");
-   if (!db_sql_query(db, "SELECT c1,c2 FROM t1", test_handler, NULL)) {
-      Emsg0(M_ERROR_TERM, 0, _("SELECT-Stmt went wrong\n"));
-   }
-
-   Dmsg0(200, "DB-Statement: UPDATE t1 SET c2='bar' WHERE c1=1\n");
-   if (!db_sql_query(db, "UPDATE t1 SET c2='bar' WHERE c1=1", NULL, NULL)) {
-      Emsg0(M_ERROR_TERM, 0, _("UPDATE-Stmt went wrong\n"));
-   }
-
-   Dmsg0(200, "DB-Statement: SELECT * FROM t1 (should be 1, bar)\n");
-   if (!db_sql_query(db, "SELECT * FROM t1", test_handler, NULL)) {
-      Emsg0(M_ERROR_TERM, 0, _("SELECT-Stmt went wrong\n"));
-   }
-
-   Dmsg0(200, "DB-Statement: DELETE FROM t1 WHERE c2 LIKE '\%r'\n");
-   if (!db_sql_query(db, "DELETE FROM t1 WHERE c2 LIKE '%r'", NULL, NULL)) {
-      Emsg0(M_ERROR_TERM, 0, _("DELETE-Stmt went wrong\n"));
-   }
-
-   Dmsg0(200, "DB-Statement: SELECT * FROM t1 (should be 0 rows)\n");
-   if (!db_sql_query(db, "SELECT * FROM t1", test_handler, NULL)) {
-      Emsg0(M_ERROR_TERM, 0, _("SELECT-Stmt went wrong\n"));
+   const char *stmt1[8] = {
+      "CREATE TABLE t1 ( c1 integer, c2 varchar(29))",
+      "INSERT INTO t1 VALUES (1, 'foo')",
+      "SELECT c1,c2 FROM t1",
+      "UPDATE t1 SET c2='bar' WHERE c1=1",
+      "SELECT * FROM t1",
+      "DELETE FROM t1 WHERE c2 LIKE '\%r'",
+      "SELECT * FROM t1",
+      "DROP TABLE t1"
+   };
+   int (*hndl1[8])(void*,int,char**) = {
+      NULL,
+      NULL,
+      test_handler,
+      NULL,
+      test_handler,
+      NULL,
+      test_handler,
+      NULL
+   };
+
+   for (int i=0; i<8; ++i) {
+      Pmsg1(0, "DB-Statement: %s\n",stmt1[i]);
+      if (!db_sql_query(db, stmt1[i], hndl1[i], NULL)) {
+         Emsg0(M_ERROR_TERM, 0, _("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"));
-   }
 
    /*
-    * simple SELECT test without tables
+    * simple SELECT tests without tables
     */
-    
-   Dmsg0(200, "DB-Statement: SELECT 'Test of simple SELECT!'\n");
-   if (!db_sql_query(db, "SELECT 'Test of simple SELECT!'", string_handler, NULL)) {
-      Emsg0(M_ERROR_TERM, 0, _("SELECT-Stmt went wrong\n"));
-   }
-
-   Dmsg0(200, "DB-Statement: SELECT 'Test of simple SELECT!' as Text\n");
-   if (!db_sql_query(db, "SELECT 'Test of simple SELECT!' as Text", string_handler, NULL)) {
-      Emsg0(M_ERROR_TERM, 0, _("SELECT-Stmt went wrong\n"));
+   Pmsg0(0, "\nsimple SELECT tests without tables...\n\n");
+   const char *stmt2[8] = {
+      "SELECT 'Test of simple SELECT!'",
+      "SELECT 'Test of simple SELECT!' as Text",
+      "SELECT VARCHAR(LENGTH('Test of simple SELECT!'))",
+      "SELECT DBMSINFO('_version')",
+      "SELECT 'This is a ''quoting'' test with single quotes'",
+      "SELECT 'This is a \"quoting\" test with double quotes'",
+      "SELECT null",
+      "SELECT ''"
+   };
+   int (*hndl2[8])(void*,int,char**) = {
+      string_handler,
+      string_handler,
+      string_handler,
+      string_handler,
+      string_handler,
+      string_handler,
+      string_handler,
+      string_handler
+   };
+
+   for (int i=0; i<8; ++i) {
+      Pmsg1(0, "DB-Statement: %s\n",stmt2[i]);
+      if (!db_sql_query(db, stmt2[i], hndl2[i], NULL)) {
+         Emsg0(M_ERROR_TERM, 0, _("Stmt went wrong\n"));
+      }
    }
 
-   Dmsg0(200, "DB-Statement: SELECT VARCHAR(LENGTH('Test of simple SELECT!'))\n");
-   if (!db_sql_query(db, "SELECT VARCHAR(LENGTH('Test of simple SELECT!'))", string_handler, NULL)) {
-      Emsg0(M_ERROR_TERM, 0, _("SELECT-Stmt went wrong\n"));
+   /*
+    * testing aggregates like avg, max, sum
+    */
+   Pmsg0(0, "\ntesting aggregates...\n\n");
+   const char *stmt[11] = {
+      "CREATE TABLE t1 (c1 integer, c2 varchar(29))",
+      "INSERT INTO t1 VALUES (1,'foo')",
+      "INSERT INTO t1 VALUES (2,'bar')",
+      "INSERT INTO t1 VALUES (3,'fun')",
+      "INSERT INTO t1 VALUES (4,'egg')",
+      "SELECT max(c1) from t1",
+      "SELECT sum(c1) from t1",
+      "INSERT INTO t1 VALUES (5,NULL)",
+      "SELECT count(*) from t1",
+      "SELECT count(c2) from t1",
+      "DROP TABLE t1"
+   };
+   int (*hndl[11])(void*,int,char**) = {
+      NULL,
+      NULL,
+      NULL,
+      NULL,
+      NULL,
+      string_handler,
+      string_handler,
+      NULL,
+      string_handler,
+      string_handler,
+      NULL
+   };
+
+   for (int i=0; i<11; ++i) {
+      Pmsg1(0, "DB-Statement: %s\n",stmt[i]);
+      if (!db_sql_query(db, stmt[i], hndl[i], NULL)) {
+         Emsg0(M_ERROR_TERM, 0, _("Stmt went wrong\n"));
+      }
    }
 
-   Dmsg0(200, "DB-Statement: SELECT DBMSINFO('_version')\n");
-   if (!db_sql_query(db, "SELECT DBMSINFO('_version')", string_handler, NULL)) {
-      Emsg0(M_ERROR_TERM, 0, _("SELECT-Stmt went wrong\n"));
-   }
 
    /* 
     * datatypes test