20000531-22:15 GMT+2 Maurilio Longo <maurilio.longo@libero.it>

This commit is contained in:
Maurilio Longo
2000-05-31 20:19:07 +00:00
parent 19e3bbe4d5
commit b39d909ac4
6 changed files with 236 additions and 39 deletions

View File

@@ -1,3 +1,16 @@
20000531-22:15 GMT+2 Maurilio Longo <maurilio.longo@libero.it>
* contrib/msql/tmsql.prg
* type "C" values need to be encoded before sending them to mSQL (' -> \')
+ contrib/msql/dbf2msql.prg
+ added a little utility to import a .dbf file into a mSQL table
* contrib/msql/Makefile
+ added dbf2msql.prg target
* contrib/msql/readme.txt
* reformatted.
* source/vm/classes.c
! patch from JFl&RaC <jfl@mafact.com>,<rac@mafact.com> to fix super:X handling
2000-05-31 13:53 UTC+0100 Victor Szakats <info@szelvesz.hu>
* include/hbapi.h
@@ -5,15 +18,15 @@
+ Added hb_retl() Extend API function.
* HB_EXTEND_API_MACROS renamed to HB_API_MACROS
* include/hbdate.h
* include/hbdate.h
* source/rtl/dates.c
* source/rtl/dateshb.c
* source/rtl/dateshb.c
+ Added hb_dateToday() and hb_dateTimeStr() functions.
* source/rtl/trim.c
% Some minor optimizations.
* source/vm/classes.c
* source/vm/classes.c
! Fixed warning, adjusted variable scopes.
* contrib/libmisc/dates2.c

View File

@@ -1,17 +1,38 @@
CompOptions = -m -n -I../include
objects = test.o msql.o tmsql.o
precomp = test.c msql.c tmsql.c
msqlobjects = msql.o tmsql.o
msqlprecomp = msql.c tmsql.c
msqlsource = tmsql.prg
source = test.prg tmsql.prg
tobjects = test.o
tprecomp = test.c
tsource = test.prg
test: $(objects)
gcc -O2 -o test.exe $(objects) -I..\include -L..\lib -lrtl -lvm -lgtos2 -lrdd -llang -lmacro -lpp -ldbfntx -lcommon -lrtl -lvm -llibmsql -lsocket
dobjects = dbf2msql.o
dprecomp = dbf2msql.c
dsource = dbf2msql.prg
$(objects): $(precomp)
gcc -O2 -c $(precomp) -I..\include
$(msqlobjects): $(msqlprecomp)
gcc -O2 -c $(msqlprecomp) -I..\include
$(msqlprecomp): $(msqlsource)
..\bin\harbour $(CompOptions) $(msqlsource)
$(precomp): $(source)
..\bin\harbour $(CompOptions) $(source)
test: $(tobjects) $(msqlobjects)
gcc -O2 -o test.exe $(tobjects) $(msqlobjects) -I..\include -L..\lib -lrtl -lvm -lgtos2 -lrdd -llang -lmacro -lpp -ldbfntx -lcommon -lrtl -lvm -llibmsql -lsocket
$(tobjects): $(tprecomp)
gcc -O2 -c $(tprecomp) -I..\include
$(tprecomp): $(tsource)
..\bin\harbour $(CompOptions) $(tsource)
dbf2msql: $(dobjects) $(msqlobjects)
gcc -O2 -o dbf2msql.exe $(dobjects) $(msqlobjects) -I..\include -L..\lib -lrtl -lvm -lgtos2 -lrdd -llang -lmacro -lpp -ldbfntx -lcommon -lrtl -lvm -llibmsql -lsocket
$(dobjects): $(dprecomp)
gcc -O2 -c $(dprecomp) -I..\include
$(dprecomp): $(dsource)
..\bin\harbour $(CompOptions) $(dsource)

View File

@@ -0,0 +1,152 @@
/*
* $Id$
*/
/*
* Harbour Project source code:
* dbf2msql.prg - converts a .dbf file into a mSQL table
*
* Copyright 2000 Maurilio Longo <maurilio.longo@libero.it>
* www - http://www.harbour-project.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version, with one exception:
*
* The exception is that if you link the Harbour Runtime Library (HRL)
* and/or the Harbour Virtual Machine (HVM) with other files to produce
* an executable, this does not by itself cause the resulting executable
* to be covered by the GNU General Public License. Your use of that
* executable is in no way restricted on account of linking the HRL
* and/or HVM code into it.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit
* their web site at http://www.gnu.org/).
*
*/
procedure main(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11)
local cTok, nTok := 1
local cHostName, cDataBase, cTable, cFile
local aDbfStruct, i
local lCreateTable := .F.
local oServer, oTable, oRecord
SET CENTURY ON
SET EPOCH TO 1960
if PCount() < 8
help()
quit
endif
i := 1
// Scan parameters and setup workings
while (i <= PCount())
cTok := hb_PValue(i++)
do case
case cTok == "-h"
cHostName := hb_PValue(i++)
case cTok == "-d"
cDataBase := hb_PValue(i++)
case cTok == "-t"
cTable := hb_PValue(i++)
case cTok == "-f"
cFile := hb_PValue(i++)
case cTok == "-c"
lCreateTable := .T.
otherwise
help()
quit
endcase
enddo
dbUseArea(.T.,, cFile, "dbffile",, .T.)
aDbfStruct := dbffile->(dbStruct())
oServer := TmSQLServer():New(cHostName)
if oServer:NetErr()
? oServer:Error()
quit
endif
oServer:SelectDB(cDataBase)
if oServer:NetErr()
? oServer:Error()
quit
endif
if lCreateTable
if Ascan(oServer:ListTables(), cTable) > 0
oServer:DeleteTable(cTable)
if oServer:NetErr()
? oServer:Error()
quit
endif
endif
oServer:CreateTable(cTable, aDbfStruct)
if oServer:NetErr()
? oServer:Error()
quit
endif
endif
// Initialize mSQL table
oTable := oServer:Query("SELECT * FROM " + cTable + " LIMIT 1")
if oTable:NetErr()
Alert(oTable:Error())
quit
endif
while !dbffile->(eof()) .AND. Inkey() <> 27
oRecord := oTable:GetBlankRow()
for i := 1 to dbffile->(FCount())
oRecord:FieldPut(i, dbffile->(FieldGet(i)))
next
oTable:Append(oRecord)
if oTable:NetErr()
Alert(oTable:Error())
endif
dbffile->(dbSkip())
DevPos(Row(), 1)
DevOut("imported recs: " + Str(dbffile->(RecNo())))
enddo
dbffile->(dbCloseArea())
return
procedure Help()
? "dbf2msql - dbf file to mSQL table conversion utility"
? "-h hostname "
? "-d name of database to use"
? "-t name of table to add records to"
? "-c delete existing table and create a new one"
? "-f name of .dbf file to import"
? "all parameters but -c are mandatory"
? ""
return

View File

@@ -13,33 +13,33 @@ This set of files gives you a mean to access an mSQL server, I've developed and
In its present state mSQL classes are made up of these files:
msql.c: low level wrapper around msql client API. It requires libmsql.a (or libmsql.lib if under
windows) import library (under OS/2 you need, also, msql.dll client api library if it's
not in your LIBPATH).
msql.h: from mSQL 2.x distribution, type and defines of mSQL client api.
msql.ch: clipper level defines of mSQL types
tmsql.prg: mSQL access classes
test.prg: a little test program which wont work for you :-) since it uses a .dbf file not
provided. Use it as a small tutorial of tmsql.prg provided functions.
Makefile my makefile for OS/2 gcc, you'll surely need to change it to adapt to your needs/platform.
msql.c: low level wrapper around msql client API. It requires libmsql.a (or libmsql.lib if under
windows) import library (under OS/2 you need, also, msql.dll client api library if it's
not in your LIBPATH).
msql.h: from mSQL 2.x distribution, type and defines of mSQL client api.
msql.ch: clipper level defines of mSQL types
tmsql.prg: mSQL access classes
test.prg: a little test program which wont work for you :-) since it uses a .dbf file not
provided. Use it as a small tutorial of tmsql.prg provided functions.
Makefile: my makefile for OS/2 gcc, you'll surely need to change it to adapt to your needs/platform.
tmsql.prg defines four classes:
TmSQLServer: manages access to a mSQL server and returns an oServer object to which you'll send all your
queries;
TmSQLQuery: a standard query to an oServer with joins. Every query has a GetRow() method
which on every call returns a TmSQLRow object which, in turn, contains requested fields.
Query objects convert mSQL answer (which is an array of strings) to clipper level types.
At present time N (with decimals), L, D, and C clipper types are supported.
TmSQLTable: It's a descendant of a TmSQLQuery and you'll receive it when your query has no joins.
It adds Update(), Append() and Delete() methods which receive a TmSQLRow object and
reflect changes to the mSQL table from which they come.
Please note that TmSQLQuery objects don't have these methods, so, if you want to change
a row received from a TmSQLQuery object you need to construct a valid SQL query and submit
it to an oServer object.
TmSQLRow: Every row returned by a SELECT is converted to a TmSQLRow object. This object handles
fields and has methods to access fields given a field name or position.
TmSQLServer: manages access to a mSQL server and returns an oServer object to which you'll send all your
queries;
TmSQLQuery: a standard query to an oServer with joins. Every query has a GetRow() method
which on every call returns a TmSQLRow object which, in turn, contains requested fields.
Query objects convert mSQL answer (which is an array of strings) to clipper level types.
At present time N (with decimals), L, D, and C clipper types are supported.
TmSQLTable: It's a descendant of a TmSQLQuery and you'll receive it when your query has no joins.
It adds Update(), Append() and Delete() methods which receive a TmSQLRow object and
reflect changes to the mSQL table from which they come.
Please note that TmSQLQuery objects don't have these methods, so, if you want to change
a row received from a TmSQLQuery object you need to construct a valid SQL query and submit
it to an oServer object.
TmSQLRow: Every row returned by a SELECT is converted to a TmSQLRow object. This object handles
fields and has methods to access fields given a field name or position.
I'm aware that this brief document doesn't explain a lot about mSQL access classes and I'm sorry for that.
I'll try to update it as work on these classes goes by and I'll like to receive feedbak and suggestions

