Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Create Connection Problem (With OLEDB)
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00565686
Message ID:
00566707
Views:
31
>The one last thing I have to ask about on this subject is how I
>can create indexes using only what the OLEDB provider provides.
>I see that "index on" is in the unsupported list.

I'm still digesting the rest of your message, but you can add index tags using the ADOX index object:
LOCAL oCat As "adox.catalog"
LOCAL oTable As "Adox.table"
LOCAL oConn As "Adodb.connection"
LOCAL oIdx As "adox.index"

*-- Setup code
SET EXCLUSIVE Off
Clear
RELEASE ALL
CLOSE ALL
CLEAR ALL

IF File("TestDBC.DBC")
	Erase TestDBC.DBC
Endif

IF File("TestDBC.Dct")
	Erase TestDBC.Dct
Endif

IF File("TestDBC.Dcx")
	Erase TestDBC.Dcx
Endif

IF File("TestTable2.dbf")
	Erase TestTable2.dbf
Endif

IF File("TestTable2.cdx")
	Erase TestTable2.cdx
Endif

CREATE DATABASE TestDBC
CLOSE DATABASES All

oCat = CREATEOBJECT("adox.catalog")
oTable = CREATEOBJECT("adox.table")
oConn = CREATEOBJECT("adodb.connection")

oConn.ConnectionString = "Provider=Vfpoledb.vfpoledb;Data Source=.\TestDBC.dbc"
oConn.Open 
oCat.ActiveConnection = oConn

oTable.Name = "testtable2"
oTable.Columns.Append("Col_char", 129)
oTable.Columns.Append("Col_Date", 133)
oTable.Columns.Append("Col_DBDate", 135)
oTable.Columns.Append("Col_int", 3)
oTable.Columns.Append("Col_dbl", 5)
oTable.Columns.Append("Col_cy", 6)
oTable.Columns.Append("Col_bool", 11)

*-- Have to this one differently, because it's the
*-- only way to set the precision before appending
*-- to the Columns collection.
oCol = CREATEOBJECT("adox.column")
oCol.Name = "Col_Num"
oCol.Type = 131  && adNumeric 
oCol.Precision = 1
oTable.Columns.Append(oCol)
oCat.Tables.Append(oTable)

? "Indexes before append:"
? oTable.Indexes.Count

*-- Append indexes to the table in ascending order
i = 0
FOR Each Child in oTable.Columns
	oIdx = CREATEOBJECT("adox.index")
	oIdx.Columns.Append(oTable.Columns(i).Name)
	oIdx.Columns(0).SortOrder = 1  && adSortAscending

	*-- Make sure the name is ten characters, and trim the "col_" from
	*-- the column name
	oIdx.Name = Substr("A_" + Substr(oTable.Columns(i).Name, 4), 1, 10)
	oTable.Indexes.Append(oIdx)

	oIdx = Null
	i = i + 1
Endfor

? "Indexes after appending ascending:"
? oTable.Indexes.Count

*-- Append descending indexes
i = 0
FOR Each Child in oTable.Columns
	oIdx = CREATEOBJECT("adox.index")
	oIdx.Columns.Append(oTable.Columns(i).Name)
	oIdx.Columns(0).SortOrder = 2  && adSortAscending

	*-- Make sure the name is ten characters, and trim the "col_" from
	*-- the column name
	oIdx.Name = Substr("D_" + Substr(oTable.Columns(i).Name, 4), 1, 10)

	oTable.Indexes.Append(oIdx)
	
	oIdx = Null
	i = i + 1
Endfor

? "Indexes after appending descending:"
? oTable.Indexes.Count

*-- Release the table object and try again
oTable = Null
oTable = CREATEOBJECT("adox.table")
oTable = oCat.Tables.Item(0)

? "Indexes after releasing table:"
? oTable.Indexes.Count

*-- Cleanup
RELEASE ALL
CLOSE ALL
CLEAR ALL
Mike Stewart
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform