Thursday, June 14, 2007

Using TADO Objects

This was a major pain in the neck. The documentation in Borland is not clear; however, I now have something working.

I should mention that I am working with Access 2003 and Borland Builder 6.0 Professional.

For my experience so far I believe the following to be true:
  • There is no way to setup an ADO connection in ODBC (I could be wrong in this but it is not clearly obvious how one would set it up.)
  • Procedures can be created and destroyed. In TQuery they can only be created.
I was able to get the connection string using the Borland ADO controls. The is a helper for building the string and I don't think I could have done what I did without it.

The following test code compiled and ran and worked.

#include

TADOConnection *conn = new TADOConnection( NULL );

conn->ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;"
"Data Source=C:\\LU_IncomingQC_APB.mdb;"
"Persist Security Info=False" ;
conn->Open();
TADOQuery *qry = new TADOQuery( NULL );
qry->Connection = conn;

// Create the procedure to be called
sql = "CREATE PROC createTable "
" (NewTable TEXT) AS "
" CREATE TABLE NewTable "
" ( "
" InvoiceID INTEGER NOT NULL, "
" InvoiceDate DATETIME NOT NULL "
" ); ";

sql = "CREATE PROCEDURE DeleteInvoices AS (DROP TABLE testTable1)";
qry->SQL->Clear();
qry->SQL->Add( sql );
qry->ExecSQL();

sql = "DROP PROC DeleteInvoices;";

qry->SQL->Clear();
qry->SQL->Add( sql );
qry->ExecSQL();

normal

Wednesday, June 6, 2007

TDS File Extentions

Turbo Debugger Symbol Table: http://filext.com/file-extension/TDS

This file should not be managed.

Friday, June 1, 2007

Table Present?

Two ways to test to see if a table is present:

One

The following code will determine is a table is present and delete it.

TDatabase *db = qry->OpenDatabase();
const String TABLE_NAME = "AC130U_061016_corrected";
TStringList *list = new TStringList;
db->GetTableNames( list );
if ( list->IndexOf(TABLE_NAME)>=0 )
{
String s1 = "DROP TABLE [" + TABLE_NAME + "];";
qry->Execute( s1 );
}

The qry is of type TQuery.

Two

bool HasTable=false;

TTable *testTable = new TTable(NULL);
try
{
testTable->DatabaseName = dbase->DatabaseName;
testTable->TableName = TableName;
HasTable = testTable->Exists;
}
__finally
{
delete testTable;
}