Wolfgang Schaible wrote:
Well, to be honest now I am sure I mislead you.hi Drew, Am Sunday 21 May 2006 18:21 schrieb Andrew Jensen: <> First - you can issue an alter table command using executeUpdate on a statement yes. For example if I have the following table defintitions: CREATE TABLE "Table1" ( "ID" IDENTITY, "Name" VARCHAR(50) ); CREATE TABLE "Table2" ( "ID" IDENTITY, "NameID" INTEGER, "Alias" VARCHAR(50)); Then I could add the foreign key constraint with this code: sub onClickAltertable( oev as object ) dim stmt dim sCmd as string sCmd = "ALTER TABLE ""Table2"" " _ + "ADD FOREIGN KEY (""ID2"") " _
+ "REFERENCES ""Table1"" (""ID"")" _
+ "ON DELETE CASCADE " _ + "ON UPDATE CASCADE" stmt = oev.source.model.parent.ActiveConnection.createStatement stmt.executeUpdate( sCmd ) end sub Of course you can also just open the SQL window in Base ( Tools>SQL ) and enter the alter table command directly also. That doesn't in and of itself help you with inserting new records in Table2 however, you still need to get the correct value for the ID2 field in Table2. So if I had a dialog box that had 5 text controls ( txtBox1...txtBox5), 1 for a name and 4 for aliases and wanted to enter them all into the database when the dialog is submitted I could code something like: sub onInsertRecords dim stmt dim rs dim FK_Val '...... 'get connection and create statment ' InsertMaster( Stmt, oDialog.GetControl("txtBox1").text )
rs = Stmt.executeQuery( " CALL IDENTITY() " ) rs.next FK_Val = rs.columns(0).getInt InsertChil( Stmt, FK_VAL, oDialog.GetControl("txtBox2").Text )
..... 'do the same fo the other aliases ..... end sub sub InsertMaster( aStmt as variant, aName as string ) aStmt.executeUpdate( "INSERT INTO ""Table1"" ( ""NAME"" ) VALUES ( " + aName + " ) " end sub sub InsertChild( aStmt as variant, aFK as integer, aAlias as string ) aStmt.executeUpdate( "INSERT INTO ""Table2"" ( ""ID2"", ""Alias"" ) VALUES ( " + aFK + ", " + aAlias + " )" end sub I would guess that is something similar to what you have already. Drew |
- [dba-users] Base.HSQL: Reference, Call Identity Wolfgang Schaible
- Re: [dba-users] Base.HSQL: Reference, Call Identity Andrew Jensen
- Re: [dba-users] Base.HSQL: Reference, Call Iden... Wolfgang Schaible
- Re: [dba-users] Base.HSQL: Reference, Call ... Andrew Jensen
- Re: [dba-users] Base.HSQL: Reference, C... Wolfgang Schaible
- Re: [dba-users] Base.HSQL: Referen... Andrew Jensen
- Re: [dba-users] Base.HSQL: Ref... Wolfgang Schaible
