Vou deixar aqui a solução para registro :
LOCAL cString := 'DRIVER=Firebird/InterBase(r) driver;UID='+cLogin+';PWD='+cPwd+';DBNAME='+cDataBase+';'
cString += "Dialect=3;Charset=UTF8;"
Precisa informar que é UTF8 na string de conexão

Moderador: Moderadores
LOCAL cString := 'DRIVER=Firebird/InterBase(r) driver;UID='+cLogin+';PWD='+cPwd+';DBNAME='+cDataBase+';'
cString += "Dialect=3;Charset=UTF8;"
FBCreateDB( oSQL_DataBase, oSQL_Login, oSQL_Pwd, oSQL_nPageSize, oSQL_cCharSet, oSQL_nDialect ) // precisa hbfbird.lib
Procedure ImportaDBF_SQL(o_TableDBF,o_TableSQL)
Local _erro:=""
ShowWait(,,"Importando dados da tabela DBF: ( "+o_TableDBF+" ), para a tabela SQL: ( "+o_TableSQL+" )...")
w_vTXT:=""
&o_TableDBF.->(DbGoTop())
e_TableDBF := &o_TableDBF.->(DbStruct()) //pega a estrutura dbf
o_LastRec := AllTrim(Str(&o_TableDBF.->(LastRec()),10))
wSaida:=.F.
While &o_TableDBF.->(!Eof()) .And. wSaida=.F.
w_vTXT := "Registro ( "+AllTrim(Str(&o_TableDBF.->(RecNo()),10))+" ) de ( "+o_LastRec+" )..."
ShowWaitProc()
wSaida := ExitSeek()
StrSql := MyImport_DBF_SQL(o_TableDBF,e_TableDBF,o_TableSQL)
If !Empty(oSQL_CnnDB) .And. Empty( _erro:= FB_executa())
//se nao deu erro, apaga o registro na tabela dbf
While &o_TableDBF.->(!RLock())
Showmessage(,,"Registro em uso, solicite liberação do mesmo...",1)
End
&o_TableDBF.->(DbDelete())
&o_TableDBF.->(DbCommit())
&o_TableDBF.->(DbUnLock())
Else
//gerar uym log do sql erro
Exit
EndIf
&o_TableDBF.->(DbSkip(1))
End
CloseWindow()
Return .T.
Static Function MyImport_DBF_SQL(o_TableDBF,e_TableDBF,o_TableSQL) //monta o strsql
Local iS,o_Field,oStrSql:="insert into "+o_TableSQL,oStrSqlF:="(",oStrSqlV:="("
For iS:= 1 To Len(e_TableDBF)
ShowWaitProc()
o_Field := e_TableDBF[iS,1]
oStrSqlF += e_TableDBF[iS,1] + If(iS=Len(e_TableDBF),")",",")
oStrSqlV += DB_SQLValue(&o_TableDBF.->&o_Field.) + If(iS=Len(e_TableDBF),")",",")
Next
Return oStrSql+=oStrSqlF + " values "+oStrSqlV
Static Function DB_SQLValue(oSQL) //modifica os dados de acordo com o sql validando o retorno, colaboração dos colegas
Do Case
Case ValType(oSQL)=="N"
oSQL:=LTrim(Str(oSQL))
Case ValType(oSQL)=="L"
If( oSQL , oSQL:= "1" , oSQL:= "0")
Case ValType(oSQL)=="D"
If(Empty( oSQL ) , oSQL:= "NULL", oSQL:= ['] + Transform(DtoS(oSQL),"@R 9999-99-99" ) + ['])
Case ValType(oSQL)=="C"
If(Empty( oSQL ) , oSQL:= "NULL", oSQL:= ['] + StrTran(upper(oSQL),"'"," ") + ['])
Otherwise
oSQL:= "NULL"
EndCase
Return oSQL
#include "adodb.ch"
Function Main
LOCAL oRs , oCn, cSql
LOCAL cUsername := "SYSDBA"
LOCAL cPassWord := "masterkey"
LOCAL cDatabase := hb_Dirbase() + "sistemas33.fdb"
LOCAL cDb := "Driver=Firebird/InterBase(r) driver;Uid=" + cUserName + ";Pwd=" + cPassword + ";DbName=" + cDataBase + ";"
//oCn := TOleauto():New('ADODB.Connection') // Classe usada por xHarbour. Exige xhb.hbc para compilar
oCn := win_oleCreateObject( "ADODB.Connection" )
oCn:ConnectionString := cDb
oCn:Open()
oRs := win_oleCreateObject( "ADODB.Recordset" )
//oRs := TOleAuto():New('ADODB.Recordset') // Classe usada por xHarbour. Exige xhb.hbc para compilar
oRs:CursorLocation = adUseClient
oRs:Open( "SELECT * FROM emp", oCn , adOpenDynamic, adLockOptimistic )
if oCn:State = adStateClose
? ('Failed open table EMP')
Return
Endif
if oRs:recordcount > 0
oRs:Movefirst()
do while !oRs:eof()
? oRs:fields("ename"):value
oRs:movenext()
enddo
oRs:Movefirst() // Opcional, retorna para o primeiro registro
endif
RETURN NIL
#define adOpenForwardOnly 0
#define adOpenKeyset 1
#define adOpenDynamic 2
#define adOpenStatic 3
#define adLockReadOnly 1
#define adLockPessimistic 2
#define adLockOptimistic 3
#define adLockBatchOptimistic 4
#define adUseNone 1
#define adUseServer 2
#define adUseClient 3
PROCEDURE MAIN()
LOCAL oRs , oCn, cSql
LOCAL cUsername := "SYSDBA"
LOCAL cPassWord := "masterkey"
LOCAL cDatabase := hb_Dirbase() + "sistemas33.fdb"
LOCAL cDb := "Driver=Firebird/InterBase(r) driver;Uid=" + cUserName + ";Pwd=" + cPassword + ";DbName=" + cDataBase + ";"
oCn := win_oleCreateObject( "ADODB.Connection" )
oCn:ConnectionString := cDb
oCn:Open()
//oRs := win_oleCreateObject("ADODB.RecordSet")
cSql := "INSERT INTO emp ( empno, ename ) VALUES ( 122 , 'NOVO NOME' )"
? "Execute : " , oCn:Execute( cSql )
oCn:Close()
RETURN
Onde oSQL_cCharSet eu passo "win1252", não testei com acentos, vou fazer.
FBCreateDB( cServer + xBanco, cUser, cPass, nPageSize, cCharSet, nDialect )
FBCreateDB( cServer + xBanco, cUser, cPass, nPageSize, cCollate, nDialect )
FBCreateDB( cServer + xBanco, cUser, cPass, nPageSize,cCharset, cCollate, nDialect )
Vlademiro escreveu:Percorrendo a tabela (tem que criar dois objetos, o oCn (Para se conectar ao banco) e o oRs (RecordSet que armazena o retorno do select)
oRs := win_oleCreateObject( "ADODB.Recordset" )
oRs:CursorLocation = adUseClient
oRs:Open( "SELECT * FROM emp", oCn , adOpenDynamic, adLockOptimistic )
if oCn:State = adStateClose
? ('Failed open table EMP')
Return
Endif
oRs := oCn:Execute( "SELECT * FROM emp" )
Usuários vendo este fórum: Nenhum usuário registrado online e 8 visitantes