2 Bacula® - The Network Backup Solution
4 Copyright (C) 2009-2014 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from many
7 others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 Bacula® is a registered trademark of Kern Sibbald.
18 * Program to test Ingres DB routines
20 * Stefan Reddig, February 2010
23 * Eric Bollengier, August 2009
29 #include "cats/cats.h"
30 #include "cats/sql_glue.h"
34 static const char *file = "COPYRIGHT";
35 //static DBId_t fnid=0;
36 static const char *db_name = "bacula";
37 static const char *db_user = "bacula";
38 static const char *db_password = "";
39 static const char *db_host = NULL;
45 "\nVersion: %s (%s)\n"
46 " -d <nn> set debug level to <nn>\n"
47 " -dt print timestamp in debug output\n"
48 " -n <name> specify the database name (default bacula)\n"
49 " -u <user> specify database user name (default bacula)\n"
50 " -P <password specify database password (default none)\n"
51 " -h <host> specify database host (default NULL)\n"
52 " -w <working> specify working directory\n"
53 " -j <jobids> specify jobids\n"
54 " -p <path> specify path\n"
55 " -f <file> specify file\n"
56 " -l <limit> maximum tuple to fetch\n"
57 " -T truncate cache table before starting\n"
59 " -? print this message\n\n"), 2001, VERSION, BDATE);
64 * simple handler for debug output of CRUD example
66 static int test_handler(void *ctx, int num_fields, char **row)
68 Pmsg2(0, " Values are %d, %s\n", str_to_int64(row[0]), row[1]);
73 * string handler for debug output of simple SELECT tests
75 static int string_handler(void *ctx, int num_fields, char **row)
77 Pmsg1(0, " Value is >>%s<<\n", row[0]);
82 /* number of thread started */
84 int main (int argc, char *argv[])
87 char *jobids = (char *)"1";
88 char *path=NULL, *client=NULL;
91 setlocale(LC_ALL, "");
92 bindtextdomain("bacula", LOCALEDIR);
96 Dmsg0(0, "Starting ing_test tool\n");
98 my_name_is(argc, argv, "ing_test");
103 while ((ch = getopt(argc, argv, "h:c:l:d:n:P:Su:vf:w:?j:p:f:T")) != -1) {
105 case 'd': /* debug level */
106 if (*optarg == 't') {
107 dbg_timestamp = true;
109 debug_level = atoi(optarg);
110 if (debug_level <= 0) {
116 limit = str_to_int64(optarg);
132 working_directory = optarg;
140 db_password = optarg;
173 Pmsg0(0, _("Wrong number of arguments: \n"));
177 if ((db = db_init_database(NULL, NULL, db_name, db_user, db_password,
178 db_host, 0, NULL, false, false)) == NULL) {
179 Emsg0(M_ERROR_TERM, 0, _("Could not init Bacula database\n"));
181 Dmsg1(0, "db_type=%s\n", db_get_type(db));
183 if (!db_open_database(NULL, db)) {
184 Emsg0(M_ERROR_TERM, 0, db_strerror(db));
186 Dmsg0(200, "Database opened\n");
188 Pmsg2(000, _("Using Database: %s, User: %s\n"), db_name, db_user);
192 * simple CRUD test including create/drop table
194 Pmsg0(0, "\nsimple CRUD test...\n\n");
195 const char *stmt1[8] = {
196 "CREATE TABLE t1 ( c1 integer, c2 varchar(29))",
197 "INSERT INTO t1 VALUES (1, 'foo')",
198 "SELECT c1,c2 FROM t1",
199 "UPDATE t1 SET c2='bar' WHERE c1=1",
201 "DELETE FROM t1 WHERE c2 LIKE '\%r'",
205 int (*hndl1[8])(void*,int,char**) = {
216 for (int i=0; i<8; ++i) {
217 Pmsg1(0, "DB-Statement: %s\n",stmt1[i]);
218 if (!db_sql_query(db, stmt1[i], hndl1[i], NULL)) {
219 Emsg0(M_ERROR_TERM, 0, _("Stmt went wrong\n"));
225 * simple SELECT tests without tables
227 Pmsg0(0, "\nsimple SELECT tests without tables...\n\n");
228 const char *stmt2[8] = {
229 "SELECT 'Test of simple SELECT!'",
230 "SELECT 'Test of simple SELECT!' as Text",
231 "SELECT VARCHAR(LENGTH('Test of simple SELECT!'))",
232 "SELECT DBMSINFO('_version')",
233 "SELECT 'This is a ''quoting'' test with single quotes'",
234 "SELECT 'This is a \"quoting\" test with double quotes'",
238 int (*hndl2[8])(void*,int,char**) = {
249 for (int i=0; i<8; ++i) {
250 Pmsg1(0, "DB-Statement: %s\n",stmt2[i]);
251 if (!db_sql_query(db, stmt2[i], hndl2[i], NULL)) {
252 Emsg0(M_ERROR_TERM, 0, _("Stmt went wrong\n"));
257 * testing aggregates like avg, max, sum
259 Pmsg0(0, "\ntesting aggregates...\n\n");
260 const char *stmt[11] = {
261 "CREATE TABLE t1 (c1 integer, c2 varchar(29))",
262 "INSERT INTO t1 VALUES (1,'foo')",
263 "INSERT INTO t1 VALUES (2,'bar')",
264 "INSERT INTO t1 VALUES (3,'fun')",
265 "INSERT INTO t1 VALUES (4,'egg')",
266 "SELECT max(c1) from t1",
267 "SELECT sum(c1) from t1",
268 "INSERT INTO t1 VALUES (5,NULL)",
269 "SELECT count(*) from t1",
270 "SELECT count(c2) from t1",
273 int (*hndl[11])(void*,int,char**) = {
287 for (int i=0; i<11; ++i) {
288 Pmsg1(0, "DB-Statement: %s\n",stmt[i]);
289 if (!db_sql_query(db, stmt[i], hndl[i], NULL)) {
290 Emsg0(M_ERROR_TERM, 0, _("Stmt went wrong\n"));
298 Pmsg0(0, "\ndatatypes test... (TODO)\n\n");
301 Dmsg0(200, "DB-Statement: CREATE TABLE for datatypes\n");
302 if (!db_sql_query(db, "CREATE TABLE t2 ("
306 /* some more datatypes... "c4 ," */
308 Emsg0(M_ERROR_TERM, 0, _("CREATE-Stmt went wrong\n"));
311 Dmsg0(200, "DB-Statement: DROP TABLE for datatypes\n");
312 if (!db_sql_query(db, "DROP TABLE t2", NULL, NULL)) {
313 Emsg0(M_ERROR_TERM, 0, _("DROP-Stmt went wrong\n"));
317 db_close_database(NULL, db);
318 Dmsg0(200, "Database closed\n");
323 int main (int argc, char *argv[])