summaryrefslogtreecommitdiffstats
path: root/kexi/tests/parser/main.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
commit8362bf63dea22bbf6736609b0f49c152f975eb63 (patch)
tree0eea3928e39e50fae91d4e68b21b1e6cbae25604 /kexi/tests/parser/main.cpp
downloadkoffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz
koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kexi/tests/parser/main.cpp')
-rw-r--r--kexi/tests/parser/main.cpp103
1 files changed, 103 insertions, 0 deletions
diff --git a/kexi/tests/parser/main.cpp b/kexi/tests/parser/main.cpp
new file mode 100644
index 000000000..f6ee57421
--- /dev/null
+++ b/kexi/tests/parser/main.cpp
@@ -0,0 +1,103 @@
+#include <iostream>
+#include <string>
+
+#include <qfileinfo.h>
+
+#include <kdebug.h>
+#include <kinstance.h>
+
+#include <kexidb/drivermanager.h>
+#include <kexidb/driver.h>
+#include <kexidb/connection.h>
+#include <kexidb/cursor.h>
+#include <kexidb/parser/parser.h>
+
+using namespace std;
+QCString prgname;
+
+int main(int argc, char **argv)
+{
+ kdDebug() << "main()" << endl;
+ QFileInfo info=QFileInfo(argv[0]);
+ prgname = info.baseName().latin1();
+ KInstance instance( prgname );
+ if (argc<2) {
+ return 1;
+ }
+ QCString drv_name(argv[1]);
+ QCString db_name = QString(argv[2]).lower().latin1();
+
+ KexiDB::DriverManager manager; // = KexiDB::DriverManager::self();
+ QStringList names = manager.driverNames();
+ kdDebug() << "DRIVERS: " << endl;
+ for (QStringList::ConstIterator it = names.constBegin(); it != names.constEnd() ; ++it)
+ kdDebug() << *it << endl;
+ if (manager.error()) {
+ kdDebug() << manager.errorMsg() << endl;
+ return 1;
+ }
+
+ //get driver
+ KexiDB::Driver *driver = manager.driver(drv_name);
+ if (!driver || manager.error()) {
+ kdDebug() << manager.errorMsg() << endl;
+ return 1;
+ }
+
+ //connection data that can be later reused
+ KexiDB::ConnectionData conn_data;
+ conn_data.setFileName(db_name);
+
+ KexiDB::Connection *conn = driver->createConnection(conn_data);
+ if (!conn || driver->error()) {
+ kdDebug() << "error: " << driver->errorMsg() << endl;
+ return 1;
+ }
+ if (!conn->connect()) {
+ kdDebug() << "error: " << conn->errorMsg() << endl;
+ return 1;
+ }
+ if (!conn->useDatabase( db_name )) {
+ kdDebug() << "error: " << conn->errorMsg() << endl;
+ return 1;
+ }
+
+ KexiDB::Parser *parser = new KexiDB::Parser(conn);
+
+ std::string cmd;
+ while(cmd != "quit")
+ {
+ std::cout << "SQL> ";
+ getline(std::cin, cmd);
+ parser->parse(cmd.c_str());
+ switch(parser->operation())
+ {
+ case KexiDB::Parser::OP_Error:
+ kdDebug() << "***********************" << endl;
+ kdDebug() << "* error *" << endl;
+ kdDebug() << "***********************" << endl;
+ break;
+ case KexiDB::Parser::OP_CreateTable:
+ {
+ kdDebug() << "Schema of table: " << parser->table()->name() << endl;
+ parser->table()->debug();
+ break;
+ }
+ case KexiDB::Parser::OP_Select:
+ {
+ kdDebug() << "Select statement: " << endl;
+ KexiDB::QuerySchema *q = parser->query();
+ q->debug();
+ delete q;
+ break;
+ }
+ default:
+ kdDebug() << "main(): not implemented in main.cpp" << endl;
+
+
+ }
+ parser->clear();
+ }
+ return 0;
+}
+