PRB: Creating Regular Indexes Through VFP ODBC Driver (163396)
The information in this article applies to:
- Microsoft Visual FoxPro for Windows 5.0
This article was previously published under Q163396 SYMPTOMS
Currently, it is not possible to create a regular index with the INDEX ON
command on a table through the Visual FoxPro ODBC driver, either by SQL
Pass Through or a Default Value, Rule, or Trigger code.
RESOLUTION
It is possible to create a Regular index indirectly with the ALTER TABLE or
CREATE TABLE commands.
NOTE: Please use steps 1-6 from the MORE INFORMATION section below prior to
using the following examples.
Example 1
This example creates a Regular index on a table when the table is created.
A problem you might encounter is that the SQLEXEC() function returns a < 0
result indicating that it failed (and it did fail to carry out the exact
command it was passed). The command passed tries to create a Persistent
Relationship to itself and Visual FoxPro completed a portion of the process
before it realized it could not complete the entire operation. The
byproduct of the command failing is the index tag. The drawback with this
method is there is no positive means of determining whether the tag was
actually created:
mchnl=SQLCONNECT('vfp') && Connect to datasouce
? mchnl && Needs to return a value > 0
? SQLEXEC(mchnl,'CREATE TABLE x6 (col1 c(1), col2 c(3), ;
FOREIGN KEY col2 TAG col2 REFERENCES x6)')
? AERROR(temp)
DISPLAY MEMORY temp
? SQLDISCONNECT(mchnl)
Example 2
This example creates a regular index on an existing table. It functions on
the same principles as Example 1 and has the same drawbacks:
mchnl=SQLCONNECT('vfp') && Connect to datasouce
? mchnl && Needs to return a value > 0
? SQLEXEC(mchnl,'CREATE TABLE x1 (col1 c(1), col2 c(3))')
? SQLEXEC(mchnl,'ALTER TABLE x1 ;
ADD FOREIGN KEY col2 TAG col2 REFERENCES x1')
Example 3
This is probably the best method because you can be confident that the
Index was not created if the SQL Pass Through command returns a < 0 number.
This example requires a Primary Key to exist for the same reasons that
Examples 1 and 2 SQL Pass Through commands failed. The SQL Pass Through
command being passed is going to establish a Persistent Relationship and
then DROP the FOREIGN KEY with the SAVE clause. This will destroy the
Persistent Relationship but will preserve the Regular index TAG:
mchnl=SQLCONNECT('vfp') && Connect to datasource
? mchnl && Needs to return a value > 0
? SQLEXEC(mchnl,'CREATE TABLE x2 (col1 c(1) PRIMARY KEY col2 c(3))')
? SQLEXEC(mchnl,'ALTER TABLE x2 ;
ADD FOREIGN KEY col2 TAG col2 REFERENCES x2')
? SQLEXEC(mchnl,'ALTER TABLE x2 DROP FOREIGN KEY TAG col2 SAVE')
STATUS
This behavior is by design.
Modification Type: | Major | Last Reviewed: | 11/1/2001 |
---|
Keywords: | kbprb KB163396 |
---|
|