From 34c4ff9b504a72ffc808fd00b61172444351f04a Mon Sep 17 00:00:00 2001 From: Maurilio Longo Date: Mon, 30 Oct 2000 17:52:56 +0000 Subject: [PATCH] 2000-10-30 18:51 GMT+2 Maurilio Longo --- harbour/ChangeLog | 4 ++++ harbour/contrib/mysql/mysql.c | 8 ++++++- harbour/contrib/mysql/tmysql.prg | 39 +++++++++++++++++++++---------- harbour/contrib/mysql/tsqlbrw.prg | 3 +-- 4 files changed, 39 insertions(+), 15 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index ad446a1846..49cc32f828 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,7 @@ +2000-10-30 18:51 GMT+2 Maurilio Longo + * contrib/mysql/* + * little changes chasing a bug :-| + 2000-10-27 18:05 GMT+2 Maurilio Longo * contrib/mysql/tmysql.prg * contrib/mysql/tsqlbrw.prg diff --git a/harbour/contrib/mysql/mysql.c b/harbour/contrib/mysql/mysql.c index cb692c32b1..ce583d45e0 100644 --- a/harbour/contrib/mysql/mysql.c +++ b/harbour/contrib/mysql/mysql.c @@ -55,6 +55,8 @@ HB_FUNC(SQLCONNECT) // MYSQL *mysql_real_connect(MYSQL*, char * host, char * use { MYSQL * mysql = NULL; + HB_TRACE(HB_TR_DEBUG, ("mysql_real_connect(%s, %s, %s)", _parc(1), _parc(2), _parc(3))); + #if MYSQL_VERSION_ID > 32200 /* from 3.22.x of MySQL there is a new parameter in mysql_real_connect() call, that is char * db which is not used here */ @@ -77,12 +79,16 @@ HB_FUNC(SQLCLOSE) // void mysql_close(MYSQL *mysql) HB_FUNC(SQLSELECTD) // int mysql_select_db(MYSQL *, char *) { - _retnl(mysql_select_db((MYSQL *)_parnl(1), _parc(2))); + HB_TRACE(HB_TR_DEBUG, ("mysql_select_db(%lu, %s)", _parnl(1), _parc(2))); + + _retnl((long) mysql_select_db((MYSQL *)_parnl(1), _parc(2))); } HB_FUNC(SQLQUERY) // int mysql_query(MYSQL *, char *) { + HB_TRACE(HB_TR_DEBUG, ("mysql_query(%lu, %s)", _parnl(1), _parc(2))); + _retnl((long) mysql_query((MYSQL *)_parnl(1), _parc(2))); } diff --git a/harbour/contrib/mysql/tmysql.prg b/harbour/contrib/mysql/tmysql.prg index 829abb2883..0270f350b0 100644 --- a/harbour/contrib/mysql/tmysql.prg +++ b/harbour/contrib/mysql/tmysql.prg @@ -282,30 +282,45 @@ METHOD New(nSocket, cQuery) CLASS TMySQLQuery local nI, aField, rc - ::aFieldStruct := {} ::nSocket := nSocket ::cQuery := cQuery - ::nCurRow := 1 + ::lError := .F. + ::aFieldStruct := {} + ::nCurRow := 1 + ::nResultHandle := nil + ::nNumFields := 0 + ::nNumRows := 0 if (rc := sqlQuery(nSocket, cQuery)) == 0 // save result set - ::nResultHandle := sqlStoreR(nSocket) - ::nNumRows := sqlNRows(::nResultHandle) - ::nNumFields := sqlNumFi(::nResultHandle) + if (::nResultHandle := sqlStoreR(nSocket)) > 0 - for nI := 1 to ::nNumFields + ::nNumRows := sqlNRows(::nResultHandle) + ::nNumFields := sqlNumFi(::nResultHandle) - aField := sqlFetchF(::nResultHandle) - AAdd(::aFieldStruct, aField) + for nI := 1 to ::nNumFields - next + aField := sqlFetchF(::nResultHandle) + AAdd(::aFieldStruct, aField) + next + + else + // Should query have returned rows? (Was it a SELECT like query?) + + if (::nNumFields := sqlNumFi(nSocket)) == 0 + + // Was not a SELECT so reset ResultHandle changed by previous sqlStoreR() + ::nResultHandle := nil + + else + ::lError := .T. + + endif + endif else - ::nResultHandle := nil - ::nNumFields := 0 - ::nNumRows := 0 ::lError := .T. endif diff --git a/harbour/contrib/mysql/tsqlbrw.prg b/harbour/contrib/mysql/tsqlbrw.prg index 055d9771c9..52275ce2c9 100644 --- a/harbour/contrib/mysql/tsqlbrw.prg +++ b/harbour/contrib/mysql/tsqlbrw.prg @@ -148,8 +148,7 @@ METHOD New(nTop, nLeft, nBottom, nRight, oServer, oQuery, cTable) CLASS TBrowseS ::oQuery := oQuery // Let's get a row to build needed columns - ::oCurRow := ::oQuery:GetRow() - ::oQuery:Skip(-1) + ::oCurRow := ::oQuery:GetRow(1) // positioning blocks ::SkipBlock := {|n| ::oCurRow := Skipper(@n, ::oQuery), n }