Thor TWEeT #10: IntellisenseX: Field Names for SQL Tables
IntellisenseX now supplies field names for your SQL tables, as shown in the following example:
What your are seeing is a dropdown list of field names for an SQL table named “Terms”. It may occur to you that this looks exactly like the list from a VFP table. You would be completely correct, as IntellisenseX now gives you field lists forboth FoxPro tables and SQL Tables, and both are accessed the same way.
You need follow only a few steps to activate this:
- Open the Thor Configuration form
- Go to the Options page
- Click on “Opening Tables” on the left
- Enter your connection string on the right
If you read no further, you have all you need to know to get started using IntellisenseX on SQL tables; what remains in this article is a discussion of the finer points.
IntellisenseX recognizes aliases within an SQL statement
As shown below, aliases within an SQL statement are handled as desired.
But something unexpected will occur because you will probably refer to the aliases in the list of fields, at the beginning of your SQL statement, before you have specified the aliases. The way around this is to create your statement in sort of an inside-out fashion, like this:
How does this work, anyway?
When you invoke IntellisenseX, it goes through a lot of hoops to determine whether the name immediately before the dot could refer to an object or an open table/cursor/view. If none of those apply, it then tries to do you a favor and open the table/view for you. (This has been true from day one).
What has been added is that if you supply a connection string (as previously noted), it will also try to read at least the structure from your SQL table. In doing so, it creates a cursor (with “_SQL_” prefixed to the name of your SQL table) which can be used by IntellisenseX. (See also the discussion below about how this applies to other tools, such as Super Browse.)
What is that “SQL Dictionary” referred to on the options page?
An alternative method to using a connection string (which accesses the table each time) is to create a local VFP table with a list of all fields from all your SQL tables. The statement below creates a table with the desired structure. (You can expand the first two character fields as needed.)
Create Table MySQLTableName ( ;
XTABNAME C(40), ;
FIELD_NAME C(30), ;
FIELD_TYPE C(1), ;
FIELD_LEN N(3), ;
FIELD_DEC N(3))
What if a single connection string is not enough?
There is no provision currently to make it easy to switch between different SQL databases, which would require multiple connection strings. However, it is possible to change the connection string programmatically, by executing the following:
Execscript(_Screen.cThorDispatcher, 'Opening Tables', 'Connection String', NewConnectionString)
and this could be used in a Thor tool to select which database to read from.
Does any of this apply to other tools?
There are a number of other tools (most notable Super Browse) which use the same sub-routine for opening tables as is used by IntellisenseX. Thus, if you use Super Browse to help you create a list of fields for an SQL statement, you can click on the name of the table (be it a VFP table or SQL table) and execute Super Browse and away you will go.