From 9da0302bb5331166a2da4a2c059edf0be7d7f7d3 Mon Sep 17 00:00:00 2001 From: Mindaugas Kavaliauskas Date: Thu, 25 Dec 2008 06:06:16 +0000 Subject: [PATCH] 2008-12-25 08:05 UTC+0200 Mindaugas Kavaliauskas (dbtopas/at/dbtopas.lt) * contrib/rddsql/sqlbase.c * contrib/rddsql/sqlmix.c * contrib/rddsql/tests/test1.prg * contrib/rddsql/common.mak - contrib/rddsql/hbsqldd.h + contrib/rddsql/hbrddsql.h * contrib/rddsql/make_b32.bat * contrib/rddsql/make_vc.bat * contrib/rddsql/make_gcc.sh + contrib/rddsql/sddmy - contrib/rddsql/mysqldd.c + contrib/rddsql/sddmy/mysqldd.c + contrib/rddsql/sddmy/Makefile + contrib/rddsql/sddmy/make_gcc.sh + contrib/rddsql/sddmy/common.mak + contrib/rddsql/sddmy/make_b32.bat + contrib/rddsql/sddmy/make_vc.bat * changed structure and names of rddsql libraries. Since it can support many SQL databases, each backend moved to a separate library. Otherwise (all backend in the same library) nobody will be able to compile library without installing packages of ALL supported SQL databases. Now: rddsql - RDD for interfacing to SQL database drivers sddmy - MySQL database driver sddpg - Postgre SQL database driver ... ; TOFIX: I was unable to manage build files. contrib/sqlrdd/sddmy/make_b32.bat sets HB_ROOT variable: set HB_ROOT = ..\..\.. but this variable is lost and contrib/make_b32.mak reassign it: !ifndef HB_ROOT HB_ROOT = ..\.. !endif This breaks building of library. To fix this problem, I've added a two hacks: - added additional include path into CFLAGS (see make_b32.bat) - added "..\" to LIB_PATH (see common.mak) The same problem is for both make_b32 and make_vc, and for both sddmy and sddpg libraries. ; TODO: check (and adjust if neccessary) build files for unix + contrib/rddsql/sddpg + contrib/rddsql/sddpg/pgsqldd.c + contrib/rddsql/sddpg/Makefile + contrib/rddsql/sddpg/make_gcc.sh + contrib/rddsql/sddpg/common.mak + contrib/rddsql/sddpg/make_b32.bat + contrib/rddsql/sddpg/make_vc.bat + added SQL database driver for Postgre SQL ; does anyone have more RDD for Christmas gift? :) --- harbour/ChangeLog | 52 ++ harbour/contrib/rddsql/common.mak | 1 - .../contrib/rddsql/{hbsqldd.h => hbrddsql.h} | 0 harbour/contrib/rddsql/make_b32.bat | 63 -- harbour/contrib/rddsql/make_gcc.sh | 17 - harbour/contrib/rddsql/make_vc.bat | 64 -- harbour/contrib/rddsql/sddmy/Makefile | 27 + harbour/contrib/rddsql/sddmy/common.mak | 13 + harbour/contrib/rddsql/sddmy/make_b32.bat | 72 +++ harbour/contrib/rddsql/sddmy/make_gcc.sh | 26 + harbour/contrib/rddsql/sddmy/make_vc.bat | 73 +++ harbour/contrib/rddsql/{ => sddmy}/mysqldd.c | 8 +- harbour/contrib/rddsql/sddpg/Makefile | 27 + harbour/contrib/rddsql/sddpg/common.mak | 13 + harbour/contrib/rddsql/sddpg/make_b32.bat | 72 +++ harbour/contrib/rddsql/sddpg/make_gcc.sh | 26 + harbour/contrib/rddsql/sddpg/make_vc.bat | 73 +++ harbour/contrib/rddsql/sddpg/pgsqldd.c | 587 ++++++++++++++++++ harbour/contrib/rddsql/sqlbase.c | 2 +- harbour/contrib/rddsql/sqlmix.c | 2 +- harbour/contrib/rddsql/tests/test1.prg | 2 +- 21 files changed, 1067 insertions(+), 153 deletions(-) rename harbour/contrib/rddsql/{hbsqldd.h => hbrddsql.h} (100%) create mode 100644 harbour/contrib/rddsql/sddmy/Makefile create mode 100644 harbour/contrib/rddsql/sddmy/common.mak create mode 100644 harbour/contrib/rddsql/sddmy/make_b32.bat create mode 100755 harbour/contrib/rddsql/sddmy/make_gcc.sh create mode 100644 harbour/contrib/rddsql/sddmy/make_vc.bat rename harbour/contrib/rddsql/{ => sddmy}/mysqldd.c (99%) create mode 100644 harbour/contrib/rddsql/sddpg/Makefile create mode 100644 harbour/contrib/rddsql/sddpg/common.mak create mode 100644 harbour/contrib/rddsql/sddpg/make_b32.bat create mode 100755 harbour/contrib/rddsql/sddpg/make_gcc.sh create mode 100644 harbour/contrib/rddsql/sddpg/make_vc.bat create mode 100644 harbour/contrib/rddsql/sddpg/pgsqldd.c diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 3166ff90d1..7eba6c1964 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,58 @@ 2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2008-12-25 08:05 UTC+0200 Mindaugas Kavaliauskas (dbtopas/at/dbtopas.lt) + * contrib/rddsql/sqlbase.c + * contrib/rddsql/sqlmix.c + * contrib/rddsql/tests/test1.prg + * contrib/rddsql/common.mak + - contrib/rddsql/hbsqldd.h + + contrib/rddsql/hbrddsql.h + * contrib/rddsql/make_b32.bat + * contrib/rddsql/make_vc.bat + * contrib/rddsql/make_gcc.sh + + contrib/rddsql/sddmy + - contrib/rddsql/mysqldd.c + + contrib/rddsql/sddmy/mysqldd.c + + contrib/rddsql/sddmy/Makefile + + contrib/rddsql/sddmy/make_gcc.sh + + contrib/rddsql/sddmy/common.mak + + contrib/rddsql/sddmy/make_b32.bat + + contrib/rddsql/sddmy/make_vc.bat + * changed structure and names of rddsql libraries. Since it can + support many SQL databases, each backend moved to a separate + library. Otherwise (all backend in the same library) nobody will + be able to compile library without installing packages of ALL + supported SQL databases. Now: + rddsql - RDD for interfacing to SQL database drivers + sddmy - MySQL database driver + sddpg - Postgre SQL database driver + ... + ; TOFIX: I was unable to manage build files. + contrib/sqlrdd/sddmy/make_b32.bat sets HB_ROOT variable: + set HB_ROOT = ..\..\.. + but this variable is lost and contrib/make_b32.mak reassign it: + !ifndef HB_ROOT + HB_ROOT = ..\.. + !endif + This breaks building of library. To fix this problem, I've added + a two hacks: + - added additional include path into CFLAGS (see make_b32.bat) + - added "..\" to LIB_PATH (see common.mak) + The same problem is for both make_b32 and make_vc, and for both + sddmy and sddpg libraries. + ; TODO: check (and adjust if neccessary) build files for unix + + + contrib/rddsql/sddpg + + contrib/rddsql/sddpg/pgsqldd.c + + contrib/rddsql/sddpg/Makefile + + contrib/rddsql/sddpg/make_gcc.sh + + contrib/rddsql/sddpg/common.mak + + contrib/rddsql/sddpg/make_b32.bat + + contrib/rddsql/sddpg/make_vc.bat + + added SQL database driver for Postgre SQL + ; does anyone have more RDD for Christmas gift? :) + 2008-12-24 12:23 UTC-0600 Teo Fonrouge (teo/at/windtelsoft/dot/com) * include/Makefile + added hbrddnsx.h header diff --git a/harbour/contrib/rddsql/common.mak b/harbour/contrib/rddsql/common.mak index afe905fb68..57d8f1c609 100644 --- a/harbour/contrib/rddsql/common.mak +++ b/harbour/contrib/rddsql/common.mak @@ -7,7 +7,6 @@ LIBNAME = $(LIBPREF)rddsql LIB_PATH = $(LIB_DIR)$(LIBNAME)$(LIBEXT) LIB_OBJS = \ - $(OBJ_DIR)mysqldd$(OBJEXT) \ $(OBJ_DIR)sqlbase$(OBJEXT) \ $(OBJ_DIR)sqlmix$(OBJEXT) \ diff --git a/harbour/contrib/rddsql/hbsqldd.h b/harbour/contrib/rddsql/hbrddsql.h similarity index 100% rename from harbour/contrib/rddsql/hbsqldd.h rename to harbour/contrib/rddsql/hbrddsql.h diff --git a/harbour/contrib/rddsql/make_b32.bat b/harbour/contrib/rddsql/make_b32.bat index d08daf16cc..c484512c4c 100644 --- a/harbour/contrib/rddsql/make_b32.bat +++ b/harbour/contrib/rddsql/make_b32.bat @@ -3,67 +3,4 @@ rem rem $Id$ rem -if not "%HB_INC_MYSQL%%HB_DIR_MYSQL%" == "" goto DIR_OK - -echo --------------------------------------------------------------- -echo IMPORTANT: You'll need MySQL package and this envvar -echo to be set to successfully build this library: -echo set HB_INC_MYSQL=C:\mysql\include -echo or -echo set HB_DIR_MYSQL=C:\mysql -echo if you want to generate .lib for the .dll. -echo --------------------------------------------------------------- -goto POST_EXIT - -:DIR_OK - -if "%HB_INC_MYSQL%" == "" set HB_INC_MYSQL=%HB_DIR_MYSQL%\include -set CFLAGS=-I"%HB_INC_MYSQL%" -set _HB_DLL_NAME=libmySQL -set _HB_DLL_DIR=%HB_DIR_MYSQL%\bin - -rem --------------------------------------------------------------- - call ..\mtpl_b32.bat %1 %2 %3 %4 %5 %6 %7 %8 %9 - -rem --------------------------------------------------------------- - -if "%HB_DIR_MYSQL%" == "" goto POST_EXIT - -set _HB_INSTALL_PREFIX=%HB_INSTALL_PREFIX% -if "%_HB_INSTALL_PREFIX%" == "" set _HB_INSTALL_PREFIX=..\.. -set _HB_LIB_INSTALL=%HB_LIB_INSTALL% -if "%_HB_LIB_INSTALL%" == "" set _HB_LIB_INSTALL=%_HB_INSTALL_PREFIX%\lib - -if "%1" == "clean" goto POST_CLEAN -if "%1" == "Clean" goto POST_CLEAN -if "%1" == "CLEAN" goto POST_CLEAN -if "%1" == "install" goto POST_INSTALL -if "%1" == "Install" goto POST_INSTALL -if "%1" == "INSTALL" goto POST_INSTALL - -:POST_BUILD - - implib ..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib "%_HB_DLL_DIR%\%_HB_DLL_NAME%.dll" >> %_HB_MAKELOG% - goto POST_EXIT - -:POST_CLEAN - - if exist ..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib del ..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib > nul - if exist ..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.exp del ..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.exp > nul - if exist %_HB_LIB_INSTALL%\%_HB_DLL_NAME%.lib del %_HB_LIB_INSTALL%\%_HB_DLL_NAME%.lib > nul - goto POST_EXIT - -:POST_INSTALL - - if exist %_HB_LIB_INSTALL%\%_HB_DLL_NAME%.lib del %_HB_LIB_INSTALL%\%_HB_DLL_NAME%.lib - if exist ..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib copy ..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib %_HB_LIB_INSTALL% - goto POST_EXIT - -:POST_EXIT - -set CFLAGS= -set _HB_DLL_NAME= -set _HB_DLL_DIR= -set _HB_INSTALL_PREFIX= -set _HB_LIB_INSTALL= diff --git a/harbour/contrib/rddsql/make_gcc.sh b/harbour/contrib/rddsql/make_gcc.sh index ead0b8cdda..0593942308 100755 --- a/harbour/contrib/rddsql/make_gcc.sh +++ b/harbour/contrib/rddsql/make_gcc.sh @@ -4,21 +4,4 @@ # $Id$ # -if [ "${HB_INC_MYSQL}" = "" ] -then - echo "---------------------------------------------------------------" - echo "IMPORTANT: You will need MYSQL package installed and this" - echo " envvar to be set to successfully build this library:" - echo " export HB_INC_MYSQL=C:/Mysql/include" - echo " or" - echo " export HB_INC_MYSQL=/usr/include/mysql" - echo "---------------------------------------------------------------" - exit 1 -fi - -export CFLAGS="" -for I in ${HB_INC_MYSQL}; do - CFLAGS="${CFLAGS} -I${I}" -done ../mtpl_gcc.sh $1 $2 $3 $4 $5 $6 $7 $8 $9 -unset CFLAGS diff --git a/harbour/contrib/rddsql/make_vc.bat b/harbour/contrib/rddsql/make_vc.bat index 3a05f82e60..4ceb9b9261 100644 --- a/harbour/contrib/rddsql/make_vc.bat +++ b/harbour/contrib/rddsql/make_vc.bat @@ -3,68 +3,4 @@ rem rem $Id$ rem -if not "%HB_INC_MYSQL%%HB_DIR_MYSQL%" == "" goto DIR_OK - -echo --------------------------------------------------------------- -echo IMPORTANT: You'll need MySQL package and this envvar -echo to be set to successfully build this library: -echo set HB_INC_MYSQL=C:\mysql\include -echo or -echo set HB_DIR_MYSQL=C:\mysql -echo if you want to generate .lib for the .dll. -echo --------------------------------------------------------------- -goto POST_EXIT - -:DIR_OK - -if "%HB_INC_MYSQL%" == "" set HB_INC_MYSQL=%HB_DIR_MYSQL%\include -set CFLAGS=-I"%HB_INC_MYSQL%" -set _HB_DLL_NAME=libmySQL -set _HB_DLL_DIR=%HB_DIR_MYSQL%\bin - -rem --------------------------------------------------------------- - call ..\mtpl_vc.bat %1 %2 %3 %4 %5 %6 %7 %8 %9 - -rem --------------------------------------------------------------- - -if "%HB_DIR_MYSQL%" == "" goto POST_EXIT - -set _HB_INSTALL_PREFIX=%HB_INSTALL_PREFIX% -if "%_HB_INSTALL_PREFIX%" == "" set _HB_INSTALL_PREFIX=..\.. -set _HB_LIB_INSTALL=%HB_LIB_INSTALL% -if "%_HB_LIB_INSTALL%" == "" set _HB_LIB_INSTALL=%_HB_INSTALL_PREFIX%\lib - -if "%1" == "clean" goto POST_CLEAN -if "%1" == "Clean" goto POST_CLEAN -if "%1" == "CLEAN" goto POST_CLEAN -if "%1" == "install" goto POST_INSTALL -if "%1" == "Install" goto POST_INSTALL -if "%1" == "INSTALL" goto POST_INSTALL - -:POST_BUILD - - rem Use supplied .lib file. - if not exist ..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib copy "%HB_DIR_MYSQL%\lib\opt\%_HB_DLL_NAME%.lib" ..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib > nul - goto POST_EXIT - -:POST_CLEAN - - if exist ..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib del ..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib > nul - if exist ..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.exp del ..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.exp > nul - if exist %_HB_LIB_INSTALL%\%_HB_DLL_NAME%.lib del %_HB_LIB_INSTALL%\%_HB_DLL_NAME%.lib > nul - goto POST_EXIT - -:POST_INSTALL - - if exist %_HB_LIB_INSTALL%\%_HB_DLL_NAME%.lib del %_HB_LIB_INSTALL%\%_HB_DLL_NAME%.lib - if exist ..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib copy ..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib %_HB_LIB_INSTALL% - goto POST_EXIT - -:POST_EXIT - -set CFLAGS= -set _HB_DLL_NAME= -set _HB_DLL_DIR= -set _HB_INSTALL_PREFIX= -set _HB_LIB_INSTALL= diff --git a/harbour/contrib/rddsql/sddmy/Makefile b/harbour/contrib/rddsql/sddmy/Makefile new file mode 100644 index 0000000000..87791bbbed --- /dev/null +++ b/harbour/contrib/rddsql/sddmy/Makefile @@ -0,0 +1,27 @@ +# +# $Id$ +# + +ROOT = ../../../ + +LIBNAME=sddmy + +ifeq ($(HB_INC_MYSQL),) +ifeq ($(HB_XBUILD),) +HB_INC_MYSQL = /usr/include/mysql +endif +endif + +HB_INC_MYSQL_OK += $(foreach d, $(HB_INC_MYSQL), $(if $(wildcard $(d)/mysql.h),$(d),)) + +ifneq ($(strip $(HB_INC_MYSQL_OK)),) + +C_USR += $(foreach d, $(HB_INC_MYSQL_OK), -I$(d)) + +C_SOURCES=\ + mysqldd.c \ + +include $(TOP)$(ROOT)config/lib.cf +else +include $(TOP)$(ROOT)config/none.cf +endif diff --git a/harbour/contrib/rddsql/sddmy/common.mak b/harbour/contrib/rddsql/sddmy/common.mak new file mode 100644 index 0000000000..639e177205 --- /dev/null +++ b/harbour/contrib/rddsql/sddmy/common.mak @@ -0,0 +1,13 @@ +# +# $Id$ +# + +LIBNAME = $(LIBPREF)sddmy + +LIB_PATH = ..\$(LIB_DIR)$(LIBNAME)$(LIBEXT) + +LIB_OBJS = \ + $(OBJ_DIR)mysqldd$(OBJEXT) \ + +all: \ + $(LIB_PATH) \ diff --git a/harbour/contrib/rddsql/sddmy/make_b32.bat b/harbour/contrib/rddsql/sddmy/make_b32.bat new file mode 100644 index 0000000000..6c59a6ae0e --- /dev/null +++ b/harbour/contrib/rddsql/sddmy/make_b32.bat @@ -0,0 +1,72 @@ +@echo off +rem +rem $Id$ +rem + +if not "%HB_INC_MYSQL%%HB_DIR_MYSQL%" == "" goto DIR_OK + +echo --------------------------------------------------------------- +echo IMPORTANT: You'll need MySQL package and this envvar +echo to be set to successfully build this library: +echo set HB_INC_MYSQL=C:\mysql\include +echo or +echo set HB_DIR_MYSQL=C:\mysql +echo if you want to generate .lib for the .dll. +echo --------------------------------------------------------------- +goto POST_EXIT + +:DIR_OK + +if "%HB_INC_MYSQL%" == "" set HB_INC_MYSQL=%HB_DIR_MYSQL%\include +set CFLAGS=-I"%HB_INC_MYSQL%" +set _HB_DLL_NAME=libmySQL +set _HB_DLL_DIR=%HB_DIR_MYSQL%\bin +set HB_MAKEFILE=..\..\mtpl_b32.mak +set HB_ROOT = ..\..\.. +set CFLAGS=-I"%HB_INC_MYSQL%";..\..\..\include + +rem --------------------------------------------------------------- + +call ..\..\mtpl_b32.bat %1 %2 %3 %4 %5 %6 %7 %8 %9 + +rem --------------------------------------------------------------- + +if "%HB_DIR_MYSQL%" == "" goto POST_EXIT + +set _HB_INSTALL_PREFIX=%HB_INSTALL_PREFIX% +if "%_HB_INSTALL_PREFIX%" == "" set _HB_INSTALL_PREFIX=..\..\.. +set _HB_LIB_INSTALL=%HB_LIB_INSTALL% +if "%_HB_LIB_INSTALL%" == "" set _HB_LIB_INSTALL=%_HB_INSTALL_PREFIX%\lib + +if "%1" == "clean" goto POST_CLEAN +if "%1" == "Clean" goto POST_CLEAN +if "%1" == "CLEAN" goto POST_CLEAN +if "%1" == "install" goto POST_INSTALL +if "%1" == "Install" goto POST_INSTALL +if "%1" == "INSTALL" goto POST_INSTALL + +:POST_BUILD + + implib ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib "%_HB_DLL_DIR%\%_HB_DLL_NAME%.dll" >> %_HB_MAKELOG% + goto POST_EXIT + +:POST_CLEAN + + if exist ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib del ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib > nul + if exist ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.exp del ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.exp > nul + if exist %_HB_LIB_INSTALL%\%_HB_DLL_NAME%.lib del %_HB_LIB_INSTALL%\%_HB_DLL_NAME%.lib > nul + goto POST_EXIT + +:POST_INSTALL + + if exist %_HB_LIB_INSTALL%\%_HB_DLL_NAME%.lib del %_HB_LIB_INSTALL%\%_HB_DLL_NAME%.lib + if exist ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib copy ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib %_HB_LIB_INSTALL% + goto POST_EXIT + +:POST_EXIT + +set CFLAGS= +set _HB_DLL_NAME= +set _HB_DLL_DIR= +set _HB_INSTALL_PREFIX= +set _HB_LIB_INSTALL= diff --git a/harbour/contrib/rddsql/sddmy/make_gcc.sh b/harbour/contrib/rddsql/sddmy/make_gcc.sh new file mode 100755 index 0000000000..c75ccc9108 --- /dev/null +++ b/harbour/contrib/rddsql/sddmy/make_gcc.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +# +# $Id$ +# + +if [ "${HB_INC_MYSQL}" = "" ] +then + echo "---------------------------------------------------------------" + echo "IMPORTANT: You will need MYSQL package installed and this" + echo " envvar to be set to successfully build this library:" + echo " export HB_INC_MYSQL=C:/Mysql/include" + echo " or" + echo " export HB_INC_MYSQL=/usr/include/mysql" + echo "---------------------------------------------------------------" + exit 1 +fi + +export CFLAGS="" +export HB_MAKEFILE="../../mtpl_gcc.mak" +for I in ${HB_INC_MYSQL}; do + CFLAGS="${CFLAGS} -I${I}" +done +../../mtpl_gcc.sh $1 $2 $3 $4 $5 $6 $7 $8 $9 +unset CFLAGS +unset HB_MAKEFILE diff --git a/harbour/contrib/rddsql/sddmy/make_vc.bat b/harbour/contrib/rddsql/sddmy/make_vc.bat new file mode 100644 index 0000000000..42a1670d4c --- /dev/null +++ b/harbour/contrib/rddsql/sddmy/make_vc.bat @@ -0,0 +1,73 @@ +@echo off +rem +rem $Id$ +rem + +if not "%HB_INC_MYSQL%%HB_DIR_MYSQL%" == "" goto DIR_OK + +echo --------------------------------------------------------------- +echo IMPORTANT: You'll need MySQL package and this envvar +echo to be set to successfully build this library: +echo set HB_INC_MYSQL=C:\mysql\include +echo or +echo set HB_DIR_MYSQL=C:\mysql +echo if you want to generate .lib for the .dll. +echo --------------------------------------------------------------- +goto POST_EXIT + +:DIR_OK + +if "%HB_INC_MYSQL%" == "" set HB_INC_MYSQL=%HB_DIR_MYSQL%\include +set CFLAGS=-I"%HB_INC_MYSQL%" +set _HB_DLL_NAME=libmySQL +set _HB_DLL_DIR=%HB_DIR_MYSQL%\bin +set HB_MAKEFILE=..\..\mtpl_b32.mak +set HB_ROOT = ..\..\.. +set CFLAGS=-I"%HB_INC_MYSQL%";..\..\..\include + +rem --------------------------------------------------------------- + +call ..\..\mtpl_vc.bat %1 %2 %3 %4 %5 %6 %7 %8 %9 + +rem --------------------------------------------------------------- + +if "%HB_DIR_MYSQL%" == "" goto POST_EXIT + +set _HB_INSTALL_PREFIX=%HB_INSTALL_PREFIX% +if "%_HB_INSTALL_PREFIX%" == "" set _HB_INSTALL_PREFIX=..\..\.. +set _HB_LIB_INSTALL=%HB_LIB_INSTALL% +if "%_HB_LIB_INSTALL%" == "" set _HB_LIB_INSTALL=%_HB_INSTALL_PREFIX%\lib + +if "%1" == "clean" goto POST_CLEAN +if "%1" == "Clean" goto POST_CLEAN +if "%1" == "CLEAN" goto POST_CLEAN +if "%1" == "install" goto POST_INSTALL +if "%1" == "Install" goto POST_INSTALL +if "%1" == "INSTALL" goto POST_INSTALL + +:POST_BUILD + + rem Use supplied .lib file. + if not exist ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib copy "%HB_DIR_MYSQL%\lib\opt\%_HB_DLL_NAME%.lib" ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib > nul + goto POST_EXIT + +:POST_CLEAN + + if exist ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib del ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib > nul + if exist ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.exp del ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.exp > nul + if exist %_HB_LIB_INSTALL%\%_HB_DLL_NAME%.lib del %_HB_LIB_INSTALL%\%_HB_DLL_NAME%.lib > nul + goto POST_EXIT + +:POST_INSTALL + + if exist %_HB_LIB_INSTALL%\%_HB_DLL_NAME%.lib del %_HB_LIB_INSTALL%\%_HB_DLL_NAME%.lib + if exist ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib copy ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib %_HB_LIB_INSTALL% + goto POST_EXIT + +:POST_EXIT + +set CFLAGS= +set _HB_DLL_NAME= +set _HB_DLL_DIR= +set _HB_INSTALL_PREFIX= +set _HB_LIB_INSTALL= diff --git a/harbour/contrib/rddsql/mysqldd.c b/harbour/contrib/rddsql/sddmy/mysqldd.c similarity index 99% rename from harbour/contrib/rddsql/mysqldd.c rename to harbour/contrib/rddsql/sddmy/mysqldd.c index 0d6ba9f6e2..b232b9e4fb 100644 --- a/harbour/contrib/rddsql/mysqldd.c +++ b/harbour/contrib/rddsql/sddmy/mysqldd.c @@ -53,7 +53,7 @@ #include "hbapi.h" #include "hbapiitm.h" #include "hbvm.h" -#include "hbsqldd.h" +#include "../hbrddsql.h" #ifndef my_socket_defined #define my_socket_defined @@ -135,12 +135,10 @@ static void hb_mysqldd_init( void * cargo ) #define HB_PRG_PCODE_VER HB_PCODE_VER #endif - -HB_FUNC( MYSQLDD ) {;} - +HB_FUNC( SDDMY ) {;} HB_INIT_SYMBOLS_BEGIN( mysqldd__InitSymbols ) -{ "MYSQLDD", {HB_FS_PUBLIC}, {HB_FUNCNAME( MYSQLDD )}, NULL }, +{ "SDDMY", {HB_FS_PUBLIC}, {HB_FUNCNAME( SDDMY )}, NULL }, HB_INIT_SYMBOLS_END( mysqldd__InitSymbols ) HB_CALL_ON_STARTUP_BEGIN( _hb_mysqldd_init_ ) diff --git a/harbour/contrib/rddsql/sddpg/Makefile b/harbour/contrib/rddsql/sddpg/Makefile new file mode 100644 index 0000000000..9db45ce472 --- /dev/null +++ b/harbour/contrib/rddsql/sddpg/Makefile @@ -0,0 +1,27 @@ +# +# $Id$ +# + +ROOT = ../../../ + +LIBNAME=sddpg + +ifeq ($(HB_INC_PGSQL),) +ifeq ($(HB_XBUILD),) +HB_INC_MYSQL = /usr/include/postgresql +endif +endif + +HB_INC_PGSQL_OK += $(foreach d, $(HB_INC_PGSQL), $(if $(wildcard $(d)/libpg-fe.h),$(d),)) + +ifneq ($(strip $(HB_INC_PGSQL_OK)),) + +C_USR += $(foreach d, $(HB_INC_PGSQL_OK), -I$(d)) + +C_SOURCES=\ + pgsqldd.c \ + +include $(TOP)$(ROOT)config/lib.cf +else +include $(TOP)$(ROOT)config/none.cf +endif diff --git a/harbour/contrib/rddsql/sddpg/common.mak b/harbour/contrib/rddsql/sddpg/common.mak new file mode 100644 index 0000000000..6970fca040 --- /dev/null +++ b/harbour/contrib/rddsql/sddpg/common.mak @@ -0,0 +1,13 @@ +# +# $Id$ +# + +LIBNAME = $(LIBPREF)sddpg + +LIB_PATH = ..\$(LIB_DIR)$(LIBNAME)$(LIBEXT) + +LIB_OBJS = \ + $(OBJ_DIR)pgsqldd$(OBJEXT) \ + +all: \ + $(LIB_PATH) \ diff --git a/harbour/contrib/rddsql/sddpg/make_b32.bat b/harbour/contrib/rddsql/sddpg/make_b32.bat new file mode 100644 index 0000000000..68bcf4a8d1 --- /dev/null +++ b/harbour/contrib/rddsql/sddpg/make_b32.bat @@ -0,0 +1,72 @@ +@echo off +rem +rem $Id$ +rem + +if not "%HB_INC_PGSQL%%HB_DIR_PGSQL%" == "" goto DIR_OK + +echo --------------------------------------------------------------- +echo IMPORTANT: You'll need Postgre SQL package and this envvar +echo to be set to successfully build this library: +echo set HB_INC_PGSQL=C:\pgsql\include +echo or +echo set HB_DIR_PGSQL=C:\pgsql +echo if you want to generate .lib for the .dll. +echo --------------------------------------------------------------- +goto POST_EXIT + +:DIR_OK + +if "%HB_INC_PGSQL%" == "" set HB_INC_PGSQL=%HB_DIR_PGSQL%\include +set CFLAGS=-I"%HB_INC_PGSQL%" +set _HB_DLL_NAME=libpg +set _HB_DLL_DIR=%HB_DIR_PGSQL%\bin +set HB_MAKEFILE=..\..\mtpl_b32.mak +set HB_ROOT = ..\..\.. +set CFLAGS=-I"%HB_INC_PGSQL%";..\..\..\include + +rem --------------------------------------------------------------- + +call ..\..\mtpl_b32.bat %1 %2 %3 %4 %5 %6 %7 %8 %9 + +rem --------------------------------------------------------------- + +if "%HB_DIR_PGSQL%" == "" goto POST_EXIT + +set _HB_INSTALL_PREFIX=%HB_INSTALL_PREFIX% +if "%_HB_INSTALL_PREFIX%" == "" set _HB_INSTALL_PREFIX=..\..\.. +set _HB_LIB_INSTALL=%HB_LIB_INSTALL% +if "%_HB_LIB_INSTALL%" == "" set _HB_LIB_INSTALL=%_HB_INSTALL_PREFIX%\lib + +if "%1" == "clean" goto POST_CLEAN +if "%1" == "Clean" goto POST_CLEAN +if "%1" == "CLEAN" goto POST_CLEAN +if "%1" == "install" goto POST_INSTALL +if "%1" == "Install" goto POST_INSTALL +if "%1" == "INSTALL" goto POST_INSTALL + +:POST_BUILD + + implib ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib "%_HB_DLL_DIR%\%_HB_DLL_NAME%.dll" >> %_HB_MAKELOG% + goto POST_EXIT + +:POST_CLEAN + + if exist ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib del ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib > nul + if exist ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.exp del ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.exp > nul + if exist %_HB_LIB_INSTALL%\%_HB_DLL_NAME%.lib del %_HB_LIB_INSTALL%\%_HB_DLL_NAME%.lib > nul + goto POST_EXIT + +:POST_INSTALL + + if exist %_HB_LIB_INSTALL%\%_HB_DLL_NAME%.lib del %_HB_LIB_INSTALL%\%_HB_DLL_NAME%.lib + if exist ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib copy ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib %_HB_LIB_INSTALL% + goto POST_EXIT + +:POST_EXIT + +set CFLAGS= +set _HB_DLL_NAME= +set _HB_DLL_DIR= +set _HB_INSTALL_PREFIX= +set _HB_LIB_INSTALL= diff --git a/harbour/contrib/rddsql/sddpg/make_gcc.sh b/harbour/contrib/rddsql/sddpg/make_gcc.sh new file mode 100755 index 0000000000..0914afe496 --- /dev/null +++ b/harbour/contrib/rddsql/sddpg/make_gcc.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +# +# $Id$ +# + +if [ "${HB_INC_PGSQL}" = "" ] +then + echo "---------------------------------------------------------------" + echo "IMPORTANT: You will need Postgre SQL package installed and this" + echo " envvar to be set to successfully build this library:" + echo " export HB_INC_PGSQL=C:/pgsql/include" + echo " or" + echo " export HB_INC_PGSQL=/usr/include/postgresql" + echo "---------------------------------------------------------------" + exit 1 +fi + +export CFLAGS="" +export HB_MAKEFILE="../../mtpl_gcc.mak" +for I in ${HB_INC_PGSQL}; do + CFLAGS="${CFLAGS} -I${I}" +done +../../mtpl_gcc.sh $1 $2 $3 $4 $5 $6 $7 $8 $9 +unset CFLAGS +unset HB_MAKEFILE diff --git a/harbour/contrib/rddsql/sddpg/make_vc.bat b/harbour/contrib/rddsql/sddpg/make_vc.bat new file mode 100644 index 0000000000..136e897b33 --- /dev/null +++ b/harbour/contrib/rddsql/sddpg/make_vc.bat @@ -0,0 +1,73 @@ +@echo off +rem +rem $Id$ +rem + +if not "%HB_INC_PGSQL%%HB_DIR_PGSQL%" == "" goto DIR_OK + +echo --------------------------------------------------------------- +echo IMPORTANT: You'll need Postgre SQL package and this envvar +echo to be set to successfully build this library: +echo set HB_INC_PGSQL=C:\pgsql\include +echo or +echo set HB_DIR_PGSQL=C:\pgsql +echo if you want to generate .lib for the .dll. +echo --------------------------------------------------------------- +goto POST_EXIT + +:DIR_OK + +if "%HB_INC_PGSQL%" == "" set HB_INC_PGSQL=%HB_DIR_PGSQL%\include +set CFLAGS=-I"%HB_INC_PGSQL%" +set _HB_DLL_NAME=libpg +set _HB_DLL_DIR=%HB_DIR_PGSQL%\bin +set HB_MAKEFILE=..\..\mtpl_b32.mak +set HB_ROOT = ..\..\.. +set CFLAGS=-I"%HB_INC_PGSQL%";..\..\..\include + +rem --------------------------------------------------------------- + +call ..\..\mtpl_vc.bat %1 %2 %3 %4 %5 %6 %7 %8 %9 + +rem --------------------------------------------------------------- + +if "%HB_DIR_PGSQL%" == "" goto POST_EXIT + +set _HB_INSTALL_PREFIX=%HB_INSTALL_PREFIX% +if "%_HB_INSTALL_PREFIX%" == "" set _HB_INSTALL_PREFIX=..\..\.. +set _HB_LIB_INSTALL=%HB_LIB_INSTALL% +if "%_HB_LIB_INSTALL%" == "" set _HB_LIB_INSTALL=%_HB_INSTALL_PREFIX%\lib + +if "%1" == "clean" goto POST_CLEAN +if "%1" == "Clean" goto POST_CLEAN +if "%1" == "CLEAN" goto POST_CLEAN +if "%1" == "install" goto POST_INSTALL +if "%1" == "Install" goto POST_INSTALL +if "%1" == "INSTALL" goto POST_INSTALL + +:POST_BUILD + + rem Use supplied .lib file. + if not exist ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib copy "%HB_DIR_PGSQL%\lib\%_HB_DLL_NAME%.lib" ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib > nul + goto POST_EXIT + +:POST_CLEAN + + if exist ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib del ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib > nul + if exist ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.exp del ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.exp > nul + if exist %_HB_LIB_INSTALL%\%_HB_DLL_NAME%.lib del %_HB_LIB_INSTALL%\%_HB_DLL_NAME%.lib > nul + goto POST_EXIT + +:POST_INSTALL + + if exist %_HB_LIB_INSTALL%\%_HB_DLL_NAME%.lib del %_HB_LIB_INSTALL%\%_HB_DLL_NAME%.lib + if exist ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib copy ..\..\..\lib\%_HB_CC_NAME%\%_HB_DLL_NAME%.lib %_HB_LIB_INSTALL% + goto POST_EXIT + +:POST_EXIT + +set CFLAGS= +set _HB_DLL_NAME= +set _HB_DLL_DIR= +set _HB_INSTALL_PREFIX= +set _HB_LIB_INSTALL= diff --git a/harbour/contrib/rddsql/sddpg/pgsqldd.c b/harbour/contrib/rddsql/sddpg/pgsqldd.c new file mode 100644 index 0000000000..9e051d0512 --- /dev/null +++ b/harbour/contrib/rddsql/sddpg/pgsqldd.c @@ -0,0 +1,587 @@ +/* + * $Id:$ + */ + +/* + * Postgre SQL Database Driver + * + * Copyright 2007 Mindaugas Kavaliauskas + * 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, or (at your option) + * any later version. + * + * 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 software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries 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 Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + + +#include "hbapi.h" +#include "hbapiitm.h" +#include "hbvm.h" +#include "../hbrddsql.h" + +#include "libpq-fe.h" + +/* TOFIX: these are defined in "server/catalog/pg_type.h", + but including this file generates compile errors. +-Ic:/pgsql/include;c:/pgsql/include/server +#include "postgres.h" +#include "catalog/pg_type.h" +*/ + +#define BOOLOID 16 +#define BYTEAOID 17 +#define CHAROID 18 +#define INT8OID 20 +#define INT2OID 21 +#define INT4OID 23 +#define TEXTOID 25 +#define OIDOID 26 +#define CIDROID 650 +#define FLOAT4OID 700 +#define FLOAT8OID 701 +#define CASHOID 790 +#define MACADDROID 829 +#define INETOID 869 +#define BPCHAROID 1042 +#define VARCHAROID 1043 +#define DATEOID 1082 +#define TIMEOID 1083 +#define TIMESTAMPOID 1114 +#define TIMESTAMPTZOID 1184 +#define TIMETZOID 1266 +#define BITOID 1560 +#define VARBITOID 1562 +#define NUMERICOID 1700 + + +static ERRCODE pgsqlConnect( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ); +static ERRCODE pgsqlDisconnect( SQLDDCONNECTION* pConnection ); +static ERRCODE pgsqlExecute( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ); +static ERRCODE pgsqlOpen( SQLBASEAREAP pArea ); +static ERRCODE pgsqlClose( SQLBASEAREAP pArea ); +static ERRCODE pgsqlGoTo( SQLBASEAREAP pArea, ULONG ulRecNo ); +static ERRCODE pgsqlGetValue( SQLBASEAREAP pArea, USHORT uiIndex, PHB_ITEM pItem ); +static ERRCODE pgsqlGetVarLen( SQLBASEAREAP pArea, USHORT uiIndex, ULONG * pLength ); + + +static SDDNODE pgsqldd = { + NULL, + "POSTGRESQL", + (SDDFUNC_CONNECT) pgsqlConnect, + (SDDFUNC_DISCONNECT) pgsqlDisconnect, + (SDDFUNC_EXECUTE) pgsqlExecute, + (SDDFUNC_OPEN) pgsqlOpen, + (SDDFUNC_CLOSE) pgsqlClose, + (SDDFUNC_GOTO) pgsqlGoTo, + (SDDFUNC_GETVALUE) pgsqlGetValue, + (SDDFUNC_GETVARLEN) pgsqlGetVarLen +}; + + +HB_FUNC_EXTERN( SQLBASE ); + + +static void hb_pgsqldd_init( void * cargo ) +{ + HB_SYMBOL_UNUSED( cargo ); + + if ( ! hb_sddRegister( & pgsqldd ) ) + { + hb_errInternal( HB_EI_RDDINVALID, NULL, NULL, NULL ); + HB_FUNC_EXEC( SQLBASE ); /* force SQLBASE linking */ + } +} + + +#define __PRG_SOURCE__ __FILE__ + +#ifdef HB_PCODE_VER + #undef HB_PRG_PCODE_VER + #define HB_PRG_PCODE_VER HB_PCODE_VER +#endif + +HB_FUNC( SDDPG ) {;} + +HB_INIT_SYMBOLS_BEGIN( sddpostgre__InitSymbols ) +{ "SDDPG", HB_FS_PUBLIC, HB_FUNCNAME( SDDPG ), NULL }, +HB_INIT_SYMBOLS_END( sddpostgre__InitSymbols ) + +HB_CALL_ON_STARTUP_BEGIN( _hb_sddpostgre_init_ ) + hb_vmAtInit( hb_pgsqldd_init, NULL ); +HB_CALL_ON_STARTUP_END( _hb_sddpostgre_init_ ) + +#if defined( HB_PRAGMA_STARTUP ) + #pragma startup sddpostgre__InitSymbols + #pragma startup _hb_sddpostgre_init_ +#elif defined( HB_MSC_STARTUP ) + #if defined( HB_OS_WIN_64 ) + #pragma section( HB_MSC_START_SEGMENT, long, read ) + #endif + #pragma data_seg( HB_MSC_START_SEGMENT ) + static HB_$INITSYM hb_vm_auto_sddpostgre__InitSymbols = sddpostgre__InitSymbols; + static HB_$INITSYM hb_vm_auto_sddpostgre_init = _hb_sddpostgre_init_; + #pragma data_seg() +#endif + + +/* ===================================================================================== */ +static USHORT hb_errRT_PostgreSQLDD( ULONG ulGenCode, ULONG ulSubCode, char * szDescription, char * szOperation, USHORT uiOsCode ) +{ + USHORT uiAction; + PHB_ITEM pError; + + pError = hb_errRT_New( ES_ERROR, "SDDPOSTGRE", ulGenCode, ulSubCode, szDescription, szOperation, uiOsCode, EF_NONE ); + + uiAction = hb_errLaunch( pError ); + + hb_itemRelease( pError ); + + return uiAction; +} + + +/* ============= SDD METHODS ============================================================= */ + +static ERRCODE pgsqlConnect( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ) +{ + PGconn* pConn; + ConnStatusType status; + + pConn = PQsetdbLogin( hb_arrayGetCPtr( pItem, 2 ), NULL, NULL, NULL, hb_arrayGetCPtr( pItem, 5 ), hb_arrayGetCPtr( pItem, 3 ), hb_arrayGetCPtr( pItem, 4 ) ); + + if ( ! pConn ) /* Low memory, etc */ + { + return FAILURE; + } + status = PQstatus( pConn ); + if ( status != CONNECTION_OK ) + { + PQfinish( pConn ); + return FAILURE; + } + pConnection->hConnection = (void*) pConn; + return SUCCESS; +} + + +static ERRCODE pgsqlDisconnect( SQLDDCONNECTION* pConnection ) +{ + if ( ! pConnection->hConnection ) + return FAILURE; + PQfinish( pConnection->hConnection ); + return SUCCESS; +} + + +static ERRCODE pgsqlExecute( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ) +{ + char* szQuery; + int iTuples; + PGresult* pResult; + + szQuery = hb_itemGetCPtr( pItem ); + if ( ! pConnection->hConnection || ! szQuery ) + { + hb_itemClear( pItem ); + return FAILURE; + } + + pResult = PQexec( pConnection->hConnection, szQuery ); + if ( ! pResult ) + { + hb_itemClear( pItem ); + return FAILURE; + } + + iTuples = PQntuples( pResult ); + if ( iTuples > 0 ) + hb_itemPutNI( pItem, iTuples ); + else + { + hb_itemPutNI( pItem, atol( PQcmdTuples( pResult ) ) ); +/* printf( "pgsqlExecute PQoidValue=%d [%s]\n", (int) PQoidValue( pResult ), PQoidStatus( pResult ) ); */ + } + PQclear( pResult ); + return SUCCESS; +} + + +static ERRCODE pgsqlOpen( SQLBASEAREAP pArea ) +{ + PGresult* pResult; + ExecStatusType status; + PHB_ITEM pItemEof, pItem; + USHORT uiFields, uiCount; + BOOL bError; + BYTE* pBuffer; + DBFIELDINFO pFieldInfo; + + + pResult = PQexec( pArea->pConnection->hConnection, pArea->szQuery ); + if ( ! pResult ) + { + hb_errRT_PostgreSQLDD( EG_OPEN, ESQLDD_LOWMEMORY, "Query failed", NULL, 0 ); /* Low memory, etc */ + return FAILURE; + } + + status = PQresultStatus( pResult ); + if ( status != PGRES_TUPLES_OK && status != PGRES_COMMAND_OK ) + { + hb_errRT_PostgreSQLDD( EG_OPEN, ESQLDD_INVALIDQUERY, PQresultErrorMessage( pResult ), pArea->szQuery, status ); + return FAILURE; + } + + pArea->pResult = pResult; + + uiFields = PQnfields( pResult ); + SELF_SETFIELDEXTENT( (AREAP) pArea, uiFields ); + + pItemEof = hb_itemArrayNew( uiFields ); + + pBuffer = ( BYTE* ) hb_xgrab( 256 ); + + bError = FALSE; + for ( uiCount = 0; uiCount < uiFields; uiCount++ ) + { + hb_strncpy( ( char* ) pBuffer, PQfname( pResult, (int) uiCount ), 256 - 1 ); + pFieldInfo.atomName = ( BYTE* ) pBuffer; + pFieldInfo.atomName[ MAX_FIELD_NAME ] = '\0'; + hb_strUpper( ( char* ) pFieldInfo.atomName, MAX_FIELD_NAME + 1 ); + + pFieldInfo.uiDec = 0; + + switch( PQftype( pResult, (int) uiCount ) ) + { + case BPCHAROID: + case VARCHAROID: + pFieldInfo.uiType = HB_FT_STRING; + pFieldInfo.uiLen = (USHORT) PQfsize( pResult, uiCount ) - 4; + break; + + case NUMERICOID: + pFieldInfo.uiType = HB_FT_DOUBLE; + pFieldInfo.uiLen = ( ( PQfsize( pResult, uiCount ) - 4 ) >> 16 ) & 0xFFFF; + pFieldInfo.uiDec = ( PQfsize( pResult, uiCount ) - 4 ) & 0xFFFF; + break; + + case INT2OID: + pFieldInfo.uiType = HB_FT_INTEGER; + pFieldInfo.uiLen = 6; + break; + + case INT4OID: + pFieldInfo.uiType = HB_FT_INTEGER; + pFieldInfo.uiLen = 11; + break; + + case INT8OID: + pFieldInfo.uiType = HB_FT_LONG; + pFieldInfo.uiLen = 20; + break; + + case FLOAT4OID: + case FLOAT8OID: + case CASHOID: /* TODO: ??? */ + pFieldInfo.uiType = HB_FT_DOUBLE; + pFieldInfo.uiLen = 16; + pFieldInfo.uiDec = 2; /* TODO: hb_set.SET_DECIMALS ??? */ + break; + + case BOOLOID: + pFieldInfo.uiType = HB_FT_LOGICAL; + pFieldInfo.uiLen = 1; + break; + + case DATEOID: + pFieldInfo.uiType = HB_FT_DATE; + pFieldInfo.uiLen = 8; + break; + + case INETOID: + pFieldInfo.uiType = HB_FT_STRING; + pFieldInfo.uiLen = 29; + break; + + case CIDROID: + pFieldInfo.uiType = HB_FT_STRING; + pFieldInfo.uiLen = 32; + break; + + case MACADDROID: + pFieldInfo.uiType = HB_FT_STRING; + pFieldInfo.uiLen = 17; + break; + + case BITOID: + case VARBITOID: + pFieldInfo.uiType = HB_FT_STRING; + pFieldInfo.uiLen = PQfsize( pResult, uiCount ); + break; + + case TIMEOID: + pFieldInfo.uiType = HB_FT_STRING; + pFieldInfo.uiLen = 12; + break; + + case TIMESTAMPOID: + pFieldInfo.uiType = HB_FT_STRING; + pFieldInfo.uiLen = 23; + break; + + case TIMETZOID: + pFieldInfo.uiType = HB_FT_STRING; + pFieldInfo.uiLen = 15; + break; + + case TIMESTAMPTZOID: + pFieldInfo.uiType = HB_FT_STRING; + pFieldInfo.uiLen = 26; + break; + + case BYTEAOID: + pFieldInfo.uiType = HB_FT_STRING; + pFieldInfo.uiLen = 0; + break; + + default: + bError = TRUE; + break; + } + /* printf( "field:%s \ttype:%d \tsize:%d \tformat:%d \tmod:%d err=%d\n", pBuffer, PQftype( pResult, (int) uiCount ), PQfsize( pResult, uiCount ), PQfformat( pResult, uiCount ) , PQfmod( pResult, uiCount ), bError ); */ + + if ( ! bError ) + { + switch ( pFieldInfo.uiType ) + { + case HB_FT_STRING: + { + char* pStr; + + pStr = (char*) hb_xgrab( pFieldInfo.uiLen + 1 ); + memset( pStr, ' ', pFieldInfo.uiLen ); + pStr[ pFieldInfo.uiLen ] = '\0'; + + pItem = hb_itemPutCL( NULL, pStr, pFieldInfo.uiLen ); + hb_xfree( pStr ); + break; + } + + case HB_FT_INTEGER: + pItem = hb_itemPutNI( NULL, 0 ); + break; + + case HB_FT_LONG: + pItem = hb_itemPutNL( NULL, 0 ); + break; + + case HB_FT_DOUBLE: + pItem = hb_itemPutND( NULL, 0.0 ); + break; + + case HB_FT_LOGICAL: + pItem = hb_itemPutL( NULL, FALSE ); + break; + + case HB_FT_DATE: + pItem = hb_itemPutDS( NULL, "" ); + break; + + default: + pItem = hb_itemNew( NULL ); + bError = TRUE; + break; + } + + hb_arraySetForward( pItemEof, uiCount + 1, pItem ); + hb_itemRelease( pItem ); + +/* if ( pFieldInfo.uiType == HB_IT_DOUBLE || pFieldInfo.uiType == HB_IT_INTEGER ) + { + pFieldInfo.uiType = HB_IT_LONG; + } */ + + if ( ! bError ) + bError = ( SELF_ADDFIELD( (AREAP) pArea, &pFieldInfo ) == FAILURE ); + } + + if ( bError ) + break; + } + + hb_xfree( pBuffer ); + + if ( bError ) + { + hb_itemClear( pItemEof ); + hb_itemRelease( pItemEof ); + hb_errRT_PostgreSQLDD( EG_CORRUPTION, ESQLDD_INVALIDFIELD, "Invalid field type", pArea->szQuery, 0 ); + return FAILURE; + } + + pArea->ulRecCount = (ULONG) PQntuples( pResult ); + + pArea->pRow = (void**) hb_xgrab( ( pArea->ulRecCount + 1 ) * sizeof( void* ) ); + pArea->pRowFlags = (BYTE*) hb_xgrab( ( pArea->ulRecCount + 1 ) * sizeof( BYTE ) ); + memset( pArea->pRowFlags, 0, ( pArea->ulRecCount + 1 ) * sizeof( BYTE ) ); + + * pArea->pRow = pItemEof; + pArea->pRowFlags[ 0 ] = SQLDD_FLAG_CACHED; + pArea->fFetched = 1; + + return SUCCESS; +} + + +static ERRCODE pgsqlClose( SQLBASEAREAP pArea ) +{ + if ( pArea->pResult ) + PQclear( pArea->pResult ); + return SUCCESS; +} + + +static ERRCODE pgsqlGoTo( SQLBASEAREAP pArea, ULONG ulRecNo ) +{ + if ( ulRecNo <= 0 || ulRecNo > pArea->ulRecCount ) + { + pArea->pRecord = pArea->pRow[ 0 ]; + pArea->bRecordFlags = pArea->pRowFlags[ 0 ]; + + pArea->fPositioned = FALSE; + } + else + { + pArea->pRecord = pArea->pRow[ ulRecNo ]; + pArea->bRecordFlags = pArea->pRowFlags[ ulRecNo ]; + + pArea->fPositioned = TRUE; + } + return SUCCESS; +} + + +static ERRCODE pgsqlGetValue( SQLBASEAREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) +{ + LPFIELD pField; + char* pValue; + BOOL bError; + PHB_ITEM pError; + ULONG ulLen; + + bError = FALSE; + uiIndex--; + pField = pArea->lpFields + uiIndex; + + if ( PQgetisnull( pArea->pResult, pArea->ulRecNo - 1, uiIndex ) ) + return SUCCESS; + + pValue = PQgetvalue( pArea->pResult, pArea->ulRecNo - 1, uiIndex ); + ulLen = (ULONG) PQgetlength( pArea->pResult, pArea->ulRecNo - 1, uiIndex ); + +/* printf( "fieldget recno:%d index:%d value:%s len:%d\n", pArea->ulRecNo, uiIndex, pValue, ulLen ); */ + + switch( pField->uiType ) + { + case HB_FT_STRING: + hb_itemPutCL( pItem, pValue, ulLen ); + break; + + case HB_FT_INTEGER: + case HB_FT_LONG: + case HB_FT_DOUBLE: + if ( pField->uiDec ) + hb_itemPutNDLen( pItem, atof( pValue ), + (int) pField->uiLen - ( (int) pField->uiDec + 1 ), + (int) pField->uiDec ); + else + if ( pField->uiLen > 9 ) + hb_itemPutNDLen( pItem, atof( pValue ), + (int) pField->uiLen, (int) pField->uiDec ); + else + hb_itemPutNLLen( pItem, atol( pValue ), (int) pField->uiLen ); + break; + + case HB_FT_LOGICAL: + hb_itemPutL( pItem, pValue[ 0 ] == 'T' || pValue[ 0 ] == 'Y' ); + break; + + + case HB_FT_DATE: + { + char szDate[ 9 ]; + + szDate[ 0 ] = pValue[ 0 ]; + szDate[ 1 ] = pValue[ 1 ]; + szDate[ 2 ] = pValue[ 2 ]; + szDate[ 3 ] = pValue[ 3 ]; + szDate[ 4 ] = pValue[ 5 ]; + szDate[ 5 ] = pValue[ 6 ]; + szDate[ 6 ] = pValue[ 8 ]; + szDate[ 7 ] = pValue[ 9 ]; + szDate[ 8 ] = '\0'; + hb_itemPutDS( pItem, szDate ); + break; + } + + default: + bError = TRUE; + break; + } + + if ( bError ) + { + pError = hb_errNew(); + hb_errPutGenCode( pError, EG_DATATYPE ); + hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_DATATYPE ) ); + hb_errPutSubCode( pError, EDBF_DATATYPE ); + SELF_ERROR( ( AREAP ) pArea, pError ); + hb_itemRelease( pError ); + return FAILURE; + } + return SUCCESS; +} + + +static ERRCODE pgsqlGetVarLen( SQLBASEAREAP pArea, USHORT uiIndex, ULONG * pLength ) +{ + HB_SYMBOL_UNUSED( pArea ); + HB_SYMBOL_UNUSED( uiIndex ); + HB_SYMBOL_UNUSED( pLength ); + return SUCCESS; +} diff --git a/harbour/contrib/rddsql/sqlbase.c b/harbour/contrib/rddsql/sqlbase.c index a44f7dd5b9..efa2c9e1f0 100644 --- a/harbour/contrib/rddsql/sqlbase.c +++ b/harbour/contrib/rddsql/sqlbase.c @@ -53,7 +53,7 @@ #include "hbapiitm.h" #include "hbvm.h" #include "hbset.h" -#include "hbsqldd.h" +#include "hbrddsql.h" #include "rddsys.ch" diff --git a/harbour/contrib/rddsql/sqlmix.c b/harbour/contrib/rddsql/sqlmix.c index 7480446b06..9ad3d6e7e3 100644 --- a/harbour/contrib/rddsql/sqlmix.c +++ b/harbour/contrib/rddsql/sqlmix.c @@ -63,7 +63,7 @@ #include "hbvm.h" #include "rddsys.ch" -#include "hbsqldd.h" +#include "hbrddsql.h" #include diff --git a/harbour/contrib/rddsql/tests/test1.prg b/harbour/contrib/rddsql/tests/test1.prg index 1c10d510f5..7084cbac01 100644 --- a/harbour/contrib/rddsql/tests/test1.prg +++ b/harbour/contrib/rddsql/tests/test1.prg @@ -17,7 +17,7 @@ #define RDDI_QUERY 1008 -REQUEST MYSQLDD, SQLMIX +REQUEST SDDMY, SQLMIX FIELD RESIDENTS