View File

@@ -105,7 +105,12 @@ METHOD FieldPut(nNum, Value) CLASS TmSQLRow
if nNum > 0 .AND. nNum <= Len(::aRow)
if Valtype(Value) == Valtype(::aRow[nNum]) .OR. Empty(::aRow[nNum])
::aRow[nNum] := Value
// if it's a char field encode singole quotes
if ValType(Value) == "C"
::aRow[nNum] := StrTran(Value, "'", "\'")
else
::aRow[nNum] := Value
endif
::aDirty[nNum] := .T.
return Value
endif
@@ -729,7 +734,7 @@ METHOD Query(cQuery) CLASS TmSQLServer
while __StrToken(cUpperQuery, i++, " ") <> "FROM"
enddo
while (cToken := __StrToken(cUpperQuery, i++, " ")) <> "WHERE" .AND. !Empty(cToken)
while (cToken := __StrToken(cUpperQuery, i++, " ")) <> "WHERE" .AND. cToken <> "LIMIT" .AND. !Empty(cToken)
cTableName := __StrToken(cQuery, i - 1, " ")
nNumTables++
enddo

View File

@@ -1745,8 +1745,14 @@ static HARBOUR hb___msgGetData( void )
* Internal function to return a superobject
*/
static HARBOUR hb___msgSuper( void )
{
hb_itemReturn( s_pMethod->pInitValue );
{ //hb_itemReturn( s_pMethod->pInitValue );
PHB_ITEM pObject = hb_stack.pBase + 1;
pObject->item.asArray.value->uiPrevCls = pObject->item.asArray.value->uiClass;
pObject->item.asArray.value->uiClass = s_pMethod->uiData;
hb_itemCopy( &hb_stack.Return, pObject );
}