CiaoBaby
asked on
Embarcadero Interbase
I want to create an Interbase table at run time like
var
MyTable : TIBTable;
begin
MyTable := TIBTable.Create(nil);
MyTable.TableName := 'MyTableName';
MyTable.Database := AnExistingDatabase;
MyTable.FieldDefs.AddField Def.Name := 'Field1';
MyTable.FieldDefs.AddField Def.DataTy pe := ftInteger;
MyTable.FieldDefs.AddField Def.Size := 0;
MyTable.FieldDefs.AddField Def.Requir ed := False;
AnExistingDatabase.Open;
MyTable.CreateTable;
This generates: Unsupported Field Type.
Also Tried to use TIBSQL component
Assign to a TIBSQL components SQL property with the text below
and set the TIBSQL database property to an IBDatabase component that points to
my database
Create Table "Table2"
(
"Field1" Varchar(20) not null,
"Field2" Float,
primary key ("Field1")
);
procedure TForm1.Button2Click(Sender : TObject);
begin
IBDatabase1.Open;
IBSQL1.ExecQuery;
end;
I get the message Transaction Not assigned
var
MyTable : TIBTable;
begin
MyTable := TIBTable.Create(nil);
MyTable.TableName := 'MyTableName';
MyTable.Database := AnExistingDatabase;
MyTable.FieldDefs.AddField
MyTable.FieldDefs.AddField
MyTable.FieldDefs.AddField
MyTable.FieldDefs.AddField
AnExistingDatabase.Open;
MyTable.CreateTable;
This generates: Unsupported Field Type.
Also Tried to use TIBSQL component
Assign to a TIBSQL components SQL property with the text below
and set the TIBSQL database property to an IBDatabase component that points to
my database
Create Table "Table2"
(
"Field1" Varchar(20) not null,
"Field2" Float,
primary key ("Field1")
);
procedure TForm1.Button2Click(Sender
begin
IBDatabase1.Open;
IBSQL1.ExecQuery;
end;
I get the message Transaction Not assigned
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I use FireBird which is close enough to Interbase:
Drop SQLTransaction and link it to the DBConnection and SQLQuery.
So you should have the following linking done first:
DBConnection.Transaction = SQLTrans
SQLTrans.Database = DBConnection
SQLQuery.Database = DBConnection
SQLQuery.Transaction = SQlTrans
Drop SQLTransaction and link it to the DBConnection and SQLQuery.
So you should have the following linking done first:
DBConnection.Transaction = SQLTrans
SQLTrans.Database = DBConnection
SQLQuery.Database = DBConnection
SQLQuery.Transaction = SQlTrans
ASKER
JimyX
When you say link SQLTransaction to the DBConnection and SQLQuery How?
TIBTransaction does not have a Database property
SQLQuery does not have a Database Property
SQLQuery does not have a Transaction property
When you say link SQLTransaction to the DBConnection and SQLQuery How?
TIBTransaction does not have a Database property
SQLQuery does not have a Database Property
SQLQuery does not have a Transaction property
I was referring to IBxxx components.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Finally, success. That was painful. I can't believe that on all the web there is no reference to how to do this.
It's so not complicated if you know all the steps and relationships. It took me 2 days to figure this out. Maybe I should have said that I do not know any SQL. Maybe it's assumed that if you know any programming that you know all this crap.
Thanks for the help you guys.
procedure TForm1.Button1Click(Sender : TObject);
begin
IBDatabase1.DatabaseName := 'c:\backupdbs\JPBD.IB';
IBDatabase1.Params.Clear;
IBDatabase1.Params.Add('us er_name=sy sdba');
IBDatabase1.Params.Add('pa ssword=mas terkey');
IBDatabase1.Open;
IBDatabase1.DefaultTransac tion := IBTransaction1;
IBTransaction1.DefaultData base := IBDatabase1;
IBQuery1.Transaction := IBTransaction1;
IBQuery1.SQL.Clear;
IBQuery1.SQl.Add('Create Table Employee4(PersonID Int, LastName varchar(255))');
IBQuery1.Transaction.Start Transactio n;
IBQuery1.ExecSQL;
IBQuery1.Transaction.Commi t;
//This also works
//IBTransaction1.Commit;
IBDatabase1.Close;
end;
It's so not complicated if you know all the steps and relationships. It took me 2 days to figure this out. Maybe I should have said that I do not know any SQL. Maybe it's assumed that if you know any programming that you know all this crap.
Thanks for the help you guys.
procedure TForm1.Button1Click(Sender
begin
IBDatabase1.DatabaseName := 'c:\backupdbs\JPBD.IB';
IBDatabase1.Params.Clear;
IBDatabase1.Params.Add('us
IBDatabase1.Params.Add('pa
IBDatabase1.Open;
IBDatabase1.DefaultTransac
IBTransaction1.DefaultData
IBQuery1.Transaction := IBTransaction1;
IBQuery1.SQL.Clear;
IBQuery1.SQl.Add('Create Table Employee4(PersonID Int, LastName varchar(255))');
IBQuery1.Transaction.Start
IBQuery1.ExecSQL;
IBQuery1.Transaction.Commi
//This also works
//IBTransaction1.Commit;
IBDatabase1.Close;
end;
I you by create mean: TIBTable.Create(nil) - then you can use some of memory tables.