From 808eb460f7eb656b47062c47914b54e02f3f67ee Mon Sep 17 00:00:00 2001 From: prabatuty Date: Fri, 27 Apr 2007 14:53:48 +0000 Subject: [PATCH] Adding temporary test scripts to check sql engine --- tmptest/Makefile | 46 ++++++++++++++++++++++++++++++++++++++++++++++ tmptest/create.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ tmptest/del.c | 40 ++++++++++++++++++++++++++++++++++++++++ tmptest/select.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ tmptest/test.c | 38 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 218 insertions(+) create mode 100644 tmptest/Makefile create mode 100644 tmptest/create.c create mode 100644 tmptest/del.c create mode 100644 tmptest/select.c create mode 100644 tmptest/test.c diff --git a/tmptest/Makefile b/tmptest/Makefile new file mode 100644 index 00000000..6adb8ced --- /dev/null +++ b/tmptest/Makefile @@ -0,0 +1,46 @@ + +OSNAME = $(shell uname -s) +PlatForm=supported + +ifeq ($(OSNAME), SunOS) +CPlus = CC +CPlusFlags = -O2 -w -mt -xarch=v8 +SYSLIBS=-ldl -lnsl -lsocket -lposix4 +else +ifeq ($(OSNAME), Linux) +CPlus = g++ +CPlusFlags = -g +SYSLIBS= -rdynamic -lrt -lpthread -lcrypt +else +PlatForm=notsupported +all: + echo "CSQL is not supported on $(OSNAME) platform" +endif +endif + +INCL= -I$(CSQL_INSTALL_ROOT)/include -I../src/sql +LIBS= -L$(CSQL_INSTALL_ROOT)/lib -L.. -lcsql -lcsqlsql + +TARGETS = \ + test \ + create\ + del\ + select + + +ifeq ($(PlatForm), supported) +all: $(TARGETS) +endif + +test: test.c + $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) +del: del.c + $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) + +create: create.c + $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) +select: select.c + $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) +clean: + rm -f $(TARGETS) + diff --git a/tmptest/create.c b/tmptest/create.c new file mode 100644 index 00000000..8e5a14e8 --- /dev/null +++ b/tmptest/create.c @@ -0,0 +1,50 @@ +/*************************************************************************** + * Copyright (C) 2007 by www.databasecache.com * + * Contact: praba_tuty@databasecache.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * 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. * + * * + **************************************************************************/ +#include +int main() +{ + //connect to the database first + Connection conn; + DbRetVal rv = conn.open("praba", "manager"); + if (rv != OK) + { + printf("Error during connection %d\n", rv); + return -1; + } + + //get dbmgr to create table and index + DatabaseManager *dbMgr = conn.getDatabaseManager(); + if (dbMgr == NULL) { printf("Auth failed\n"); return -1;} + + //create table with two fields, f1 integer and f2 string + TableDef tabDef; + tabDef.addField("f1", typeInt, 0, NULL, true, true); + tabDef.addField("f2", typeInt); + rv = dbMgr->createTable("t1", tabDef); + if (rv != OK) { printf("Table creation failed\n"); return -1; } + printf("Table created\n"); + //Creating hash index on field f1 of table t1 + HashIndexInitInfo *idxInfo = new HashIndexInitInfo(); + strcpy(idxInfo->tableName, "t1"); + idxInfo->list.append("f1"); + idxInfo->indType = hashIndex; + rv = dbMgr->createIndex("indx1", idxInfo); + if (rv != OK) { printf("Index creation failed\n"); return -1; } + printf("Index created\n"); + + conn.close(); + return 0; +} diff --git a/tmptest/del.c b/tmptest/del.c new file mode 100644 index 00000000..6514b6bd --- /dev/null +++ b/tmptest/del.c @@ -0,0 +1,40 @@ +#include +#include +int main() +{ + DbRetVal rv = OK; + SqlConnection *con = new SqlConnection(); + con->connect("praba", "manager"); + SqlStatement *stmt = new SqlStatement(); + stmt->setConnection(con); + char statement[1024]; + strcpy(statement, "DELETE FROM t1 WHERE f1 >97"); + int rows =0; + rv = stmt->prepare(statement); + if (rv != OK) {delete stmt; delete con; return 1; } + int id1 =100, id2 = 100; + int icount=0; + void *tuple; + NanoTimer timer; + timer.start(); + con->beginTrans(); + stmt->execute(rows); + printf(" Rows returned %d\n", rows); + /*while(true) + { + tuple = (char*)stmt->fetch() ; + if (tuple == NULL) { break; } + printf("f1=%d f2=%d\n", id1, id2); + icount++; + }*/ + con->commit(); + timer.stop(); + + printf("Select %d %lld %lld %lld\n", icount, timer.min(), timer.max(), timer.avg()); + + + stmt->free(); + delete stmt; + delete con; + return 0; +} diff --git a/tmptest/select.c b/tmptest/select.c new file mode 100644 index 00000000..af2a8292 --- /dev/null +++ b/tmptest/select.c @@ -0,0 +1,44 @@ +#include +#include +int main() +{ + DbRetVal rv = OK; + SqlConnection *con = new SqlConnection(); + con->connect("praba", "manager"); + SqlStatement *stmt = new SqlStatement(); + stmt->setConnection(con); + char statement[1024]; + strcpy(statement, "SELECT * from t1 where f1 = 98 ;"); + int rows =0; + rv = stmt->prepare(statement); + if (rv != OK) {delete stmt; delete con; return 1; } + int id1 =100, id2 = 100; + int icount=0; + rv = stmt->bindField(1, &id1); + if (rv != OK) {delete stmt; delete con; return 2; } + rv = stmt->bindField(2, &id2); + if (rv != OK) {delete stmt; delete con; return 3; } + void *tuple; + NanoTimer timer; + timer.start(); + con->beginTrans(); + stmt->execute(rows); + printf("\n"); + while(true) + { + tuple = (char*)stmt->fetch() ; + if (tuple == NULL) { break; } + printf("f1=%d f2=%d\n", id1, id2); + icount++; + } + con->commit(); + timer.stop(); + + printf("Select %d %lld %lld %lld\n", icount, timer.min(), timer.max(), timer.avg()); + + + stmt->free(); + delete stmt; + delete con; + return 0; +} diff --git a/tmptest/test.c b/tmptest/test.c new file mode 100644 index 00000000..267ef15e --- /dev/null +++ b/tmptest/test.c @@ -0,0 +1,38 @@ +#include +#include +int main() +{ + DbRetVal rv = OK; + SqlConnection *con = new SqlConnection(); + con->connect("praba", "manager"); + SqlStatement *stmt = new SqlStatement(); + stmt->setConnection(con); + char statement[1024]; + //strcpy(statement, "INSERT INTO t1 (f1, f2) VALUES (100, 200);"); + strcpy(statement, "INSERT INTO t1 (f1, f2) VALUES (?, ?);"); + //strcpy(statement, "INSERT INTO t1 VALUES (100, 200);"); + //strcpy(statement, "INSERT INTO t1 "); + int rows =0; + rv = stmt->prepare(statement); + int id1 =100, id2 = 100; + stmt->bindParam(1, &id1); + stmt->bindParam(2, &id2); + if (rv != OK) {delete stmt; delete con; return -1; } + NanoTimer timer; + for (int i = 0 ; i < 100 ; i++) + { + timer.start(); + id1 = i; id2 = i; + con->beginTrans(); + stmt->execute(rows); + con->commit(); + timer.stop(); + } + printf("Insert %lld %lld %lld\n", timer.min(), timer.max(), timer.avg()); + + + stmt->free(); + delete stmt; + delete con; + return 0; +} -- 2.11.4.GIT