Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Storing the environment strings in cursor
Changing file attributes
Comparing dimensions of the VFP main window with _SCREEN properties
Enumerating global and local group accounts on a server (WinNT/XP/2K)
Enumerating Volumes and Volume Mounting Points (NTFS)
Retrieving list of all active RAS connections
Testing an ODBC connection for supporting specific functionality
Using InternetGoOnline function
Displaying the drive type value
Drawing standard Windows icons
Finding the path to the VFP executable running
GDI+: printing image file
Number of clipboard formats available
Reading VFP settings from the Windows Registry
Yet another modal dialog: now HTML-based
Enumerating MIDI output devices
Enumerating print processors and supporting data types installed on the specified server
GDI+: Storing DLL icon resources in image files
How to save registry key including its subkeys and values to a file
Printing text on the client area of the main VFP window
Reading and setting system access privileges for the current process
Retrieving information about MS-DOS device names using QueryDosDevice (WinNT only)
Retrieving information about the main VFP window
Retrieving list of available disk drives
Using vendor-neutral SQL constructs

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:
The vendor-neutral constructs also known as "escape clauses" or "escape sequences" are useful for avoiding proprietary SQL syntax.
 
DO decl
 
#DEFINE SQL_HANDLE_DBC         2
#DEFINE SQL_SUCCESS            0
#DEFINE SQL_SUCCESS_WITH_INFO  1
 
PRIVATE hEnv, hConn
STORE 0 TO hEnv, hConn
 
* parameters being passed to initiate a connection: DSN, user, password
* replace them with connection parameters valid for your computer
 
*IF Not GetConnect("sqlserver", "sa", "")
*IF Not GetConnect("mysql", "sa", "")
IF Not GetConnect("ECDCMusic", "sa", "")
    RETURN
ENDIF
 
* samples of SQL commands with _Escape_ Sequences (escape clauses)
LOCAL lcSQL
lcSQL = [SELECT * FROM Titles WHERE pubdate < {d "1997-04-27"}]
*lcSQL = [SELECT {fn CONCAT({fn CONCAT(au_lname, ", ")}, au_fname)} FROM Authors]
*lcSQL = [SELECT {fn UCASE(Name)} FROM Customers]
 
* returns the SQL string as modified by the driver
* Notice: does not execute the SQL statement
? GetNativeSQL(lcSQL)
 
DO GetDisconnect
* end of main
 
FUNCTION GetNativeSQL (lcSQL)
    LOCAL lcBuffer, lnBufSize, lnResult
    lnBufSize = 4096
    lcBuffer = Repli(Chr(0), lnBufSize)
 
    lnResult = SQLNativeSql (hConn, lcSQL, Len(lcSQL),;
        @lcBuffer, lnBufSize, @lnBufSize)
    IF INLIST(lnResult, SQL_SUCCESS, SQL_SUCCESS_WITH_INFO)
        RETURN Left(lcBuffer, lnBufSize)
    ELSE
        RETURN "#error#"
    ENDIF
 
FUNCTION GetConnect (lcServer, lcUser, lcPwd)
    = SQLAllocEnv(@hEnv)
    IF hEnv = 0
        = MessageB ("Unable to allocate ODBC environment")
        RETURN .F.
    ENDIF
 
    = SQLAllocHandle (SQL_HANDLE_DBC, hEnv, @hConn)
    IF hConn = 0
        = MessageB ("Unable to allocate ODBC connection handle")
        RETURN .F.
    ENDIF
 
    LOCAL lnResult
    lnResult = SQLConnect32 (hConn, lcServer, Len(lcServer),;
        lcUser, Len(lcUser), lcPwd, Len(lcPwd))
 
    IF INLIST(lnResult, SQL_SUCCESS, SQL_SUCCESS_WITH_INFO)
        RETURN .T.
    ELSE
        = MessageB ("Unable to connect to the [" + lcServer + "]")
        RETURN .F.
    ENDIF
 
PROCEDURE GetDisconnect
    IF hConn <> 0
        = SQLDisconnect32 (hConn)
        = SQLFreeHandle (SQL_HANDLE_DBC, hConn)
    ENDIF
 
    IF hEnv <> 0
        = SQLFreeEnv(hEnv)
    ENDIF
RETURN
 
PROCEDURE decl
    DECLARE SHORT SQLAllocEnv IN odbc32 INTEGER @env
    DECLARE SHORT SQLFreeEnv IN odbc32 INTEGER env
 
    DECLARE SHORT SQLFreeHandle IN odbc32;
        INTEGER HandleType, INTEGER Handle
 
    DECLARE SHORT SQLAllocHandle IN odbc32;
        INTEGER HandleType, INTEGER InputHandle,;
        INTEGER @OutputHandlePtr
 
    DECLARE SHORT SQLConnect IN odbc32 AS SQLConnect32;
        INTEGER ConnectionHandle,;
        STRING ServerName, INTEGER NameLength1,;
        STRING UserName, INTEGER NameLength2,;
        STRING Authentication, INTEGER NameLength3
 
    DECLARE SHORT SQLDisconnect IN odbc32 AS SQLDisconnect32;
        INTEGER ConnectionHandle
 
    DECLARE SHORT SQLNativeSql IN odbc32;
        INTEGER ConnectionHandle, STRING InStatText, INTEGER TextLen1,;
        STRING @OutStatText, INTEGER BufferLen, INTEGER @TextLen2Ptr
 
 

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
2808 bytes  
Created: 2002-03-17 11:12:54  
Modified: 2002-12-30 19:17:56  
Visits in 7 days: 73  
Listed functions:
SQLAllocEnv
SQLAllocHandle
SQLConnect
SQLDisconnect
SQLFreeEnv
SQLFreeHandle
SQLNativeSql
Printer friendly API declarations
My comment:
SQLNativeSql returns the SQL string as modified by the driver. SQLNativeSql does not execute the SQL statement..

Some links on vendor-neutral constructs:
Escape Sequences in ODBC
Step Up to Advanced SQL
Using Interoperable SQL. By Ken North
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.156.140)
4 sec.Example: 'Bitmap Class for Visual FoxPro application'
2.24 hrs.Example: 'How to display the Properties dialog box for a file (ShellExecuteEx)'
 Function: 'GetClipboardOwner'
Function group: 'Clipboard'
4.7 hrs.Example: 'Building a tree of subdirectories for a given path using FindFile functions'
 Function: 'RegEnumKey'
Function group: 'Registry'
5.44 hrs.Function: 'WTSQuerySessionInformation'
Function group: 'Terminal Services'
 Function: 'PathSearchAndQualify'
Function group: 'Shell Lightweight Utility APIs -- Path Functions'
5.76 hrs.Function: 'WinHttpQueryHeaders'
Function group: 'HTTP Functions (WinHTTP)'
 Example: 'Reading the state of mouse buttons within DO WHILE loop'
7.35 hrs.Example: 'Using Font and Text functions'
Google
Advertise here!