Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Enumerating print processors and supporting data types installed on the specified server
How to perform Base64 encoding/decoding using Cryptography API Functions
How to read email messages using Simple MAPI
Retrieving graphic capabilities of your display
Creating a directory on the FTP
Enumerating the subkeys for a given registry key
How to release and renew a lease on an IP address previously obtained through Dynamic Host Configuration Protocol (DHCP)
How to view icons stored in executable files (Icon Viewer) - II
How to view system icons for the classes installed on the local machine
Reading metrics for the currently selected font
Retrieving the command line for the VFP session
Retrieving various system metrics
Using the Semaphore object to allow only one instance of VFP application running
FindText -- the hopeless and useless Common Dialog
GDI+: printing vertical text on VFP reports via generated images (VFP9)
How to build UDP responder
How to find which fonts Windows uses for drawing captions, menus and message boxes
Obtaining a handle to the desktop associated with the calling thread
Removing FTP directory
StrDup returns a pointer to the duplicate of a source VFP string
Using the CopyFile
GDI+: retrieving list of available image encoders and image decoders
Opening access to the Microsoft Internet functions for the application
Passing data records between VFP applications via the Clipboard
The SQLGetProp() creates a bridge between Visual FoxPro and the ODBC API

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Before you begin:
A native VFP functions SQLGetProp() returns a valid connection handle that can be used with appropriate ODBC API functions whenever they require a connection handle as a parameter.

hConn = SQLGetProp (myconn, "ODBChdbc")

Practically it means that you have all ODBC API functionality available for data connections established in Visual FoxPro through the native SQLConnect() function.
 
#DEFINE SQL_SUCCESS                   0
#DEFINE SQL_SUCCESS_WITH_INFO         1
#DEFINE SQL_HANDLE_DBC                2
 
#DEFINE SQL_DRIVER_NAME               6
#DEFINE SQL_DRIVER_ODBC_VER           77
#DEFINE SQL_DRIVER_VER                7
#DEFINE SQL_DM_VER                    171
#DEFINE SQL_DATA_SOURCE_NAME          2
#DEFINE SQL_SERVER_NAME               13
#DEFINE SQL_DATABASE_NAME             16
#DEFINE SQL_DBMS_NAME                 17
#DEFINE SQL_DBMS_VER                  18
#DEFINE SQL_USER_NAME                 47
#DEFINE SQL_CREATE_TABLE              132
#DEFINE SQL_PROCEDURES                21
#DEFINE SQL_UNION                     96
#DEFINE SQL_MAX_COLUMNS_IN_TABLE      101
#DEFINE SQL_MAX_TABLE_NAME_LEN        35
#DEFINE SQL_IDENTIFIER_QUOTE_CHAR     29
#DEFINE SQL_KEYWORDS                  89
#DEFINE SQL_SPECIAL_CHARACTERS        94
 
PRIVATE hVfpConn, hConn
 
* establishing an ODBC connection using regular VFP way
hVfpConn = SQLConnect("ECDCMusic")
IF hVfpConn <= 0
    = MessageB ("Unable to establish an ODBC connection.")
    RETURN
ENDIF
 
* retrieving internal ODBC connection handle
* that is valid to access ODBC API functions
hConn = SQLGetProp (hVfpConn, "ODBChdbc")
 
CREATE CURSOR csResult (infotype C(30), datatype C(1),;
    infovalue C(254), largevalue M)
 
= AddInfo ("Data source name",        SQL_DATA_SOURCE_NAME,      "C")
= AddInfo ("Driver name",             SQL_DRIVER_NAME,           "C")
= AddInfo ("Driver version",          SQL_DRIVER_VER,            "C")
= AddInfo ("ODBC version",            SQL_DRIVER_ODBC_VER,       "C")
= AddInfo ("Driver manager version",  SQL_DM_VER,                "C")
= AddInfo ("Server name",             SQL_SERVER_NAME,           "C")
= AddInfo ("Database name",           SQL_DATABASE_NAME,         "C")
= AddInfo ("DBMS name",               SQL_DBMS_NAME,             "C")
= AddInfo ("DBMS version",            SQL_DBMS_VER,              "C")
= AddInfo ("User name",               SQL_USER_NAME,             "C")
= AddInfo ("CREATE TABLE support",    SQL_CREATE_TABLE,          "I")
= AddInfo ("SQL procedures support",  SQL_PROCEDURES,            "C")
= AddInfo ("UNION support",           SQL_UNION,                 "I")
= AddInfo ("Max table name",          SQL_MAX_TABLE_NAME_LEN,    "I")
= AddInfo ("Max cols in table",       SQL_MAX_COLUMNS_IN_TABLE,  "I")
= AddInfo ("Identifier quoting char", SQL_IDENTIFIER_QUOTE_CHAR, "C")
= AddInfo ("Keywords",                SQL_KEYWORDS,              "M")
= AddInfo ("Special characters",      SQL_SPECIAL_CHARACTERS,    "C")
 
