Difference between revisions of "SQLCONNECT()"

From Lianjapedia
Jump to: navigation, search
 
 
(11 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
==Purpose==
 
==Purpose==
Connect to a data source
+
Connect to an ODBC data source
 
+
  
 
==Syntax==
 
==Syntax==
SQLCONNECT([<nStatementHandle>])
+
SQLCONNECT(<cDataSourceName> [, <cUserID> [, <cPassword>]])
 
+
SQLCONNECT([<cConnectionName> | <cDataSourceName> [, <cUserID> [, <cPassword>]][, <lShared]])
+
 
+
SQLCONNECT([<cServerDataSource>])
+
 
+
  
 
==See Also==
 
==See Also==
[[CREATE CONNECTION]], [[SQLCANCEL()]], [[SQLCOLUMNS()]], [[SQLCOMMIT()]], [[SQLDISCONNECT()]], [[SQLEXEC()]], [[SQLGETPROP()]], [[SQLMORERESULTS()]], [[SQLPREPARE()]], [[SQLROLLBACK()]], [[SQLSETPROP()]], [[SQLSTRINGCONNECT()]], [[SQLTABLES()]]
+
[[SQLCANCEL()]], [[SQLCOLUMNS()]], [[SQLCOMMIT()]], [[SQLDISCONNECT()]], [[SQLEXEC()]], [[SQLGETPROP()]], [[SQLMORERESULTS()]], [[SQLPREPARE()]], [[SQLROLLBACK()]], [[SQLSETPROP()]], [[SQLSTRINGCONNECT()]], [[SQLTABLES()]], [[SQLTRANSACTION()]]
  
 
==Description==
 
==Description==
The SQLCONNECT() function is used to connect to a data source and return a statement handle for use by other SQL functions.
+
The SQLCONNECT() function is used to connect to an ODBC data source and return a statement handle for use by other SQL functions.
  
If SQLCONNECT() is called without specifying any data source information, the Select a Gateway dialog is displayed allowing an existing gateway definition file (.gtw) to be selected.  Gateway files can be created in Recital Terminal Developer using the CREATE GATEWAY | MODIFY GATEWAY tool.
+
{| class="wikitable" width="100%"
 
+
!width="30%"|Keywords||width="70%"|Description
 
+
{| class="wikitable"
+
!Keywords||Description
+
 
|-
 
|-
|nStatementHandle||The workarea in which a gateway data source is open and to which a new connection should be made.
+
|cDataSourceName||ODBC data source name
|-
+
|}
+
 
+
Or
+
 
+
{| class="wikitable"
+
!Keywords||Description
+
|-
+
|cConnectionName||Existing gateway (.gtw) file
+
|-
+
|cDataSourceName||ODBC data source name (ODBC supported platforms only)
+
 
|-
 
|-
 
|cUserID||Data source login user id
 
|cUserID||Data source login user id
 
|-
 
|-
 
|cPassword||Data source login password
 
|cPassword||Data source login password
|-
 
|lShared||False (.F.) Connection created is not shared (default)
 
True (.T.) Connection created is shared
 
|-
 
|}
 
 
Or
 
 
{| class="wikitable"
 
!Keywords||Description
 
|-
 
|cServerDataSource||ODBC, OLEDB or JDBC server side data source in the format:
 
odbc:odbc_data_source_name_on_server
 
oledb:oledb_connection_string_on_server
 
jdbc:dbc_driver_path_on_server;jdbc:Recital:args
 
 
|-
 
|-
 
|}
 
|}
Line 59: Line 24:
 
====Return values:====
 
====Return values:====
  
{| class="wikitable"
+
{| class="wikitable" width="100%"
!Return Value||Description
+
!width="30%"|Return Value||width="70%"|Description
 
|-
 
|-
|>0||Statement handle to connection
+
|>0||Statement handle to the connection
 
|-
 
|-
 
|&ndash;2||Connection creation error
 
|&ndash;2||Connection creation error
 
|-
 
|-
 
|}
 
|}
 
  
 
==Example==
 
==Example==
 
<code lang="recital">
 
<code lang="recital">
// SQLCONNECT() using the 'Select a Gateway' dialog
+
nStatHand = sqlconnect("mylocal")
nStatHand=SQLCONNECT()
+
// or
 
+
nStatHand = sqlconnect("Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=mydb","myuser","mypass")
// SQLCONNECT(<nStatementHandle>) to an active gateway opened with SQLSTRINGCONNECT()
+
nStatHand=SQLSTRINGCONNECT("mysql@linux1:user1/pass1-database1.tcpip",.T.)
+
if nStatHand < 1
+
  messagebox([Could not connect])
+
else
+
  messagebox([Connected in workarea ]+str(nStatHand,3))
+
  nStatHand2=SQLCONNECT(nStatHand)
+
  if nStatHand2 < 1
+
    messagebox([Could not connect])
+
  else
+
    messagebox([Connected in workarea ]+str(nStatHand2,3))
+
  endif
+
endif
+
 
+
// SQLCONNECT() to an existing Gateway definition file
+
nStatHand = SQLCONNECT("gateway1.gtw",.T.)
+
 
+
// SQLCONNECT() to an ODBC data source
+
nStatHand = SQLCONNECT("SouthWind", "recital", "recital", .T.)
+
 
+
//SQLCONNECT() alternative syntax to an ODBC data source
+
nStatHand = SQLCONNECT("odbc:southwind")
+
 
+
//SQLCONNECT() to an OLEDB data source
+
nStatHand = SQLCONNECT ("oledb:Provider=vfpoledb.1;" + ;
+
"Data Source=C:Data;Collating Sequence=general")
+
 
</code>
 
</code>
  
 
==Products==
 
Recital, Recital Server
 
 
[[Category:Documentation]]
 
[[Category:Documentation]]
 
[[Category:Functions]]
 
[[Category:Functions]]
 
[[Category:SQL]]
 
[[Category:SQL]]
[[Category:Remote Data Connectivity Functions]]
+
[[Category:ODBC Functions]]
 +
[[Category:SQL Functions]]

Latest revision as of 10:18, 31 January 2013

Purpose

Connect to an ODBC data source

Syntax

SQLCONNECT(<cDataSourceName> [, <cUserID> [, <cPassword>]])

See Also

SQLCANCEL(), SQLCOLUMNS(), SQLCOMMIT(), SQLDISCONNECT(), SQLEXEC(), SQLGETPROP(), SQLMORERESULTS(), SQLPREPARE(), SQLROLLBACK(), SQLSETPROP(), SQLSTRINGCONNECT(), SQLTABLES(), SQLTRANSACTION()

Description

The SQLCONNECT() function is used to connect to an ODBC data source and return a statement handle for use by other SQL functions.

Keywords Description
cDataSourceName ODBC data source name
cUserID Data source login user id
cPassword Data source login password

Return values:

Return Value Description
>0 Statement handle to the connection
–2 Connection creation error

Example

nStatHand = sqlconnect("mylocal")
// or
nStatHand = sqlconnect("Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=mydb","myuser","mypass")