In general, to create the datamodule you should follow the instructions in Connecting to a Firebird (Interbase) Database ... this page relates mostly to coding differences - ie, how to migrate existing code from one datamodule to another.
Database Connection
| KADao | Interbase | |
|---|---|---|
| Database name | TKADaoDatabase.Database | TIBDatabase.DatabaseName |
| KADao | Interbase | |
|---|---|---|
| Component | KADaoTable1.TableName := query
KADaoTable1.SQL := query | IBQuery1.SQL.Text := query |
| Filter | Set the Filter property and set Filtered to true | Not supported (only works with tables) |
| Parameters (both are the same) |
KADao
Table.SQL := 'SELECT * FROM tbl1 WHERE ID=:Param_Name;';
Table.Active := false;
Table.Params.ParamByName('Param_Name').AsString := 'xyz';
Table.Active := true;
Interbase
IBQuery1.SQL := 'SELECT * FROM "tbl1" WHERE "ID"=:Param_Name;';
IBQuery1.Active := false;
IBQuery1.Params.ParamByName('Param_Name').AsString := 'xyz';
IBQuery1.Active := true;
In both cases, if the parameter is a string, do NOT surround it with quotes in the query.
| |
| KADao | Interbase | |
|---|---|---|
| Strings in a where clause | Place in double quotes where field1="text"or in single quotes where field1='text' | Place in single quotes where FIELD1='text' |
| Strings in a where clause | The comparison is not case sensitive | This comparison is case sensitive where FIELD1='text'This comparison is NOT case sensitive where FIELD1 like 'text' |
| Dates in a where clause | Place between pound signs where field1=#1/12/04# | Place in single quotes where FIELD1='2/23/04' |
| Table and Field names - Without delimiters | As long as they do not contain spaces
tablename.fieldname | If they are all upper case and do not contain spaces
TABLE_NAME.FIELD_NAME |
| Table and Field names - Required delimiters | Use [..] if they contain spaces
[table name].[field name] | Use double quotes if they are mixed case or contain spaces
(dialect 3 only)
"table name"."field name" |
| Select Queries | The same component can be used for both tables and queries
KADaoTable_Query: TKADaoTable; | Tables and queries use different components
IBQuery1 : TIBQuery; IBDataSet1: TIBDataSet |
| Update Queries | The same component can be used for both tables and queries
KADaoTable_Query: TKADaoTable; KADaoTable_Query.ExecSQL(SQL); | 2 components can be used
IBQuery1 : TIBQuery; TIBQuery.ExecSQL TIBSQL.SQL := '' TIBSQL.ExecQuery |
| String concatenation in Queries |
SELECT [LN]+', '+[FN] AS Name |
"LN" || ', ' || "FN" AS NameSpaces on either side of the operators does not matter Plus (+) is not the string concatenation operator "LN"+', '+"FN" AS Nameproduces Dynamic SQL Error expression evaluation not supported. |
| Distinct Rows |
SELECT DISTINCTROW * FROM A_tbl SELECT DISTINCT * FROM A_tbl Distinct -> UniqueVales DistinctRow -> UniqueRecords |
SELECT DISTINCT * FROM "A_tbl"DistinctRow is not supported ... and the error points to the wrong place in the SQL string Dynamic SQL Error Token unknown |
| Problem Characters | Dashes are ok
From-A-To-B | Dashes are not allowed
From_A_To_B |
| Datetime | 12 hour time may be ok
| Must use 24 hour time, supports literals
'8/19/2004 3:19:43 PM' Fails '8/19/2004 15:19:43' OK 'now' current datetime |
s :=
'SELECT Barcodes_tbl.Barcode ' +
' FROM Barcodes_tbl ' +
' WHERE (((Barcodes_tbl.Barcode)="' + Barcode + '"));' ;
This query is used with Interbase components -
the table and field names are in double quotes,
and the search string is in single quotes.
s :=
'SELECT "Barcodes_tbl"."Barcode" ' +
' FROM "Barcodes_tbl" ' +
' WHERE ((("Barcodes_tbl"."Barcode")=''' + Barcode + '''));' ;
Select Query Code Fragments
MS Access/KADao example
s :=
'SELECT Barcodes_tbl.Barcode ' +
' FROM Barcodes_tbl ' +
' WHERE (((Barcodes_tbl.Barcode)="' + Barcode + '"));' ;
KADaoTable_Query.Active := False;
KADaoTable_Query.TableName := s;
KADaoTable_Query.Active := True;
if KADaoTable_Query.FieldValues['Barcode'] <> null then begin
LastVerifiedbarcode := Barcode;
result := true;
end else
LastVerifiedbarcode := '**not Set**';
Interbase/Firebird example
s :=
'SELECT "Barcodes_tbl"."Barcode" ' +
' FROM "Barcodes_tbl" ' +
' WHERE ((("Barcodes_tbl"."Barcode")=''' + Barcode + '''));' ;
IBQuery1.Active := False;
IBQuery1.SQL.Text := s;
IBQuery1.Active := True;
if IBQuery1.FieldValues['Barcode'] <> null then begin
LastVerifiedbarcode := Barcode;
result := true;
end else
LastVerifiedbarcode := '**not Set**';
Select Query Code Fragments
MS Access/KADao example
SELECT Users_tbl.UserID, Group_User_Map_tbl.Group_ID,
[Last_Name]+', '+[First_Name] AS Name
FROM Users_tbl
INNER JOIN Group_User_Map_tbl ON Users_tbl.UserID = Group_User_Map_tbl.User_ID
WHERE (((Group_User_Map_tbl.Group_ID)=:Group_ID_Parameter))
ORDER BY [Last_Name]+', '+[First_Name];
Interbase/Firebird example - as shown, this fails because it contains expressions
SELECT "Users_tbl"."UserID", "Group_User_Map_tbl"."Group_ID",
"Last_Name" || ', ' || "First_Name" AS Name
FROM "Users_tbl"
INNER JOIN "Group_User_Map_tbl" ON "Users_tbl"."UserID" = "Group_User_Map_tbl"."User_ID"
WHERE ((("Group_User_Map_tbl"."Group_ID")=:Group_ID_Parameter))
ORDER BY "Last_Name"||', '||"First_Name";
Note the use of a parameter - :Group_ID_Parameter - requires setting
ParamType and ParamCheck.
IBQuery_Users_View.Active := false;
IBQuery_Users_View.Params.ParamByName('Group_ID_Parameter').AsString := Value;
IBQuery_Users_View.Params.ParamByName('Group_ID_Parameter').ParamType := ptInput;
IBQuery_Users_View.Open;
Insert/Update Query Code Fragments
In these examples, Sample_ID is a number.
MS Access/KADao example
s := 'UPDATE Samples_tbl SET ' + fields +
' WHERE (Sample_ID=' + IntToStr(Sample_ID) + ')';
SQL := TStringList.Create;
SQL.Add(s);
KADaoTable_Query.ExecSQL(SQL);
SQL.Free;
Interbase/Firebird example (not tested ... yet)
s := 'UPDATE "Samples_tbl" SET ' + fields +
' WHERE ("Sample_ID"=' + IntToStr(Sample_ID) + ')';
IBQuery1.SQL.Text := s;
IBQuery1.ExecSQL;
Debugging Queries
There is obviously some kind of cache, and simply restarting your program does not affect it.
Changing field names and intentionally introducing errors has no effect - the old results are still returned.
| Locating a record | KADao | flag := KADaoTable_SOPs.Find_First
('Procedure_ID', SOP_ID, [loCaseInsensitive]); |
|---|---|---|
| Interbase | flag := IBTable_SOPs_tbl.LocateNext
('Procedure_ID', SOP_ID, [loCaseInsensitive]); |