/* * Copyright (c) 1995 Gunther Schadow. All rights reserved. * * 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. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "Test.h" char *zahl[] = { "null", "eins", "zwei", "drei", "vier", "fuenf", "sechs", "sieben", "acht", "neun", "zehn" }; void show(Test &t); main() { Test::use("scott/tiger"); Test::owner("scott"); cout << endl << "DROPPING THE TABLE" << endl; Test::drop(); cout << endl << "AND CREATING IT AGAIN" << endl; Test::create(); Test t; cout << endl << "SHOULD BE EMPTY NOW" << endl; show(t); cout << endl << "INSERTING DATA" << endl; cout << endl << "BLA\tFOO\tBAR" << endl << "--------" "--------" "--------" << endl; for(int i = 0; i <= 10; i++) { t.set_bla(i); if(i % 2) { t.set_foo(zahl[i]); t.unset_bar(); } else { t.unset_foo(); t.set_bar(zahl[i]); } cout << t.get_bla() << "\t"; if(t.foo_is_null()) cout << "NULL\t"; else cout << t.get_foo() << "\t"; if(t.bar_is_null()) cout << "NULL\t"; else cout << t.get_bar() << "\t"; cout << endl; t.insert(); } Test::database()->commit(); cout << endl << "THE RESULT OF INSERTION" << endl; show(t); cout << endl << "UPDATING SOME ROWS (WHERE BAR IS NULL)" << endl; t.set_foo("some"); t.set_bar("other"); t.update("WHERE BAR IS NULL"); Test::database()->commit(); cout << endl << "THE RESULT OF UPDATE" << endl; show(t); cout << endl << "UPDATING BY ROWID" << endl; int num = 0; for(result r = t.retrieve("WHERE FOO IS NULL"); r == SUCCESS; r = t.next()) { t.set_foo(zahl[num++]); t.update(); } Test::database()->commit(); cout << endl << "THE RESULT OF UPDATE" << endl; show(t); cout << endl << "DELETING SOME ROWS" << endl; t.remove("WHERE FOO = 'some'"); Test::database()->commit(); cout << endl << "THE RESULT OF DELETION" << endl; show(t); cout << endl << "DELETING BY ROWID" << endl; for(r = t.retrieve("WHERE FOO = 'drei'"); r == SUCCESS; r = t.next()) t.remove(); Test::database()->commit(); cout << endl << "THE RESULT OF DELETION" << endl; show(t); cout << endl << "THE END" << endl; } void show(Test &t) { cout << endl << "BLA\tFOO\tBAR" << endl << "--------" "--------" "--------" << endl; for(result r = t.retrieve(); r == SUCCESS; r = t.next()) { cout << t.get_bla() << "\t"; if(t.foo_is_null()) cout << "NULL\t"; else cout << t.get_foo() << "\t"; if(t.bar_is_null()) cout << "NULL\t"; else cout << t.get_bar() << "\t"; cout << endl; } cout << endl; }