Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
StrDup returns a pointer to the duplicate of a source VFP string
Creating a unique filename based on existing filename
DiskFreeSpace class
Retrieving the rectangle area where the mouse cursor is confined
Using ActiveX control for adding a menu directly to a FoxPro MDI form
Using the CopyFile
Who owns the Windows Clipboard
Winsock: creating a socket that is bound to a specific service provider
Winsock: how to retrieve the protocol information corresponding to a protocol number
Accessing the list of Windows Recent Documents
Creating hash values for the list of names
Current System information
Enumerating connections made to a shared resource for the local computer (WinNT only)
How to make the caption of a VFP application flashing in the Windows task bar
Using IsChild() for testing ThisForm.ShowWindow property
Creating two-byte hashes for a list of URLs
Displaying all TCP connections for the local system
Enumerating Processes -- Win9*
GetFileOwner - Get the owner of an NTFS file
Obtaining physical parameters for a drive: sectors, clusters, cylinders...
Retrieving statistics for the TCP protocol running on the local computer
Using an Event Object. Part B: running an application responding to events
Displaying the color palette stored in an image file
Extracting the name and extension parts of a path string
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: 139  
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.226.5.29)
3.7 hrs.Function: 'GetAclInformation'
Function group: 'Security'
 Function: 'InternetCrackUrl'
Function group: 'Internet Functions (WinInet)'
Google
Advertise here!