Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to change display settings: screen resolution, screen refresh rate
Adding and deleting Scheduled Tasks using NetScheduleJob API functions
Custom GDI+ class
Converting Unicode data from the Clipboard to a character string using a given code page
Capturing keyboard activity of another application with the Raw Input API (VFP9)
Enumerating data formats currently available on the clipboard
Winsock: sending email messages (SMTP, port 25)
Custom FTP Class for Visual FoxPro application
Detecting changes in connections to removable drives (VFP9)
How to download a file from the FTP server using FtpGetFile
Splash Screen for the VFP application
Mapping and disconnecting network drives
Enumerating raw input devices attached to the system (keyboard, mouse, human interface device)
How to convert a bitmap file to monochrome format (1 bpp)
Custom HttpRequest class (WinHTTP)
Custom HttpRequest class (WinINet)
How to activate Windows Calculator
Establishing connection using the SQLDriverConnect
GDI+: copying to the Clipboard (a) image of active FoxPro window/form, (b) image file
Using Font and Text functions
Displaying bitmap using the AlphaBlend function
Using EnumPrinters function to enumerate locally installed printers
Using WM_COPYDATA for interprocess communication (VFP9)
Extensible Storage Engine class library
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: 129  
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 (107.21.186.38)
3.83 hrs.Example: 'How to write and read Window Properties for the specified window'
7.98 hrs.Function: 'CryptGetProvParam'
 Function: 'GetNativeSystemInfo'
10.06 hrs.Example: 'How to assemble an array of strings and pass it to external function'
10.42 hrs.Example: 'Simple Window Viewer'
 Example: 'Drawing a window caption using the DrawCaption routine'
14.99 hrs.Gallery
Page 9
18.54 hrs.Function: 'GetFullPathName'
1 day(s)Example: 'Pocket PC: custom RAPI class for operating with the Object Store Databases'
 Function: 'CloseDesktop'
Function group: 'Window Station and Desktop'
Google
Advertise here!