sptk



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: step3Query.eof in sptk database example



For some reason, ODBC driver reports that the table is empty, or reports an
error in catch block. I can try this with MS Access when I get on WIndows
machine, that doesn't happen before Monday.

2007/2/8, UN PEP <infounpep@yahoo.com>:

All the messages that was tested in fl_message are shown.
  Only the message inside " while (step3Query.eof() != true ) {   " is not
shown.
  It means it cannot go into that loop.
  what is the problem in checking eof()?


Alexey Parshin <alexeyp@gmail.com> wrote:
  Oh, then you have to modify the catch block to use fl_message instead of
printf:

fl_message( e.what() );

2007/2/8, UN PEP :
>
> i did not use any visual c++.
> I used dev c++.
> and i add only the code below in my FLTK project.(sptk and sqllite
> library is linked in fltk project)
> see below coding and if you can suggest that where should i modify,
> please let me know.
>
>
> Alexey Parshin wrote:
> I suggest you modify settings of Visual C++. You have to change
> SUBSYSTEM=WINDOWS to SUBSYSTEM=CONSOLE.
>
> 2007/2/8, UN PEP :
> >
> > how to do?
> > give detail instruction.
> >
> > Alexey Parshin wrote:
> > Well, you have to start using the console window, or modify catch
block
> > to
> > show the error message.
> >
> > 2007/2/8, UN PEP :
> > >
> > > i ran it in dev c++ debug mode.
> > > and i did not see any message box.
> > > i did not use console window.
> > >
> > > Alexey Parshin wrote:
> > > Do you see any messages in the console window, like "Openning the
> > > database"
> > > ?
> > >
> > > 2007/2/8, UN PEP :
> > > >
> > > > Of course. it has several data.
> > > > no message shown.
> > > > i did run it in both debug mode and normal console but nothing has
> > > > shown.
> > > >
> > > > Alexey Parshin wrote:
> > > > UN PEP,
> > > >
> > > > 1) Does this table have any records inside?
> > > > 2) Do you have this message in a window "End of database" ?
> > > > 3) Do you run this program in debug mode (so you may have a
console
> > > > window)
> > > > ?
> > > >
> > > > 2007/2/8, UN PEP :
> > > > >
> > > > > Hi
> > > > > I'm trying to read the data from MS Access database from the
SPTK
> > > > > coding.
> > > > > I used ODBC to link with database and application.And I followed
> the
> > > > > odbc example program in sptk.
> > > > > But when i run my program, it doesn't work in checking end of
file
> > > part
> > > > > and i doesn't go into the loop. It also doesn't show any error
> > > > message.Idon't know why and if anyone has an idea how to correct
it,
> > > > please share
> > > > > with me.
> > > > > I posted my coding below for reference.
> > > > > Thank you.
> > > > > =============================================================
> > > > > #ifdef __BORLANDC__
> > > > > #include
> > > > > #pragma hdrstop
> > > > > #endif
> > > > > #include
> > > > > #include
> > > > > #include
> > > > > #include "ui.h"
> > > > > #include "scenwin.h"
> > > > > //#include
> > > > > #include
> > > > > #include
> > > > > #include
> > > > > using namespace std;
> > > > > using namespace sptk;
> > > > > int testTransactions(CDatabase &db,string tableName,bool
rollback)
> {
> > > > > try {
> > > > > // CQuery step5Query(&db,"DELETE FROM "+tableName);
> > > > > CQuery step6Query(&db,"SELECT count(*) FROM "+tableName);
> > > > > cout << "\n Begining the transaction ..";
> > > > > db.beginTransaction();
> > > > > // cout << "\n Deleting everything from the temp table ..";
> > > > > //step5Query.exec();
> > > > > step6Query.open();
> > > > > int counter = step6Query[0].asInteger();
> > > > > step6Query.close();
> > > > > fl_message("\n The temp table now has %d records..",
> > > > > counter );
> > > > > if (rollback) {
> > > > > cout << "\n Rolling back the transaction ..";
> > > > > db.rollbackTransaction();
> > > > > } else {
> > > > > cout << "\n Commiting the transaction ..";
> > > > > db.commitTransaction();
> > > > > }
> > > > > step6Query.open();
> > > > > counter = step6Query[0].asInteger();
> > > > > step6Query.close();
> > > > > cout << "\n The temp table now has " << counter << "
> > > > > records..";
> > > > > } catch (exception& e) {
> > > > > cout << "Error: " << e.what() << endl;
> > > > > }
> > > > > return true;
> > > > > }
> > > > > //int dbConnectmonitor() {
> > > > > void dbConnectmonitor() {
> > > > > // If you want to test the database abilities of the data
controls
> > > > > // you have to setup the ODBC database connection.
> > > > > // Typical connect string is something like:
> > > > > "DSN=odbc_demo;UID=user;PWD=password".
> > > > > // If UID or PWD are omitted they are read from the datasource
> > > > > settings.
> > > > > string cResult;
> > > > > string tableName;
> > > > > string isTemp;
> > > > > string name;
> > > > > string position;
> > > > >
> > > > > CODBCDatabase db("DSN=odbc_demo");
> > > > > CFileLog logFile("odbc_test.log");
> > > > > //fl_message("Db connect monitor");
> > > > > db.logFile(&logFile);
> > > > > logFile.reset();
> > > > > try {
> > > > > cout << "Openning the database.. ";
> > > > > db.open();
> > > > > cout << "Ok.\nDriver description: " << db.driverDescription() <<
> > > > > endl;
> > > > > CDbObjectType objectTypes[] = { DOT_TABLES, DOT_VIEWS,
> > > > > DOT_PROCEDURES };
> > > > > string objectTypeNames[] = { "tables", "views", "stored
> > > > > procedures"};
> > > > > for (unsigned i = 0; i < 3; i++) {
> > > > > CStrings objectList;
> > > > > db.objectList(objectTypes[i],objectList);
> > > > > cout << "-------------------------------------------------" <<
> > > > > endl;
> > > > > cout << "First 10 " << objectTypeNames[i] << " in the
> > > > > database:" << endl;
> > > > > for (unsigned i = 0; i < objectList.size() && i < 10; i++)
> > > > > cout << " " << objectList[i] << endl;
> > > > > }
> > > > > cout << "-------------------------------------------------" <<
> > > > > endl;
> > > > > // Defining the queries
> > > > > //strcpy(tableName,"airH");
> > > > > tableName = "airH";
> > > > > //strcpy(isTemp,"TEMP");
> > > > > isTemp ="TEMP";
> > > > >
> > > > > if (db.driverDescription() == "SPTK database") {
> > > > > tableName = "##airH";
> > > > > isTemp = "";
> > > > > /*strcpy(tableName,"airH");
> > > > > strcpy(isTemp,"");*/
> > > > > }
> > > > > // CQuery step1Query(&db,"CREATE "+isTemp+" TABLE
"+tableName+"(id
> > > > > INT,name CHAR(20),position CHAR(20))");
> > > > > // CQuery step2Query(&db,"INSERT INTO "+tableName+"
> > > > > VALUES(:person_id,:person_name,:position_name)");
> > > > > CQuery step3Query(&db,"SELECT * FROM airh"); //+tableName WHERE
> > > > > id > :some_id");
> > > > > // CQuery step4Query(&db,"DROP TABLE "+tableName);
> > > > > //cout << "Ok.\nStep 5: Selecting the information the fast way
> > > > > .." << endl;
> > > > > // fl_message("Ok.\nStep 5: Selecting the information the fast
way
> > > > > ..");
> > > > > // step3Query.param("some_id") = 1;
> > > > > step3Query.open();
> > > > > // int counter = step3Query[0].asInteger();
> > > > > // fl_message("\n The temp table now has %d records..",
> > > > > counter );
> > > > > // First, find the field references by name or by number
> > > > > // CField& idField = step3Query[0];
> > > > > CField& nameField = step3Query["Table Name"];
> > > > > CField& positionField = step3Query["Country"];
> > > > > //fl_message("%s",CField& nameField);
> > > > > if(step3Query.eof() == true)
> > > > > {
> > > > > fl_message("End of database");
> > > > > }
> > > > > while (step3Query.eof() != true ) { // it doesn't come into that
> > loop
> > > > > // int id = idField.asInteger();
> > > > > //string name = nameField.asString();
> > > > > name = nameField.asString();
> > > > > char * msg = (char *) name.c_str();
> > > > > fl_message("%s namefield",msg);
> > > > > //strcpy(name,nameField.asString());
> > > > > //string position = positionField.asString();
> > > > > position = positionField.asString();
> > > > > //strcpy(position,positionField.asString());
> > > > > //cout << setw(20) << name << " | " << position << endl;
> > > > > cResult = name;
> > > > > //strcpy(cResult,name);
> > > > > step3Query.fetch();
> > > > > }
> > > > > step3Query.close();
> > > > > cout <<
> > > > > "Ok.\n***********************************************\nTesting
the
> > > > > transactions.";
> > > > > testTransactions(db,tableName,true);
> > > > > testTransactions(db,tableName,false);
> > > > > // step4Query.exec();
> > > > > cout << "Ok.\nStep 6: Closing the database.. ";
> > > > > db.close();
> > > > > cout << "Ok." << endl;
> > > > > fl_message("Ok");
> > > > > } catch (exception& e) {
> > > > > cout << "\nError: " << e.what() << endl;
> > > > > cout << "\nSorry, you have to fix your database connection." <<
> > > > > endl;
> > > > > cout << "Please, read the README.txt for more information." <<
> > > > > endl;
> > > > > }
> > > > > // return 0;
> > > > > return ;//cResult;
> > > > > }
> > > > > ================================================================
> > > > >
> > > > >
> > > > >
> > > > > ---------------------------------
> > > > > Expecting? Get great news right away with email Auto-Check.
> > > > > Try the Yahoo! Mail Beta.
> > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Alexey Parshin,
> > > > http://www.sptk.net
> > > >
> > > >
> > > >
> > > > ---------------------------------
> > > > Never Miss an Email
> > > > Stay connected with Yahoo! Mail on your mobile. Get started!
> > >
> > >
> > >
> > >
> > > --
> > > Alexey Parshin,
> > > http://www.sptk.net
> > >
> > >
> > >
> > > ---------------------------------
> > > We won't tell. Get more on shows you hate to love
> > > (and love to hate): Yahoo! TV's Guilty Pleasures list.
> >
> >
> >
> >
> > --
> > Alexey Parshin,
> > http://www.sptk.net
> >
> >
> >
> > ---------------------------------
> > Check out the all-new Yahoo! Mail beta - Fire up a more powerful email
> and
> > get things done faster.
>
>
>
>
> --
> Alexey Parshin,
> http://www.sptk.net
>
>
>
> ---------------------------------
> Don't get soaked. Take a quick peak at the forecast
> with theYahoo! Search weather shortcut.




--
Alexey Parshin,
http://www.sptk.net



---------------------------------
Don't be flakey. Get Yahoo! Mail for Mobile and
always stay connected to friends.




--
Alexey Parshin,
http://www.sptk.net

List hosted by Total Knowledge

Authoright © Total Knowledge: 2005