From 607eba503311f4adc21e2aecf8b007d493bf3d07 Mon Sep 17 00:00:00 2001 From: Maurilio Longo Date: Sat, 30 Sep 2000 20:23:57 +0000 Subject: [PATCH] 2000-09-30 22:22 GMT+2 Maurilio Longo --- harbour/ChangeLog | 6 +++++ harbour/contrib/mysql/tmysql.prg | 30 ++++++++++++++++-------- harbour/contrib/mysql/tsqlbrw.prg | 38 ++++++++++++++++++++++--------- 3 files changed, 54 insertions(+), 20 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index b842232f53..a7959760c0 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,9 @@ +2000-09-30 22:22 GMT+2 Maurilio Longo + *contrib/mysql/tmysql.prg + ! fixes / changes to work with tsqlbrw.prg + +contrib/mysql/tsqlbrw.prg + * fixes / changes - work in progress. + 2000-09-30 09:50 GMT+3 Alexander Kresin * contrib/mysql/mysql.c * minor change for support of Win32 diff --git a/harbour/contrib/mysql/tmysql.prg b/harbour/contrib/mysql/tmysql.prg index 9a020d5d26..e022034170 100644 --- a/harbour/contrib/mysql/tmysql.prg +++ b/harbour/contrib/mysql/tmysql.prg @@ -98,14 +98,13 @@ METHOD New(aRow, aFStruct, cTableName) CLASS TMySQLRow default cTableName to "" default aFStruct to {} - ::cTable := cTableName - ::aFieldStruct := aFStruct - ::aRow := aRow ::aFieldStruct := aFStruct + ::cTable := cTableName ::aDirty := Array(Len(::aRow)) ::aOldValue := Array(Len(::aRow)) + AFill(::aDirty, .F.) return Self @@ -114,7 +113,14 @@ return Self METHOD FieldGet(nNum) CLASS TMySQLRow if nNum > 0 .AND. nNum <= Len(::aRow) - return ::aRow[nNum] + + // Char fields are padded with spaces since a real .dbf field would be + if ValType(::aRow[nNum]) == "C" + return PadR(::aRow[nNum], ::aFieldStruct[nNum][MYSQL_FS_LENGTH]) + else + return ::aRow[nNum] + endif + endif return nil @@ -125,6 +131,12 @@ METHOD FieldPut(nNum, Value) CLASS TMySQLRow if nNum > 0 .AND. nNum <= Len(::aRow) if Valtype(Value) == Valtype(::aRow[nNum]) .OR. Empty(::aRow[nNum]) + + // if it is a char field remove trailing spaces + if ValType(Value) == "C" + Value := RTrim(Value) + endif + // Save starting value for this field if !::aDirty[nNum] ::aOldValue[nNum] := ::aRow[nNum] @@ -511,8 +523,8 @@ METHOD Delete(oRow) CLASS TMySQLTable cDeleteQuery += oRow:MakePrimaryKeyWhere() - if sqlQuery(::nSocket, cDeleteQuery) == 1 - return .T. + if sqlQuery(::nSocket, cDeleteQuery) == 0 + ::lError := .F. else ::lError := .T. @@ -521,7 +533,7 @@ METHOD Delete(oRow) CLASS TMySQLTable endif -return .F. +return !::lError // Adds a row with values passed into oRow @@ -683,9 +695,9 @@ METHOD CreateTable(cTable, aStruct) CLASS TMySQLServer case aStruct[i][DBS_TYPE] == "N" if aStruct[i][DBS_DEC] == 0 - cCreateQuery += aStruct[i][DBS_NAME] + " int " + Eval(cNN, aStruct[i]) + "," + cCreateQuery += aStruct[i][DBS_NAME] + " int(" + AllTrim(Str(aStruct[i][DBS_LEN])) + ")" + Eval(cNN, aStruct[i]) + "," else - cCreateQuery += aStruct[i][DBS_NAME] + " real " + Eval(cNN, aStruct[i]) + "," + cCreateQuery += aStruct[i][DBS_NAME] + " real(" + AllTrim(Str(aStruct[i][DBS_LEN])) + "," + AllTrim(Str(aStruct[i][DBS_DEC])) + ")" + Eval(cNN, aStruct[i]) + "," endif case aStruct[i][DBS_TYPE] == "D" diff --git a/harbour/contrib/mysql/tsqlbrw.prg b/harbour/contrib/mysql/tsqlbrw.prg index 68b24c8b10..a1961ab347 100644 --- a/harbour/contrib/mysql/tsqlbrw.prg +++ b/harbour/contrib/mysql/tsqlbrw.prg @@ -97,7 +97,11 @@ METHOD Block() CLASS TBColumnSQL xValue := iif(xValue, ".T.", ".F.") case ValType(xValue) $ "CM" - xValue := "'" + xValue + "'" + // Chr(34) is a double quote + // That is: if there is a double quote inside text substitute it with a string + // which gets converted back to a double quote by macro operator. If not it would + // give an error because of unbalanced double quotes. + xValue := Chr(34) + StrTran(xValue, Chr(34), Chr(34) + "+Chr(34)+" + Chr(34)) + Chr(34) otherwise endcase @@ -122,6 +126,7 @@ CLASS TBrowseSQL from TBrowse // corresponding row inside table METHOD BrowseTable(nKey, lCanEdit) // Handles standard moving inside table and if lCanEdit == .T. // allows editing of field. It is the stock ApplyKey() moved inside a table + // if lCanEdit K_DEL deletes current row ENDCLASS @@ -160,24 +165,26 @@ METHOD New(nTop, nLeft, nBottom, nRight, oServer, oQuery, cTable) CLASS TBrowseS // Add a column for each field for i := 1 to ::oQuery:FCount() + // No bBlock now since New() would use it to find column length, but column is not ready yet at this point oCol := TBColumnSQL():New(::oCurRow:FieldName(i),, Self) oCol:Width := Max(::oCurRow:aFieldStruct[i][MYSQL_FS_LENGTH], Len(oCol:Heading)) + //Alert(Str(oCol:Width)) + // which field does this column display oCol:nFieldNum := i // Add a picture - /*do case + do case case ISNUMBER(::oCurRow:FieldGet(i)) - oCol:picture := "@N999,999" + oCol:picture := replicate("9", ::oCurRow:aFieldStruct[i][MYSQL_FS_LENGTH]) case ISCHARACTER(::oCurRow:FieldGet(i)) - // For non-numeric, just use colors 3 and 4 ("B/W" and "B/BG") - oCol:picture := replicate("!", ::oCurRow:aFieldStruct[i][MYSQL_FS_LENGTH]) + oCol:picture := replicate("!", ::oCurRow:aFieldStruct[i][MYSQL_FS_LENGTH]) - endcase*/ + endcase ::AddColumn(oCol) next @@ -268,7 +275,7 @@ METHOD EditField() CLASS TBrowseSQL aGetList := { getnew( row(), col(), ; {|xValue| iif(xValue == nil, ::oCurRow:FieldGet(oCol:nFieldNum), ::oCurRow:FieldPut(oCol:nFieldNum, xValue))} ,; oCol:heading, ; - nil, ; + oCol:picture, ; ::colorSpec ) } // Set insert key to toggle insert mode and cursor shape @@ -378,11 +385,20 @@ METHOD BrowseTable(nKey, lCanEdit) CLASS TBrowseSQL ::EditField() endif - /*otherwise - KEYBOARD chr( nKey ) - DoGet( oBrowse )*/ - otherwise + /*case nKey == K_DEL + if lCanEdit + if ! ::oQuery:Delete(::oCurRow) + Alert("not deleted " + ::oQuery:Error()) + endif + if !::oQuery:Refresh() + Alert(::oQuery:Error()) + endif + ::inValidate() + ::refreshAll():forceStable() + endif*/ + + otherwise endcase return Self