summaryrefslogtreecommitdiff
path: root/src/tests/xb_test_sql.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/xb_test_sql.cpp')
-rwxr-xr-xsrc/tests/xb_test_sql.cpp95
1 files changed, 90 insertions, 5 deletions
diff --git a/src/tests/xb_test_sql.cpp b/src/tests/xb_test_sql.cpp
index 630cc89..20c8514 100755
--- a/src/tests/xb_test_sql.cpp
+++ b/src/tests/xb_test_sql.cpp
@@ -35,6 +35,8 @@ int main( int argCnt, char **av )
/* 1 - NORMAL */
/* 2 - VERBOSE */
+ xbString sSql;
+
if( argCnt > 1 ) {
if( av[1][0] == 'Q' )
po = 0;
@@ -56,7 +58,7 @@ int main( int argCnt, char **av )
xbXBase x;
-#ifdef XB_LOGGING_SUPPORT
+ #ifdef XB_LOGGING_SUPPORT
x.EnableMsgLogging();
if( po ){
std::cout << "Logfile is [" << x.GetLogFqFileName().Str() << "]" << std::endl;
@@ -64,7 +66,7 @@ int main( int argCnt, char **av )
xbString sMsg;
sMsg.Sprintf( "Program [%s] initializing...", av[0] );
x.WriteLogMessage( sMsg );
-#endif
+ #endif
@@ -77,26 +79,108 @@ int main( int argCnt, char **av )
if( po > 0 )
std::cout << "Default Data Directory is [" << x.GetDataDirectory().Str() << "]" << std::endl;
+
xbDbf4 SqlDbf( &x ); // version 4 dbf file
+
+
+ // clean up any things possibly needing cleaned up
+ xbString sDir;
+ SqlDbf.GetFileDirPart( sDir );
+ xbString sDbfName;
+ xbString sDbtName;
+ xbString sMdxName;
+ sDbfName.Sprintf( "%sTestSQL.DBF", sDir.Str());
+ sDbtName.Sprintf( "%sTestSQL.DBR", sDir.Str());
+ sMdxName.Sprintf( "%sTestSQL.MDX", sDir.Str());
+ SqlDbf.xbRemove( sDbfName );
+ SqlDbf.xbRemove( sDbtName );
+ SqlDbf.xbRemove( sMdxName );
+ sDbfName.Sprintf( "%sTestSqlR.DBF", sDir.Str());
+ sDbtName.Sprintf( "%sTestSqlR.DBT", sDir.Str());
+ sMdxName.Sprintf( "%sTestSqlR.MDX", sDir.Str());
+ SqlDbf.xbRemove( sDbfName );
+ SqlDbf.xbRemove( sDbtName );
+ SqlDbf.xbRemove( sMdxName );
+
+
iRc2 = SqlDbf.CreateTable( "TestSQL.DBF", "TestSQL", MySqlRecord, XB_OVERLAY, XB_MULTI_USER );
iRc += TestMethod( po, "CreateTable()", (xbInt32) iRc2, XB_NO_ERROR );
if( iRc2 )
x.DisplayError( iRc2 );
+ #ifdef XB_MDX_SUPPORT
+ sSql = "CREATE INDEX tag1 ON TestSQL.DBF( CITY, STATE, DTOS( LASTUPDATE )) FILTER .NOT. DELETED()";
+ // xbString sSql = "CREATE INDEX tag1 ON TestSQL.DBF( CITY, STATE )";
- xbString sSql = "INSERT INTO TestSQL (CITY, STATE, ZIPCODE, NOTES, LASTUPDATE, ACTIVE ) VALUES ( 'San Diego', 'CA', 92007, 'San Diego is a cool place', '1989-02-09', 'Y')";
+ iRc2 = sql.ExecuteNonQuery( sSql );
+ iRc += TestMethod( po, "SqL CreateIndex()", (xbInt32) iRc2, XB_NO_ERROR );
+ if( iRc2 )
+ x.DisplayError( iRc2 );
+ #endif // XB_MDX_SUPPORT
+ sSql = "INSERT INTO TestSQL (CITY, STATE, ZIPCODE, NOTES, LASTUPDATE, ACTIVE ) VALUES ( 'San Diego', 'CA', 92007, 'San Diego is a cool place', '1989-02-09', 'Y')";
iRc2 = sql.ExecuteNonQuery( sSql );
- iRc += TestMethod( po, "Insert()", (xbInt32) iRc2, XB_NO_ERROR );
+ iRc += TestMethod( po, "SqlInsert()", (xbInt32) iRc2, XB_NO_ERROR );
if( iRc2 )
x.DisplayError( iRc2 );
+ sSql = "INSERT INTO TestSQL (CITY, STATE, ZIPCODE, NOTES, LASTUPDATE, ACTIVE ) VALUES ( 'Dallas', 'TX', 76248, 'Dallas is hot in the summer', '1989-02-09', 'N')";
+ iRc2 = sql.ExecuteNonQuery( sSql );
+ iRc += TestMethod( po, "SqlInsert()", (xbInt32) iRc2, XB_NO_ERROR );
+ if( iRc2 )
+ x.DisplayError( iRc2 );
+
+ sSql = "ALTER TABLE TestSQL.DBF RENAME TO TestSqlR.DBF";
+
+ iRc2 = sql.ExecuteNonQuery( sSql );
+ iRc += TestMethod( po, "SqlAlterTable()", (xbInt32) iRc2, XB_NO_ERROR );
+ if( iRc2 )
+ x.DisplayError( iRc2 );
+
+ x.DisplayTableList();
+
+
+ sSql = "DELETE FROM TestSqlR.DBF WHERE CITY='San Diego'";
+ iRc2 = sql.ExecuteNonQuery( sSql );
+ iRc += TestMethod( po, "SqlDelete()", (xbInt32) iRc2, XB_NO_ERROR );
+ if( iRc2 )
+ x.DisplayError( iRc2 );
+
+ sSql = "UNDELETE FROM TestSqlR.DBF WHERE CITY='San Diego'";
+ iRc2 = sql.ExecuteNonQuery( sSql );
+ iRc += TestMethod( po, "SqlUndelete()", (xbInt32) iRc2, XB_NO_ERROR );
+ if( iRc2 )
+ x.DisplayError( iRc2 );
+
+ sSql = "DELETE FROM TestSqlR.DBF";
+ iRc2 = sql.ExecuteNonQuery( sSql );
+ iRc += TestMethod( po, "SqlDelete()", (xbInt32) iRc2, XB_NO_ERROR );
+ if( iRc2 )
+ x.DisplayError( iRc2 );
+
+ sSql = "UNDELETE FROM TestSqlR.DBF";
+ iRc2 = sql.ExecuteNonQuery( sSql );
+ iRc += TestMethod( po, "SqlDelete()", (xbInt32) iRc2, XB_NO_ERROR );
+ if( iRc2 )
+ x.DisplayError( iRc2 );
+
+
+ sSql = "DELETE FROM TestSqlR.DBF WHERE BAD='EXPRESSION'";
+ iRc2 = sql.ExecuteNonQuery( sSql );
+ iRc += TestMethod( po, "SqlDelete()", (xbInt32) iRc2, XB_INVALID_FIELD_NAME );
+// if( iRc2 )
+// x.DisplayError( iRc2 );
+
+
+// sSql = "SELECT CITY, STATE ZIPCODE FROM TestSQL.DBF WHERE CITY IS NOT NULL";
+// iRc += TestMethod( po, "Select()", SqlDbf.Select( sSql ), XB_NO_ERROR );
+
+
iRc += TestMethod( po, "Close()", SqlDbf.Close(), XB_NO_ERROR );
if( po > 0 || iRc < 0 )
fprintf( stdout, "Total Errors = %d\n", iRc * -1 );
-
#ifdef XB_LOGGING_SUPPORT
sMsg.Sprintf( "Program [%s] terminating with [%d] errors...", av[0], iRc * -1 );
x.WriteLogMessage( sMsg );
@@ -105,3 +189,4 @@ int main( int argCnt, char **av )
return iRc;
}
+ \ No newline at end of file