2 Bacula® - The Network Backup Solution
4 Copyright (C) 2009-2010 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version three of the GNU Affero General Public
10 License as published by the Free Software Foundation and included
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU Affero General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula® is a registered trademark of Kern Sibbald.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
30 * Program to test Ingres DB routines
32 * Stefan Reddig, February 2010
35 * Eric Bollengier, August 2009
40 #include "cats/cats.h"
41 #include "cats/sql_glue.h"
45 static const char *file = "COPYRIGHT";
46 //static DBId_t fnid=0;
47 static const char *db_name = "bacula";
48 static const char *db_user = "bacula";
49 static const char *db_password = "";
50 static const char *db_host = NULL;
56 "\nVersion: %s (%s)\n"
57 " -d <nn> set debug level to <nn>\n"
58 " -dt print timestamp in debug output\n"
59 " -n <name> specify the database name (default bacula)\n"
60 " -u <user> specify database user name (default bacula)\n"
61 " -P <password specify database password (default none)\n"
62 " -h <host> specify database host (default NULL)\n"
63 " -w <working> specify working directory\n"
64 " -j <jobids> specify jobids\n"
65 " -p <path> specify path\n"
66 " -f <file> specify file\n"
67 " -l <limit> maximum tuple to fetch\n"
68 " -T truncate cache table before starting\n"
70 " -? print this message\n\n"), 2001, VERSION, BDATE);
75 * simple handler for debug output of CRUD example
77 static int test_handler(void *ctx, int num_fields, char **row)
79 Pmsg2(0, " Values are %d, %s\n", str_to_int64(row[0]), row[1]);
84 * string handler for debug output of simple SELECT tests
86 static int string_handler(void *ctx, int num_fields, char **row)
88 Pmsg1(0, " Value is >>%s<<\n", row[0]);
93 /* number of thread started */
95 int main (int argc, char *argv[])
98 char *jobids = (char *)"1";
99 char *path=NULL, *client=NULL;
102 setlocale(LC_ALL, "");
103 bindtextdomain("bacula", LOCALEDIR);
104 textdomain("bacula");
107 Dmsg0(0, "Starting ing_test tool\n");
109 my_name_is(argc, argv, "ing_test");
110 init_msg(NULL, NULL);
114 while ((ch = getopt(argc, argv, "h:c:l:d:n:P:Su:vf:w:?j:p:f:T")) != -1) {
116 case 'd': /* debug level */
117 if (*optarg == 't') {
118 dbg_timestamp = true;
120 debug_level = atoi(optarg);
121 if (debug_level <= 0) {
127 limit = str_to_int64(optarg);
143 working_directory = optarg;
151 db_password = optarg;
184 Pmsg0(0, _("Wrong number of arguments: \n"));
188 if ((db = db_init_database(NULL, NULL, db_name, db_user, db_password,
189 db_host, 0, NULL, false, false)) == NULL) {
190 Emsg0(M_ERROR_TERM, 0, _("Could not init Bacula database\n"));
192 Dmsg1(0, "db_type=%s\n", db_get_type(db));
194 if (!db_open_database(NULL, db)) {
195 Emsg0(M_ERROR_TERM, 0, db_strerror(db));
197 Dmsg0(200, "Database opened\n");
199 Pmsg2(000, _("Using Database: %s, User: %s\n"), db_name, db_user);
203 * simple CRUD test including create/drop table
205 Pmsg0(0, "\nsimple CRUD test...\n\n");
206 const char *stmt1[8] = {
207 "CREATE TABLE t1 ( c1 integer, c2 varchar(29))",
208 "INSERT INTO t1 VALUES (1, 'foo')",
209 "SELECT c1,c2 FROM t1",
210 "UPDATE t1 SET c2='bar' WHERE c1=1",
212 "DELETE FROM t1 WHERE c2 LIKE '\%r'",
216 int (*hndl1[8])(void*,int,char**) = {
227 for (int i=0; i<8; ++i) {
228 Pmsg1(0, "DB-Statement: %s\n",stmt1[i]);
229 if (!db_sql_query(db, stmt1[i], hndl1[i], NULL)) {
230 Emsg0(M_ERROR_TERM, 0, _("Stmt went wrong\n"));
236 * simple SELECT tests without tables
238 Pmsg0(0, "\nsimple SELECT tests without tables...\n\n");
239 const char *stmt2[8] = {
240 "SELECT 'Test of simple SELECT!'",
241 "SELECT 'Test of simple SELECT!' as Text",
242 "SELECT VARCHAR(LENGTH('Test of simple SELECT!'))",
243 "SELECT DBMSINFO('_version')",
244 "SELECT 'This is a ''quoting'' test with single quotes'",
245 "SELECT 'This is a \"quoting\" test with double quotes'",
249 int (*hndl2[8])(void*,int,char**) = {
260 for (int i=0; i<8; ++i) {
261 Pmsg1(0, "DB-Statement: %s\n",stmt2[i]);
262 if (!db_sql_query(db, stmt2[i], hndl2[i], NULL)) {
263 Emsg0(M_ERROR_TERM, 0, _("Stmt went wrong\n"));
268 * testing aggregates like avg, max, sum
270 Pmsg0(0, "\ntesting aggregates...\n\n");
271 const char *stmt[11] = {
272 "CREATE TABLE t1 (c1 integer, c2 varchar(29))",
273 "INSERT INTO t1 VALUES (1,'foo')",
274 "INSERT INTO t1 VALUES (2,'bar')",
275 "INSERT INTO t1 VALUES (3,'fun')",
276 "INSERT INTO t1 VALUES (4,'egg')",
277 "SELECT max(c1) from t1",
278 "SELECT sum(c1) from t1",
279 "INSERT INTO t1 VALUES (5,NULL)",
280 "SELECT count(*) from t1",
281 "SELECT count(c2) from t1",
284 int (*hndl[11])(void*,int,char**) = {
298 for (int i=0; i<11; ++i) {
299 Pmsg1(0, "DB-Statement: %s\n",stmt[i]);
300 if (!db_sql_query(db, stmt[i], hndl[i], NULL)) {
301 Emsg0(M_ERROR_TERM, 0, _("Stmt went wrong\n"));
309 Pmsg0(0, "\ndatatypes test... (TODO)\n\n");
312 Dmsg0(200, "DB-Statement: CREATE TABLE for datatypes\n");
313 if (!db_sql_query(db, "CREATE TABLE t2 ("
317 /* some more datatypes... "c4 ," */
319 Emsg0(M_ERROR_TERM, 0, _("CREATE-Stmt went wrong\n"));
322 Dmsg0(200, "DB-Statement: DROP TABLE for datatypes\n");
323 if (!db_sql_query(db, "DROP TABLE t2", NULL, NULL)) {
324 Emsg0(M_ERROR_TERM, 0, _("DROP-Stmt went wrong\n"));
328 db_close_database(NULL, db);
329 Dmsg0(200, "Database closed\n");