Dear Mr.Rao&Antonio,
Is it possible the make FWMARIADB to use all (MySql, MariaDB and PostgeSQL) with one code in the future?
It will be useful for user to choose RDBMS?
Regards,
Dutch
nageswaragunupudi wrote:But please tell me why do you want postgresql?
Isn't mariadb enough?
#include "fivewin.ch"
#include "dbstruct.ch"
#include "mysql.ch"
#include "DbStruct.ch"
#define _STRU_FIELDNAME 1
#define _STRU_FIELDTYPE 2
#define _STRU_FIELDLEN 3
#define _STRU_FIELDDEC 4
#define _STRU_TABLE 5
#define _STRU_TABLECOL 6
REQUEST DBFNTX
REQUEST DBFCDX
REQUEST DBFFPT
REQUEST DBFDBT
#define DB_ALIAS 1
#define DB_FILE 2
#define DB_QUERY 3
#define DB_ROW 4
#define DB_FETCH 5
function main()
mysqlservername := "192.168.1.2"
username := "simrs"
password := "8091016"
oserver:= TMySQLServer():New(mysqlservername,username,password)
IF oServer:NetErr()
?oServer:Error()
ENDIF
oServer:SelectDB( "blu" )
IF oServer:NetErr()
?oServer:Error()
ENDIF
cFileORIG := "customer.dbf"
cFileDEST := "mst_customer"
lAppend := .t.
ConvertToSQL(cFileORIG,cFileDEST,lAppend,oServer)
oserver:destroy()
return
static function ConvertToSQL(cFileORIG,cFileDEST,lAppend,oServer)
local cComm, apCode, cOut
local nErr, nPos
LOCAL vEmp := {}
Local nCnn, s,oSql
local aReturn := {}
local aReturnX := {}
cFileORIG := lower(alltrim(cFileORIG))
cFileDEST := lower(alltrim(cFileDEST))
define dialog oDlgStock from 1,1 to 40,400 pixel style nOR( WS_CAPTION ) title "Tunggu Sebentar"
activate dialog oDlgStock centered nowait
oDlgStock:cTitle := cFileDEST
SysRefresh()
dbCloseAll()
cSql := "DROP TABLE IF EXISTS "+cFileDEST
oQuery := oServer:Query( cSql )
IF oQuery:NetErr()
?oQuery:Error()
ENDIF
oQuery:Destroy()
dbCloseAll()
use (cFileORIG) new shared alias orig
aStruct := orig->(DbStruct())
cField := ""
for i := 1 to len(aStruct)
cFieldName := alltrim(aStruct[i][DBS_NAME])
if lower(cFieldName) == "index"
cFieldName := "XINDEX"
endif
cType := aStruct[i][DBS_TYPE]
cLen := alltrim(Str( aStruct[i][DBS_LEN ], 3 ))
cDec := alltrim(Str( aStruct[i][DBS_DEC ], 3 ))
cOke := ""
if cType == "C"
cOke := " "+cFieldName+" CHAR ("+cLen+") , "
endif
if cType == "M"
cOke := " "+cFieldName+" CHAR (150) , "
endif
if cType == "N"
if val(cDec) == 0
cOke := " "+cFieldName+" NUMERIC ( "+cLen+", 0) , "
else
cOke := " "+cFieldName+" NUMERIC ( "+cLen+", 2) , "
endif
endif
if cType == "D"
cOke := " "+cFieldName+" DATE, "
endif
if cType == "L"
cOke := " "+cFieldName+" BOOLEAN, "
endif
cField += cOke
next
cField := upper(cField)
cSql := "CREATE TABLE "+cFileDEST+" ( recno_key serial primary key, "
cSQL += cField
cSQL += " edited_date DATE, edited_time CHAR(8) "
cSQL += " );"
?cSql
oQuery := oServer:Query( cSql )
IF oQuery:NetErr()
?oQuery:Error()
ENDIF
oQuery:Destroy()
if lAppend
dbCloseAll()
use (cFileORIG) new shared alias orig
nMulai := 0
nPersen := 0
nRecord := orig->(lastrec())
orig->(dbGotop())
do while !orig->(eof())
++nMulai
nPersen := ( nMulai / nRecord ) * 100
oDlgStock:cTitle := cFileDEST +" "+str(nMulai,12)+"/"+str(nRecord,12)+"="+str(nPersen,12)+"%"
SysRefresh()
cFieldJalan := alltrim(orig->(FieldName(1)))
cDatanya := orig->&cFieldJalan
if valtype(cDatanya) == "N"
cDatanya := alltrim(str(cDatanya,14,2))
else
cDatanya := "'"+upper(alltrim(cDatanya))+"'"
endif
cSQL := "INSERT INTO "+alltrim(cFileDEST)+" ( "+cFieldJalan+" ) VALUES ( "+cDatanya+" )"
oQuery := oServer:Query( cSql )
IF oQuery:NetErr()
?oQuery:Error()
ENDIF
oQuery:Destroy()
for x := 2 to orig->(fcount())
cFieldJalan := alltrim(orig->(FieldName(x)))
cDatanya := orig->&cFieldJalan
if valtype(cDatanya) == "N"
cDatanya := alltrim(str(cDatanya,14,2))
endif
if valtype(cDatanya) == "D"
cTahun := strzero(year(cDatanya),4)
cBulan := strzero(month(cDatanya),2)
cTgl := strzero(day(cDatanya),2)
cDatanya := cTahun+"-"+cBulan+"-"+cTgl
endif
if valtype(cDatanya) == "L"
if cDatanya
cDatanya := "1"
else
cDatanya := "0"
endif
endif
if valtype(cDatanya) == "C"
cChar := ""
for xx := 1 to len(cDatanya)
cOke := subs(cDatanya,xx,1)
if cOke == "'"
cOke := ""
endif
cChar += cOke
next
cDatanya := "'"+upper(alltrim(cChar))+"'"
endif
if valtype(cDatanya) == "M"
cDatanya := "'"+upper(alltrim(cDatanya))+"'"
endif
cSql := "UPDATE "+alltrim(cFileDEST)+" SET "+cFieldJalan+" = "+cDatanya+" WHERE recno_key = "+alltrim(str(nMulai,12))
oQuery := oServer:Query( cSql )
IF oQuery:NetErr()
?oQuery:Error()
ENDIF
oQuery:Destroy()
next
orig->(dbSkip())
enddo
dbCloseAll()
endif
**********************
oDlgStock:End()
return nil
a litle faster than mysql for Insert command
at the end is a personal election
But I'm happy that FW has support to PG
nageswaragunupudi wrote:But please tell me why do you want postgresql?
Isn't mariadb enough?
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 21 guests