by russimicro » Sat Apr 17, 2010 4:21 pm
#include "sqlrdd.ch"
#include "mysql.ch"
#define RECORDS_IN_TEST 1000
#define SQL_DBMS_NAME 17
#define SQL_DBMS_VER 18
REQUEST SQLRDD, SR_MYSQL
/*------------------------------------------------------------------------*/
Function Main( cDSN, lLog )
local apCode, oSqlCon , oRddCon , oSqlRdd, oSqlWeb
local nCnn, i
//***INICIO CONEXION CON DB CON POSTGRES SQLRDD
? "Connecting to database SQLRDD...postgres"
cConnString1 := "PGS=192.168.2.11;UID=user_comparta;PWD=123;DTB=xhb"
oSqlRdd := ConectaSqlRdd(cConnString1)
SR_GetConnection( oSqlRdd )
? "Connected to SQLRDD :", SR_GetConnectionInfo(, SQL_DBMS_NAME ), SR_GetConnectionInfo(, SQL_DBMS_VER )
USE "TEST_TABLE" EXCLUSIVE VIA "SQLRDD" NEW ALIAS TEST
BROWSE()
// CODIFIQUE IGUAL QUE CON DBF...
//***FIN CONEXION CON DB CON POSTGRES
*/
//***INICIO CONEXION CON DB CON MYSQL NO SQLRDD
? "Connecting to database NO SQLRDD...mysql"
cConnString2 := "MySQL=200.00.888.121;UID=user_zerus;PWD=123;DTB=db_zerus"
oSqlWeb := ConectaSqlRdd(cConnString2)
oSql := SR_GetConnection( oSqlWeb )
? "Connected to NO SQLRDD :", SR_GetConnectionInfo(, SQL_DBMS_NAME ),SR_GetConnectionInfo(, SQL_DBMS_VER )
apCode := SR_SQLParse( "SELECT * FROM personas WHERE ccodigocli = ?")
cSql := SR_SQLCodeGen( apCode,{"1"}, oSql:nSystemID )
osql:exec(cSql,,.t.,,'arquivo.dbf','temp') // ...ok
//aRet:={}
//osql:exec(cSql,,.t.,@aret) // ..OK
// alert( len(aRet) )
// use (csql) shared new alias temp via "SQLRDD" // ...ok
sele temp
browse(5,5,20,75)
apCode := SR_SQLParse( "UPDATE personas SET cnombrecli = ? WHERE ccodigocli = ?")
oSql := SR_GetConnection( oSqlWeb )
cSql := SR_SQLCodeGen( apCode,{"la juana VALENTINA 4","1"}, oSql:nSystemID )
osql:exec(cSql)
temp->( DBCOMMIT() )
TEMP->( DBGOTOP() )
DO WHILE TEMP->( !EOF() )
? TEMP->CNOMBRECLI
TEMP->( DBSKIP() )
ENDDO
INKEY(0)
CLOSE ALL
// CODIFIQUE IGUAL QUE CON DBF...
//***FIN CONEXION CON DB CON MYSQL NO SQLRDD
Return NIL
*******************************************************************************************
FUNCTION ConectaSqlRdd(cConnString)
LOCAL nDetected
nDetected := DetectDBFromDSN( cConnString )
If nDetected > SYSTEMID_UNKNOW
oCon := SR_AddConnection( nDetected, cConnString )
ELSE
alert("Error de conexi¢n")
return -1
EndIf
If oCon < 0
alert("Error al conectarse a la base de datos de MySql : " )
CLS
Quit
EndIf
return oCon
**************************************************
#include "connect.prg"
/* IMPORTANT: THIS FILE IS NOT TO BE USED DIRECTLY. YOU SHOULD INCLUDE IT IN PROPER APPLICATION PRG FILE
AS SHOWN IN DEMO01.PRG, PARSER2.PRG, MEMO.PRG, ETC., AND CALL CONNECT() FUNCTION.
*/
/*
* SQLRDD connection
* Sample applications connect routine
* Copyright (c) 2005 - Marcelo Lombardo <lombardo@uol.com.br>
* All Rights Reserved
*/
#include "pgs.ch" // Needed if you plan to use native connection to Postgres
#include "mysql.ch" // Needed if you plan to use native connection to MySQL
#include "oracle.ch" // Needed if you plan to use native connection to Oracle
#include "firebird.ch" // Needed if you plan to use native connection to Firebird
REQUEST SQLRDD // SQLRDD should be linked in
REQUEST SR_ODBC // Needed if you plan to connect with ODBC
REQUEST SR_PGS // Needed if you plan to use native connection to Postgres
REQUEST SR_MYSQL // Needed if you plan to use native connection to MySQL
REQUEST SR_ORACLE // Needed if you plan to use native connection to Oracle
REQUEST SR_FIREBIRD // Needed if you plan to use native connection to Firebird
REQUEST DBFNTX
REQUEST DBFCDX
REQUEST DBFFPT
REQUEST DBFDBT
/*------------------------------------------------------------------------*/
Function Connect( cDatabase )
local nCnn, nDrv, cDriver, nOpt, nDetected, hIniFile, aKeys, nKey, cConnString
local oldScreen, hDsn
SetMode( 35, 80 )
hIniFile := HB_ReadIni( "sqlrdd.ini", .F.,,.F. ) // Read ini file in a hash table
If hIniFile == NIL
? "Could not read from sqlrdd.ini"
Quit
EndIf
If cDatabase == NIL
aKeys := HGetKeys( hIniFile )
If len(aKeys) == 0
? "No connections available in sqlrdd.ini"
Quit
ElseIf len(aKeys) == 1
nKey := 1
Else
clear screen
@5,1 say PadC( "Choose connection option", 80 )
nKey := achoice( 5, 20, 22, 60, aKeys )
clear screen
If nKey == 0
? "No connection selected"
Quit
EndIf
EndIf
hDsn := HGetValueAt( hIniFile, nKey )
If !"CONNSTRING" IN hDsn
? "ConnString not found in " + aKeys[nKey]
Quit
EndIf
Else
If ! cDatabase IN hIniFile
? "Connection [" + cDatabase + "] not found in sqlrdd.ini"
Quit
EndIf
hDsn := hIniFile[ cDatabase ]
If !"CONNSTRING" IN hDsn
? "ConnString not found in " + cDatabase
Quit
EndIf
EndIf
cConnString := hDsn[ "CONNSTRING" ]
nDetected := DetectDBFromDSN( cConnString )
If nDetected > SYSTEMID_UNKNOW
? "Connecting to", cConnString
nCnn := SR_AddConnection( nDetected, cConnString )
Else
clear screen
nOpt := Alert( "Please, select connection type", { "ODBC", "Postgres", "MySQL", "Oracle", "Firebird" } )
If nOpt > 0
nCnn := SR_AddConnection( If( nOpt = 1, CONNECT_ODBC, if( nOpt = 2, CONNECT_POSTGRES, if( nOpt = 3, CONNECT_MYSQL, if( nOpt = 4, CONNECT_ORACLE, CONNECT_FIREBIRD ) ) ) ), cConnString )
Else
? "No connection type selected"
Quit
EndIf
EndIf
/* returns the connection handle or -1 if it fails */
If nCnn < 0
? "Connection error. See sqlerror.log for details."
Quit
EndIf
Return .T.
/*------------------------------------------------------------------------*/