[VSDK] Can't update boolean

Arthur Clemens aclemens at xs4all.nl
Thu Nov 20 11:26:20 CST 2003


It it a bit unclear to me how to change a boolean value with an SQL 
query. Should I use true or 'true' or '1' or 1?
Either way I can't manage to update the value with SQL.

I have made a test case by changing Example1 (see below).
In all 3 tests I get zero results.

It does work when I use a VDK_Short and use that as boolean by setting 
to 0 or 1.

Arthur Clemens



-----------------------------------------------------------------
EXAMPLE 1

in .h:
class MyBaseObject : public VDK_BaseObject
{
     public:
         VDK_String		mfField1;
         VDK_String		mfField2;
         VDK_Short		mfField3;
         VDK_Double		mfField4;
         VDK_ULong		mfField5;
         VDK_Boolean             mfField6;
         VDK_Boolean             mfField7;
         VDK_Boolean             mfField8;

public:
         MyBaseObject( void ) : VDK_BaseObject( "MyBaseObject" ),
             mfField1( "Field1", 40 ),
             mfField2( "Field2", 40 ),
             mfField3( "Field3" ),
             mfField4( "Field4" ),
             mfField5( "Field5" ),
             mfField6( "Field6" ),
             mfField7( "Field7" ),
             mfField8( "Field8" ){ }
};

in .cpp:
in addRecords, add:

         mBaseObject1.mfField6 = false;
         mBaseObject1.mfField7 = false;
         mBaseObject1.mfField8 = false;

and replace doSqlTest

void MyDataBase::doSqlTest()
{
     {
         this->SqlExecute("UPDATE MyBaseObject "
                         "SET Field6 = true "
                         "WHERE Field3 = 10" );
         VDK_Cursor* pCursor = this->SqlSelect(
                                             "SELECT * FROM MyBaseObject 
"
                                             "WHERE Field6 = true "
                                             "ORDER BY Field1, Field2" );
         ulong recsCount = pCursor->GetRecordCount();
         cout << "After setting Field6 = true" << endl;
         cout << "Records found: " << recsCount << endl;
         if (recsCount > 0) {
             // we can iterate records of cursor as we want:
             do {
                 short 	v3 = pCursor->GetShort("Field3");
                 bool        v6 = pCursor->GetBoolean("Field6");
                 bool        v7 = pCursor->GetBoolean("Field7");
                 bool        v8 = pCursor->GetBoolean("Field8");
                 cout << "v3 = " << v3 << " v6 = " << v6 << " v7 = " << 
v7 << " v8 = " << v8 << endl;
             } while( pCursor->NextRecord() );  	
         }
         delete pCursor;
     }
     {
         this->SqlExecute("UPDATE MyBaseObject "
                          "SET Field6 = 'true' "
                          "WHERE Field3 = 11" );
         VDK_Cursor* pCursor = this->SqlSelect(
                                               "SELECT * FROM 
MyBaseObject "
                                               "WHERE Field6 = 'true' "
                                               "ORDER BY Field1, Field2" 
);
         ulong recsCount = pCursor->GetRecordCount();
         cout << "After setting Field6 = 'true'" << endl;
         cout << "Records found: " << recsCount << endl;
         if (recsCount > 0) {
             // we can iterate records of cursor as we want:
             do {
                 short 	v3 = pCursor->GetShort("Field3");
                 bool        v6 = pCursor->GetBoolean("Field6");
                 bool        v7 = pCursor->GetBoolean("Field7");
                 bool        v8 = pCursor->GetBoolean("Field8");
                 cout << " v3 = " << v3 << " v6 = " << v6 << " v7 = " << 
v7 << " v8 = " << v8 << endl;
             } while( pCursor->NextRecord() );  	
         }
         delete pCursor;
     }
     {
         this->SqlExecute("UPDATE MyBaseObject "
                          "SET Field6 = 1 "
                          "WHERE Field3 = 12" );
         VDK_Cursor* pCursor = this->SqlSelect(
                                               "SELECT * FROM 
MyBaseObject "
                                               "WHERE Field6 = 1 "
                                               "ORDER BY Field1, Field2" 
);
         ulong recsCount = pCursor->GetRecordCount();
         cout << "After setting Field6 = 1" << endl;
         cout << "Records found: " << recsCount << endl;
         if (recsCount > 0) {
             // we can iterate records of cursor as we want:
             do {
                 short 	v3 = pCursor->GetShort("Field3");
                 bool        v6 = pCursor->GetBoolean("Field6");
                 bool        v7 = pCursor->GetBoolean("Field7");
                 bool        v8 = pCursor->GetBoolean("Field8");
                 cout << " v3 = " << v3 << " v6 = " << v6 << " v7 = " << 
v7 << " v8 = " << v8 << endl;
             } while( pCursor->NextRecord() );  	
         }
         delete pCursor;
     }
}


More information about the Valentina mailing list