Many RDBMSs support SQL DDL statements. ADOX can be used with some databases to do things like create new tables. I do not think this is particularly exotic, especially when the program uses some kind of "built-in" file database as an internal data store or even as an output format.
No problems creating indexes, constraints, relationships, etc. as needed. Example:
Private Const WG_CONNSTRING As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=5;" _
& "Jet OLEDB:Create System Database=True;" _
& "Data Source='$MDB$.mdw'"
Private Const DB_CONNSTRING As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=5;" _
& "Jet OLEDB:System Database='$MDB$.mdw';" _
& "Data Source='$MDB$.mdb'"
'Exits with new MDB created, populated from initial data
'in text files, and cnDB left open.
Dim catDB As Object 'Don't early-bind ADOX objects.
Set catDB = CreateObject("ADOX.Catalog")
catDB.Create Replace$(WG_CONNSTRING, "$MDB$", MDB_NAME)
catDB.Create Replace$(DB_CONNSTRING, "$MDB$", MDB_NAME)
Set cnDB = catDB.ActiveConnection
With cnDB
.Execute "CREATE TABLE Fruits (" _
& "FruitID IDENTITY NOT NULL CONSTRAINT PK_FruitID PRIMARY KEY," _
& "Fruit TEXT(50) WITH COMPRESSION NOT NULL UNIQUE" _
& ")", _
, adCmdText
.Execute "CREATE TABLE Pies (" _
& "PieID IDENTITY NOT NULL CONSTRAINT PK_PieID PRIMARY KEY," _
& "Pie TEXT(50) WITH COMPRESSION NOT NULL," _
& "FruitID INTEGER NOT NULL CONSTRAINT FK_FruitID " _
& "REFERENCES Fruits (FruitID)" _
& ")", _
, adCmdText
.Execute "CREATE VIEW PiesView (ID, Pie, Fruit) AS " _
& "SELECT PieID AS ID, Pie, Fruit " _
& "FROM Pies LEFT OUTER JOIN Fruits " _
& "ON Pies.FruitID = Fruits.FruitID", _
, adCmdText
.Execute "CREATE PROC InsertPie(NewPie TEXT(50), FruitName TEXT(50)) AS " _
& "INSERT INTO Pies (Pie, FruitId) " _
& "SELECT NewPie, Fruits.FruitId FROM Fruits " _
& "WHERE Fruit = FruitName", _
, adCmdText
End With
source
share