From 93fa32b1e048cb50e1bb26b59150a064fb8b8e56 Mon Sep 17 00:00:00 2001 From: Tomaz Zupan Date: Sat, 17 Aug 2002 19:12:12 +0000 Subject: [PATCH] 2002-08-17 21:05 UTC+0100 Tomaz Zupan --- harbour/ChangeLog | 8 ++++++++ harbour/contrib/odbc/odbc.c | 12 ++++++++++++ harbour/contrib/odbc/todbc.prg | 20 ++++++++++++++------ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index c09f2fe8b8..2901f6a6b1 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,14 @@ 2002-12-01 23:12 UTC+0100 Foo Bar */ +2002-08-17 21:05 UTC+0100 Tomaz Zupan + * contrib/odbc/odbc.c + + Added SQLConnect function + * contrib/odbc/todbc.prg + + Method new() now accepts additional parameters username and password. + If TODBC:new() is called with username and password, it uses + SQLConnect insted of SQLDriverConnect to establish ODBC conenction. + 2002-08-15 17:40 UTC-0300 Luiz Rafael Culik * source/rtl/memoedit.prg * When User function is Defined , Make ALT+W key exit the Editing windows if not redefined inside the UDF function diff --git a/harbour/contrib/odbc/odbc.c b/harbour/contrib/odbc/odbc.c index d7ef290ea4..6f0575816c 100644 --- a/harbour/contrib/odbc/odbc.c +++ b/harbour/contrib/odbc/odbc.c @@ -118,6 +118,18 @@ HB_FUNC( SQLDRIVERC ) /* HB_SQLDRIVERCONNECT( hDbc, @ cConnectString, lPrompt ) hb_storc( bBuffer1 , 3 ); hb_retni( ret ); } +HB_FUNC( SQLCONNECT ) /* HB_SQLCONNECT( hDbc, @ cServerName, nNameLength1, @cUserName, nNameLength2, @cPassword, nNameLength3 ) --> nRetCode */ +{ + RETCODE ret = SQLConnect( ( HDBC ) hb_parnl( 1 ), + hb_parc( 2 ), + strlen(hb_parc(2)), + hb_parc( 3 ), + strlen(hb_parc(3)), + hb_parc( 4 ), + strlen(hb_parc(4))); + + hb_retni( ret ); +} HB_FUNC( SQLDISCONN ) /* HB_SQLDISCONNECT( hDbc ) --> nRetCode */ { diff --git a/harbour/contrib/odbc/todbc.prg b/harbour/contrib/odbc/todbc.prg index 404d681de3..c535cda3e8 100644 --- a/harbour/contrib/odbc/todbc.prg +++ b/harbour/contrib/odbc/todbc.prg @@ -155,10 +155,13 @@ METHOD SQLErrorMessage() CLASS TODBC RETURN( "Error " + cErrorClass + " - " + cErrorMsg ) // New instance of TODBC -METHOD New( cODBCStr ) CLASS TODBC - +METHOD New( cODBCStr, cUserName, cPassword ) CLASS TODBC LOCAL xBuf LOCAL nRet + + IF cUserName != NIL + DEFAULT cPassword TO "" + ENDIF // WHILE .t. ::cODBCStr := cODBCStr @@ -183,9 +186,15 @@ METHOD New( cODBCStr ) CLASS TODBC SQLAllocCo( ::hEnv, @xBuf ) // Allocates SQL Connection ::hDbc := xBuf - - SQLDriverC( ::hDbc, ::cODBCStr, @xBuf ) // Connects to Driver - ::cODBCRes := xBuf + + IF cUserName == NIL + SQLDriverC( ::hDbc, ::cODBCStr, @xBuf ) // Connects to Driver + ::cODBCRes := xBuf + ELSE + IF .not. ( (nRet := SQLConnect( ::hDbc, cODBCStr, cUserName, cPassword)) == SQL_SUCCESS ) + //TODO: Some error here + ENDIF + ENDIF // ENDDO RETURN ( Self ) @@ -289,7 +298,6 @@ METHOD Open() CLASS TODBC // Sets the Dataset state to active and put cursor on first record ::Active := .t. - ::First() EXIT