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;
}


Wednesday, May 30, 2007

When to use __fastcall

The __fastcall keyword should be used when a function is expecting parameters to be passed in registers. It must be used for all TForm methods. (see http://www.codepedia.com/1/CppBuilderFastcall)

This guy talks about it in a Win32 sense. He mentions that I buys little in a x86 world because of the limited register set. However, under the x64 calling convention this is not the case. (see http://www.nynaeve.net/?p=63). This guy, Ken Johnson, really seems to know what he is talking about.

Confusing Compiler Error Messages

If I leave the semicolon off a class declaration I get the following set of confusing error messages:

[C++ Warning] QuerySet.cpp(19): W8058 Cannot create pre-compiled header: header incomplete

[C++ Error] QuerySet.cpp(20): E2111 Type 'QuerySet' may not be defined here

[C++ Error] QuerySet.cpp(20): E2136 Constructor cannot have a return type specification

Add the semicolon to the end of the class declaration and all these problems go away.

Friday, May 25, 2007

Database Objects

TTable
TQuery
TStoredProc - store procedure are available in ACCESS since 2000. However, you cannot get to them from the user interface. They must be created.

Tuesday, May 15, 2007

Parameters

A subroutine's parameters can be passed on one of two ways.

  • call by value - copies the value of an argument in to the formal parameter of the subroutine. Changes to the parameter of the subroutine has no effect on the argument used to call it.
  • call by reference - the address of an argument is copied in the parameter. Changes made to the parameter will affect the argument.