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 two of the GNU 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 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/bvfs.h"
42 #include "findlib/find.h"
46 static const char *file = "COPYRIGHT";
47 //static DBId_t fnid=0;
48 static const char *db_name = "bacula";
49 static const char *db_user = "bacula";
50 static const char *db_password = "";
51 static const char *db_host = NULL;
57 "\nVersion: %s (%s)\n"
58 " -d <nn> set debug level to <nn>\n"
59 " -dt print timestamp in debug output\n"
60 " -n <name> specify the database name (default bacula)\n"
61 " -u <user> specify database user name (default bacula)\n"
62 " -P <password specify database password (default none)\n"
63 " -h <host> specify database host (default NULL)\n"
64 " -w <working> specify working directory\n"
65 " -j <jobids> specify jobids\n"
66 " -p <path> specify path\n"
67 " -f <file> specify file\n"
68 " -l <limit> maximum tuple to fetch\n"
69 " -T truncate cache table before starting\n"
71 " -? print this message\n\n"), 2001, VERSION, BDATE);
76 * simple handler for debug output of CRUD example
78 static int test_handler(void *ctx, int num_fields, char **row)
80 Dmsg2(200, " Values are %d, %s\n", str_to_int64(row[0]), row[1]);
85 * string handler for debug output of simple SELECT tests
87 static int string_handler(void *ctx, int num_fields, char **row)
89 Dmsg1(200, " Value is >>%s<<\n", row[0]);
94 /* number of thread started */
96 int main (int argc, char *argv[])
99 char *jobids = (char *)"1";
100 char *path=NULL, *client=NULL;
103 setlocale(LC_ALL, "");
104 bindtextdomain("bacula", LOCALEDIR);
105 textdomain("bacula");
108 Dmsg0(0, "Starting ing_test tool\n");
110 my_name_is(argc, argv, "ing_test");
111 init_msg(NULL, NULL);
115 while ((ch = getopt(argc, argv, "h:c:l:d:n:P:Su:vf:w:?j:p:f:T")) != -1) {
117 case 'd': /* debug level */
118 if (*optarg == 't') {
119 dbg_timestamp = true;
121 debug_level = atoi(optarg);
122 if (debug_level <= 0) {
128 limit = str_to_int64(optarg);
144 working_directory = optarg;
152 db_password = optarg;
185 Pmsg0(0, _("Wrong number of arguments: \n"));
189 if ((db=db_init_database(NULL, db_name, db_user, db_password,
190 db_host, 0, NULL, 0)) == NULL) {
191 Emsg0(M_ERROR_TERM, 0, _("Could not init Bacula database\n"));
193 Dmsg1(0, "db_type=%s\n", db_get_type());
195 if (!db_open_database(NULL, db)) {
196 Emsg0(M_ERROR_TERM, 0, db_strerror(db));
198 Dmsg0(200, "Database opened\n");
200 Pmsg2(000, _("Using Database: %s, User: %s\n"), db_name, db_user);
204 /* simple CRUD test including create/drop table */
206 Pmsg0(0, "\nsimple CRUD test...\n\n");
208 Dmsg0(200, "DB-Statement: CREATE TABLE t1 ( c1 integer, c2 varchar(29))\n");
209 if (!db_sql_query(db, "CREATE TABLE t1 ( c1 integer, c2 varchar(29))", NULL, NULL)) {
210 Emsg0(M_ERROR_TERM, 0, _("CREATE-Stmt went wrong\n"));
213 Dmsg0(200, "DB-Statement: INSERT INTO t1 VALUES (1, 'foo')\n");
214 if (!db_sql_query(db, "INSERT INTO t1 VALUES (1, 'foo')", NULL, NULL)) {
215 Emsg0(M_ERROR_TERM, 0, _("INSERT-Stmt went wrong\n"));
218 Dmsg0(200, "DB-Statement: SELECT c1,c2 FROM t1 (should be 1, foo)\n");
219 if (!db_sql_query(db, "SELECT c1,c2 FROM t1", test_handler, NULL)) {
220 Emsg0(M_ERROR_TERM, 0, _("SELECT-Stmt went wrong\n"));
223 Dmsg0(200, "DB-Statement: UPDATE t1 SET c2='bar' WHERE c1=1\n");
224 if (!db_sql_query(db, "UPDATE t1 SET c2='bar' WHERE c1=1", NULL, NULL)) {
225 Emsg0(M_ERROR_TERM, 0, _("UPDATE-Stmt went wrong\n"));
228 Dmsg0(200, "DB-Statement: SELECT * FROM t1 (should be 1, bar)\n");
229 if (!db_sql_query(db, "SELECT * FROM t1", test_handler, NULL)) {
230 Emsg0(M_ERROR_TERM, 0, _("SELECT-Stmt went wrong\n"));
233 Dmsg0(200, "DB-Statement: DELETE FROM t1 WHERE c2 LIKE '\%r'\n");
234 if (!db_sql_query(db, "DELETE FROM t1 WHERE c2 LIKE '%r'", NULL, NULL)) {
235 Emsg0(M_ERROR_TERM, 0, _("DELETE-Stmt went wrong\n"));
238 Dmsg0(200, "DB-Statement: SELECT * FROM t1 (should be 0 rows)\n");
239 if (!db_sql_query(db, "SELECT * FROM t1", test_handler, NULL)) {
240 Emsg0(M_ERROR_TERM, 0, _("SELECT-Stmt went wrong\n"));
243 Dmsg0(200, "DB-Statement: DROP TABLE t1\n");
244 if (!db_sql_query(db, "DROP TABLE t1", NULL, NULL)) {
245 Emsg0(M_ERROR_TERM, 0, _("DROP-Stmt went wrong\n"));
249 * simple SELECT test without tables
252 Dmsg0(200, "DB-Statement: SELECT 'Test of simple SELECT!'\n");
253 if (!db_sql_query(db, "SELECT 'Test of simple SELECT!'", string_handler, NULL)) {
254 Emsg0(M_ERROR_TERM, 0, _("SELECT-Stmt went wrong\n"));
257 Dmsg0(200, "DB-Statement: SELECT 'Test of simple SELECT!' as Text\n");
258 if (!db_sql_query(db, "SELECT 'Test of simple SELECT!' as Text", string_handler, NULL)) {
259 Emsg0(M_ERROR_TERM, 0, _("SELECT-Stmt went wrong\n"));
262 Dmsg0(200, "DB-Statement: SELECT VARCHAR(LENGTH('Test of simple SELECT!'))\n");
263 if (!db_sql_query(db, "SELECT VARCHAR(LENGTH('Test of simple SELECT!'))", string_handler, NULL)) {
264 Emsg0(M_ERROR_TERM, 0, _("SELECT-Stmt went wrong\n"));
267 Dmsg0(200, "DB-Statement: SELECT DBMSINFO('_version')\n");
268 if (!db_sql_query(db, "SELECT DBMSINFO('_version')", string_handler, NULL)) {
269 Emsg0(M_ERROR_TERM, 0, _("SELECT-Stmt went wrong\n"));
275 Pmsg0(0, "\ndatatypes test... (TODO)\n\n");
278 Dmsg0(200, "DB-Statement: CREATE TABLE for datatypes\n");
279 if (!db_sql_query(db, "CREATE TABLE t2 ("
283 /* some more datatypes... "c4 ," */
285 Emsg0(M_ERROR_TERM, 0, _("CREATE-Stmt went wrong\n"));
288 Dmsg0(200, "DB-Statement: DROP TABLE for datatypes\n");
289 if (!db_sql_query(db, "DROP TABLE t2", NULL, NULL)) {
290 Emsg0(M_ERROR_TERM, 0, _("DROP-Stmt went wrong\n"));
294 db_close_database(NULL, db);
295 Dmsg0(200, "Database closed\n");