See changelog 2001-12-2 23:10 GMT -3
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Harbour Project source code:
|
||||
* MySQL DBMS low level (client api) interface code.
|
||||
@@ -51,6 +50,17 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* The following parts are Copyright of the individual authors.
|
||||
* www - http://www.harbour-project.org
|
||||
*
|
||||
* Copyright 2001 Luiz Rafael Culik <culik@sl.conex.net>
|
||||
* DATATOSQL(),FILETOSQLBINARY()
|
||||
*
|
||||
* See doc/license.txt for licensing terms.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* NOTE: we need this to prevent base types redefinition */
|
||||
#define _CLIPDEFS_H
|
||||
@@ -61,6 +71,9 @@
|
||||
#include "extend.api"
|
||||
#include "item.api"
|
||||
#include "mysql.h"
|
||||
#include <stdio.h>
|
||||
#include <hb_io.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
|
||||
/* NOTE: OS/2 EMX port of MySQL needs libmysqlclient.a from 3.21.33b build which has st and mt
|
||||
@@ -327,3 +340,50 @@ HB_FUNC(SQLSRVINFO)
|
||||
{
|
||||
_retc( mysql_get_server_info( (MYSQL *)_parnl(1) ) );
|
||||
}
|
||||
|
||||
char *filetoBuff(char *f,char *s)
|
||||
{
|
||||
int i=0;
|
||||
int fh= hb_fsOpen(s,2);
|
||||
i=hb_fsReadLarge(fh,f,filelength(fh));
|
||||
f[ i ] = '\0';
|
||||
hb_fsClose(fh);
|
||||
return f ;
|
||||
}
|
||||
|
||||
HB_FUNC(DATATOSQL)
|
||||
{
|
||||
const char *from;
|
||||
int iSize;
|
||||
int iLen;
|
||||
char *buffer;
|
||||
from=hb_parc(1);
|
||||
iLen=hb_parclen(1)*2;
|
||||
iSize=strlen(from);
|
||||
buffer=hb_xgrab(iLen);
|
||||
mysql_escape_string(buffer,from,iSize);
|
||||
hb_retc((char*)buffer);
|
||||
hb_xfree(buffer);
|
||||
}
|
||||
|
||||
HB_FUNC(FILETOSQLBINARY)
|
||||
{
|
||||
char *szFile=hb_parc(1);
|
||||
const char *from;
|
||||
int fh;
|
||||
int iSize;
|
||||
int iLen;
|
||||
char *buffer;
|
||||
char *FromBuffer;
|
||||
fh=hb_fsOpen(szFile,2);
|
||||
iSize=filelength(fh);
|
||||
iLen=iSize*2;
|
||||
FromBuffer=hb_xgrab(iSize+1);
|
||||
hb_fsClose(fh);
|
||||
from=(char*)filetoBuff(FromBuffer,szFile);
|
||||
buffer=hb_xgrab(iLen);
|
||||
mysql_escape_string(buffer,from,iSize);
|
||||
hb_retc((char*)buffer);
|
||||
hb_xfree(buffer);
|
||||
hb_xfree(FromBuffer);
|
||||
}
|
||||
|
||||
@@ -88,3 +88,17 @@ Excuse my poor english and happy selecting :-)
|
||||
|
||||
Maurilio Longo - <maurilio.longo@libero.it>
|
||||
|
||||
New Enhacemets
|
||||
|
||||
Added support to mediumint and mediumblob type on the follow classes
|
||||
TMySqlRow:FieldType() will Return an "B" for mediumblob and an "I" Mediumint field
|
||||
TMySQLServer:CreateTable(cTable, aStruct,cPrimaryKey,cUniqueKey,cAuto) Added tree new parameters
|
||||
Cprimarykey tell to use the field defined as an primaty key.
|
||||
CUniqueKey tell that this field has unique values
|
||||
cAuto Tell that this field should be auto_increment
|
||||
Also to create an Table with mediumint and mediumblob field types use
|
||||
{{"Data","B",1,0},{"Ammount","I",9,0}} in the astructure array
|
||||
To save an File to an mediumblob field use
|
||||
cBuffer:=FILETOSQLBINARY(cFile) . this will read up the file and return an string formated to mysql requeriments
|
||||
|
||||
Luiz Rafael Culik - <culik@sl.conex.net>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
@@ -236,6 +236,12 @@ METHOD FieldType(nNum) CLASS TMySQLRow
|
||||
::aFieldStruct[nNum][MYSQL_FS_TYPE] == MYSQL_STRING_TYPE
|
||||
cType := "C"
|
||||
|
||||
case ::aFieldStruct[nNum][MYSQL_FS_TYPE] == MYSQL_INT24_TYPE
|
||||
cType := "I"
|
||||
|
||||
case ::aFieldStruct[nNum][MYSQL_FS_TYPE] == MYSQL_MEDIUM_BLOB_TYPE
|
||||
cType := "B"
|
||||
|
||||
otherwise
|
||||
cType := "U"
|
||||
|
||||
@@ -705,13 +711,13 @@ CLASS TMySQLServer
|
||||
DATA cUser // user accessing db
|
||||
DATA cPassword // his/her password
|
||||
DATA lError // .T. if occurred an error
|
||||
|
||||
DATA cCreateQuery
|
||||
METHOD New(cServer, cUser, cPassword) // Opens connection to a server, returns a server object
|
||||
METHOD Destroy() // Closes connection to server
|
||||
|
||||
METHOD SelectDB(cDBName) // Which data base I will use for subsequent queries
|
||||
|
||||
METHOD CreateTable(cTable, aStruct) // Create new table using the same syntax of dbCreate()
|
||||
METHOD CreateTable(cTable, aStruct,cPrimaryKey,cUniqueKey,cAuto) // Create new table using the same syntax of dbCreate()
|
||||
METHOD DeleteTable(cTable) // delete table
|
||||
METHOD TableStruct(cTable) // returns a structure array compatible with clipper's dbStruct() ones
|
||||
METHOD CreateIndex(cName, cTable, aFNames, lUnique) // Create an index (unique) on field name(s) passed as an array of strings aFNames
|
||||
@@ -764,47 +770,59 @@ return .F.
|
||||
// NOTE: OS/2 port of MySQL is picky about table names, that is if you create a table with
|
||||
// an upper case name you cannot alter it (for example) using a lower case name, this violates
|
||||
// OS/2 case insensibility about names
|
||||
METHOD CreateTable(cTable, aStruct) CLASS TMySQLServer
|
||||
METHOD CreateTable(cTable, aStruct,cPrimaryKey,cUniqueKey,cAuto) CLASS TMySQLServer
|
||||
|
||||
/* NOTE: all table names are created with lower case */
|
||||
local cCreateQuery := "CREATE TABLE " + Lower(cTable) + " ("
|
||||
|
||||
local i
|
||||
|
||||
// returns NOT NULL if extended structure has DBS_NOTNULL field to true
|
||||
local cNN := {|aArr| iif(Len(aArr) > DBS_DEC, iif(aArr[DBS_NOTNULL], " NOT NULL ", ""), "")}
|
||||
|
||||
::cCreateQuery := "CREATE TABLE " + Lower(cTable) + " ("
|
||||
for i := 1 to Len(aStruct)
|
||||
do case
|
||||
case aStruct[i][DBS_TYPE] == "C"
|
||||
cCreateQuery += aStruct[i][DBS_NAME] + " char(" + AllTrim(Str(aStruct[i][DBS_LEN])) + ")" + Eval(cNN, aStruct[i]) + ","
|
||||
::cCreateQuery += aStruct[i][DBS_NAME] + " char(" + AllTrim(Str(aStruct[i][DBS_LEN])) + ")" + Eval(cNN, aStruct[i])+ if(aStruct[i][DBS_NAME]==cPrimaryKey," NOT NULL ",'' )+ ","
|
||||
|
||||
case aStruct[i][DBS_TYPE] == "M"
|
||||
cCreateQuery += aStruct[i][DBS_NAME] + " text" + Eval(cNN, aStruct[i]) + ","
|
||||
::cCreateQuery += aStruct[i][DBS_NAME] + " text" + Eval(cNN, aStruct[i]) + ","
|
||||
|
||||
case aStruct[i][DBS_TYPE] == "N"
|
||||
if aStruct[i][DBS_DEC] == 0
|
||||
cCreateQuery += aStruct[i][DBS_NAME] + " int(" + AllTrim(Str(aStruct[i][DBS_LEN])) + ")" + Eval(cNN, aStruct[i]) + ","
|
||||
::cCreateQuery += aStruct[i][DBS_NAME] + " int(" + AllTrim(Str(aStruct[i][DBS_LEN])) + ")" + Eval(cNN, aStruct[i]) + if(aStruct[i][DBS_NAME]==cPrimaryKey," NOT NULL ",'' )+ if(aStruct[i][DBS_NAME]==cAuto," auto_increment ",'' ) + ","
|
||||
else
|
||||
cCreateQuery += aStruct[i][DBS_NAME] + " real(" + AllTrim(Str(aStruct[i][DBS_LEN])) + "," + AllTrim(Str(aStruct[i][DBS_DEC])) + ")" + 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"
|
||||
cCreateQuery += aStruct[i][DBS_NAME] + " date " + Eval(cNN, aStruct[i]) + ","
|
||||
::cCreateQuery += aStruct[i][DBS_NAME] + " date " + Eval(cNN, aStruct[i]) + ","
|
||||
|
||||
case aStruct[i][DBS_TYPE] == "L"
|
||||
cCreateQuery += aStruct[i][DBS_NAME] + " tinyint " + Eval(cNN, aStruct[i]) + ","
|
||||
::cCreateQuery += aStruct[i][DBS_NAME] + " tinyint " + Eval(cNN, aStruct[i]) + ","
|
||||
|
||||
case aStruct[i][DBS_TYPE] == "B"
|
||||
::cCreateQuery += aStruct[i][DBS_NAME] + " mediumblob " + Eval(cNN, aStruct[i]) + ","
|
||||
|
||||
case aStruct[i][DBS_TYPE] == "I"
|
||||
::cCreateQuery += aStruct[i][DBS_NAME] + " mediumint " + Eval(cNN, aStruct[i]) + ","
|
||||
|
||||
otherwise
|
||||
cCreateQuery += aStruct[i][DBS_NAME] + " char(" + AllTrim(Str(aStruct[i][DBS_LEN])) + ")" + Eval(cNN, aStruct[i]) + ","
|
||||
::cCreateQuery += aStruct[i][DBS_NAME] + " char(" + AllTrim(Str(aStruct[i][DBS_LEN])) + ")" + Eval(cNN, aStruct[i]) + ","
|
||||
|
||||
endcase
|
||||
|
||||
next
|
||||
if cPrimarykey != NIL
|
||||
::cCreateQuery += ' PRIMARY KEY ('+cPrimaryKey+'),'
|
||||
endif
|
||||
if cUniquekey != NIL
|
||||
::cCreateQuery += ' UNIQUE '+cUniquekey +' ('+cUniqueKey+'),'
|
||||
endif
|
||||
|
||||
|
||||
// remove last comma from list
|
||||
cCreateQuery := Left(cCreateQuery, Len(cCreateQuery) -1) + ")"
|
||||
|
||||
if sqlQuery(::nSocket, cCreateQuery) == 0
|
||||
::cCreateQuery := Left(::cCreateQuery, Len(::cCreateQuery) -1) + ");"
|
||||
if sqlQuery(::nSocket, ::cCreateQuery) == 0
|
||||
return .T.
|
||||
else
|
||||
::lError := .T.
|
||||
@@ -974,6 +992,14 @@ METHOD TableStruct(cTable) CLASS TMySQLServer
|
||||
aSField[DBS_LEN] := 12
|
||||
aSFIeld[DBS_DEC] := 8
|
||||
|
||||
case aField[MSQL_FS_TYPE] == MYSQL_MEDIUM_BLOB_TYPE
|
||||
aSField[DBS_TYPE] := "B"
|
||||
aSField[DBS_LEN] := aField[MSQL_FS_LENGTH]
|
||||
|
||||
case aField[MSQL_FS_TYPE] == FIELD_TYPE_INT24
|
||||
aSField[DBS_TYPE] := "I"
|
||||
aSField[DBS_LEN] := aField[MSQL_FS_LENGTH]
|
||||
aSFIeld[DBS_DEC] := aField[MYSQL_FS_DECIMALS]
|
||||
otherwise
|
||||
|
||||
endcase
|
||||
@@ -1007,7 +1033,9 @@ static function ClipValue2SQL(Value)
|
||||
endif
|
||||
|
||||
case Valtype(Value) $ "CM"
|
||||
cValue := "'" + StrTran(Value, "'", "\'") + "'"
|
||||
cValue := "'"
|
||||
Value:=DATATOSQL(value)
|
||||
cValue+= value+ "'"
|
||||
|
||||
case Valtype(Value) == "L"
|
||||
cValue := AllTrim(Str(iif(Value == .F., 0, 1)))
|
||||
|
||||
Reference in New Issue
Block a user