Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Using vendor-neutral SQL constructs
Winsock: retrieving Web pages using sockets (HTTP, port 80)
Transparent Menu Class (requires VFP9)
Using Video Capture: displaying on FoxPro form frames and previewing video obtained from a digital camera
Displaying dimmed window behind VFP top-level form
Enumerating network resources
How to adjust monitor brightness (Vista, monitor with DDC support)
How to copy the image of a form to the Clipboard using Bitmap API functions
Adding an ODBC data source with the SQLConfigDataSource; use automatic or interactive mode
Dragging files from Explorer window and dropping them on FoxPro control (requires VFP9)
How to disable the Windows Clipboard (VFP9)
Winsock: retrieving the standard host name and IP address for the local machine
How to block the PrintScreen key
Downloading files from the FTP server using InternetReadFile
How to remove a directory that is not empty
Loading a string resource from an executable file
Reading and setting the priority class values for the current process and thread
Retrieving the interface–to–IP address mapping table
How to ping a remote site using IP Helper API calls
Reading entries from Event logs
Using the GradientFill function
How to extract frames from AVI files
Enumerating global and local group accounts on a server (WinNT/XP/2K)
Enumerating ports that are available for printing on a specified server
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: 149  
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 (54.234.231.49)
4 sec.Function: 'GetClassInfoEx'
7.85 hrs.Example: 'Retrieving a universal form for the drive-based path for a network resource'
 Function: 'SystemParametersInfo'
Function group: 'System Information'
10.78 hrs.Example: 'Creating an Open dialog box to specify the drive, directory, and name of a file to open (Shell32 version)'
11.76 hrs.Example: 'Windows Shell Icons displayed and exported to ICO files (Vista)'
 Example: 'Storing content of the Clipboard to a bitmap file'
13.39 hrs.Example: 'Pocket PC: retrieving data from the Contacts Database'
13.4 hrs.Example: 'List of addresses in the AutoDial mapping database'
Google
Advertise here!