Laurent ,
From wath i know, i supose you have to define your Columndescriptor also
something
like:
with descCol
. name = "testcolumn1"
.type = datatype.INTEGER
.IsNullable=ColumnValues.NO_NULLS
.IsAutoincrement = true
thanks to Roberto Benitez and his exelent book i found this working sub:
Sub createTable()
Dim Context As Object
Dim DB As Object
Dim Conn As Object
Dim Tables AS Object
Dim Columns As Object
Dim Keys As Object
Dim KeyColumns As Object
Dim TableDescriptor As Object
Dim ColumnDescriptor As Object
Dim KeyDescriptor
Dim DataTypes As object
Dim ColumnValues As Object
Dim KeyTypes As Object
Context=CreateUnoService("com.sun.star.sdb.DatabaseContext")
DB=Context.getByName(ConvertToURL("H:\Documents\Book\Sample
Databases\DB1.odb") )
Conn=DB.getConnection("","")
DataTypes=com.sun.star.sdbc.DataType
ColumnValues=com.sun.star.sdbc.ColumnValue
KeyTypes=com.sun.star.sdbcx.KeyType
REM CREATE DESCRIPTOR
Tables=Conn.Tables
TableDescriptor=Tables.createDataDescriptor()
TableDescriptor.Name="INCIDENTS"
Columns=TableDescriptor.Columns
ColumnDescriptor=Columns.createDataDescriptor()
REM APPEND COLUMN 1
With ColumnDescriptor
.Name="INCIDENTID"
.Type=DataTypes.INTEGER
.IsNullable=ColumnValues.NO_NULLS
.IsAutoIncrement=True
End With
rem
Columns.appendByDescriptor(ColumnDescriptor)
REM APPEND COLUMN 2
With ColumnDescriptor
.Name="EMPID"
.Type=DataTypes.INTEGER
.IsNullable=ColumnValues.NO_NULLS
.IsAutoIncrement=false REM WAS SET TO TRUE ON PREVIOUS
End With
Columns.appendByDescriptor(ColumnDescriptor)
REM APPEND COLUMN 3
With ColumnDescriptor
.Name="DESCRIPTION"
.Type=DataTypes.LONGVARCHAR
.IsNullable=ColumnValues.NULLABLE
End With
Columns.appendByDescriptor(ColumnDescriptor)
REM CREATE KEY
Keys=TableDescriptor.Keys
KeyDescriptor=Keys.createDataDescriptor()
KeyDescriptor.Type=KeyTypes.PRIMARY
KeyDescriptor.Name="INCIDENTS_PK"
KeyColumns=KeyDescriptor.Columns
ColumnDescriptor=KeyColumns.createDataDescriptor()
ColumnDescriptor.Name="INCIDENTID"
KeyColumns.appendByDescriptor(ColumnDescriptor)
Keys.AppendByDescriptor(KeyDescriptor)
REM FINALLY, APPEND THE TABLE TO THE TABLE SUPPLIER
Tables.appendByDescriptor(TableDescriptor)
Conn.Close()
End Sub
hope it helps
Fernand
Hi all
I'm facing a problem for 3 days i cannot solve using database and
OOoBasic
My goal is to dynamically create a table
It used to work in some light tests based on Andrew's document (thanks
to him) but now, going in my whole stuff, i encounter the following
problem
I create my DataDescriptor,
descCol = connection.Tables.createDataDescriptor
I define the column, good, no problem
But, it raises an error when i want to
cols = descTable.Columns
cols.appendByDescriptor(descCol)
The appendByDescriptor method is not available for the created
dataDescriptor , confirmed with the use of XRay
Is there any known cases where this can happen ?
I have also to say that i do somme uggly stuff on
moving/deleting/copying .odb files before creating the connection but
i do not expect problem here as examinating the connection seems ok,
giving for example, all the tables list and doing requests (select,
insert, update)
Btw, is there a way to list all the currently active connections that
OOo manages in order to explore if i do not have some already opened,
trying to close them for testing ?
Thanks a lot for any hints you may give to a poor lost scripter in
database API world
Laurent
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org
For additional commands, e-mail: dev-h...@api.openoffice.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org
For additional commands, e-mail: dev-h...@api.openoffice.org