= SQLDisconnect(hVfpConn)
 
GO TOP
BROW NORMAL NOWAIT
* end of main
 
FUNCTION AddInfo (lcInfoType, lnInfoType, lcDataType)
    LOCAL lcResult
 
    DO CASE
    CASE lcDataType = "C"
        lcResult = GetInfoStr(lnInfoType)
        INSERT INTO csResult (infotype, datatype, infovalue);
            VALUES (lcInfoType, lcDataType, lcResult)
 
    CASE lcDataType = "M"
        lcResult = GetInfoStr(lnInfoType)
        INSERT INTO csResult (infotype, datatype, infovalue, largevalue);
            VALUES (lcInfoType, lcDataType, "See memo field", lcResult)
 
    CASE lcDataType = "I"
        lcResult = GetInfoInt(lnInfoType, @lcDataType)
        INSERT INTO csResult (infotype, datatype, infovalue);
            VALUES (lcInfoType, lcDataType, lcResult)
    ENDCASE
RETURN
 
FUNCTION GetInfoInt (lnInfoType, lcDataType)
* returns a numeric parameter
    DECLARE SHORT SQLGetInfo IN odbc32;
        INTEGER ConnectionHandle, INTEGER InfoType,;
        INTEGER @InfoValuePtr, INTEGER BufLen, INTEGER @StrLenPtr
 
    LOCAL lnResult, lnBufLen
    STORE 0 TO lnResult, lnBufLen
    = SQLGetInfo (hConn, lnInfoType, @lnResult, 4, @lnBufLen)
 
    DO CASE
    CASE lnBuflen = 0
        RETURN "#error#"
    CASE lnBuflen = 2
        lcDataType = "S"
        RETURN LTRIM(STR(BitAnd(65535, lnResult)))
    CASE lnBuflen = 4
        lcDataType = "I"
        RETURN LTRIM(STR(lnResult))
    OTHER
        lcDataType = LTRIM(STR(lnBuflen))
        RETURN "#unknown type#"
    ENDCASE
 
FUNCTION GetInfoStr (lnInfoType)
* returns a string parameter
    DECLARE SHORT SQLGetInfo IN odbc32;
        INTEGER ConnectionHandle, INTEGER InfoType,;
        STRING @InfoValuePtr, INTEGER BufLen, INTEGER @StrLenPtr
 
    LOCAL lcBuffer, lnBufLen
    lcBuffer = REPLI(Chr(0), 4096)
    lnBufLen = 0
    = SQLGetInfo (hConn, lnInfoType, @lcBuffer, Len(lcBuffer), @lnBufLen)
RETURN Iif(lnBufLen>0, Left(lcBuffer, lnBufLen), "#error#")
 
 

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
4381 bytes  
Created: 2002-03-23 10:08:58  
Modified: 2002-03-23 10:24:27  
Visits in 7 days: 104  
Listed functions:
SQLGetInfo
Printer friendly API declarations
My comment:
The application connects to an ODBC data source using regular SQLConnect(). Then the connection handle is retrieved with the SQlGetProp() function. And this connection handle is the real one created behind the scene by Visual FoxPro itself with the SQLAllocHandle.

Notice that the SQLGetProp() also provides a valid statement handle.

Definitely the bridge is not too far.
Word Index links for this example:
Translate this page:
  Spanish    Portuguese    German    French    Italian  
FreeTranslation.com offers instant, free translations of text or web pages.
User Contributed Notes:
There are no notes on this subject.


Copyright © 2001-2013 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

Privacy policy
Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (184.72.91.94)
12.01 hrs.
 Function: 'PathIsRoot'
Function group: 'Shell Lightweight Utility APIs -- Path Functions'
 Example: 'Retrieving list of available disk drives'
18.04 hrs.Function: 'CreateDirectory'
Function group: 'File Management'
 Function: 'GdipCreateFromHDC2'
Function group: 'GDI+ Graphics'
18.9 hrs.Example: 'Custom GDI+ class'
Language: 'Visual FoxPro'
 Function: 'Escape'
Function group: 'Printing and Print Spooler'
21.9 hrs.Example: 'Minimizing all running applications'
 Example: 'Validating the heap of the calling process'
22.59 hrs.Example: 'Testing serial ports'
Google
Advertise here!