Iniciar testes com MariaDB.

Moderador: Moderadores
asimoes escreveu:Qual é a string de conexão para usar o MariaDb?
Quais suas impressões sobre esse SGBD
Erro executando comando:-2147217900 [MySQL][ODBC 5.3(a) Driver][mysqld-5.5.66-MariaDB]Can't DROP 'NOTA'; check that column/key exists
IF ! :IndexExists( "JPNOTFIS", "NOTA" )
:ExecuteCmd( "ALTER TABLE JPNOTFIS DROP INDEX NOTA" )
ENDIF
/*
ZE_SQLFROMDBF - Transfere de DBF pra MySQL incluindo ou não
José Quintas
*/
#include "inkey.ch"
#include "dbstruct.ch"
#define MYSQL_MAX_CMDINSERT 500000
FUNCTION SqlFromDbf()
LOCAL oFiles, nCont, acAchoice := {}, cFileDbf, nOpc := 1, cConfirma := "NAO", GetList := {}
@ 2, 1 SAY "ATENÇÃO"
@ Row() + 1, 1 SAY "Os dados dos DBFs são salvos no MySql."
@ Row() + 1, 1 SAY "Se quiser eliminar dados anteriores do MySql, precisa fazer manualmente"
@ Row() + 1, 1 SAY "Se quiser eliminar dados finais do DBF, precisa fazer manualmente"
oFiles := CnfDbfInd()
FOR nCont = 1 TO Len( oFiles )
AAdd( acAchoice, oFiles[ nCont, 1 ] )
NEXT
DO WHILE .T.
wAchoice( Row() + 1, 5, acAchoice, @nOpc, "Arquivos a transferir" )
IF LastKey() == K_ESC
EXIT
ENDIF
cFileDbf := Upper( oFiles[ nOpc, 1 ] )
Mensagem( "Confirme criar estrutura para " + cFileDbf )
@ Row(), Col() + 2 GET cConfirma PICTURE "@!"
READ
Mensagem()
IF LastKey() == K_ESC .OR. cConfirma != "SIM"
LOOP
ENDIF
CopyDbfToMySql( cFileDbf, .F., .T., .F., cFileDbf )
ENDDO
RETURN NIL
FUNCTION CopyDbfToMySql( cTable, lTransfere, lCria, lZera, cNewTable )
LOCAL oStru
LOCAL cSql, xValue, nCont, cSqlFix
LOCAL lBegin := .T., cTxt, cKeyName
LOCAL cnGERAL := ADOClass():New( AppConexao() )
LOCAL nSelect := Select()
IF ! File( cTable + iif( ".DBF" $ Upper( cTable ), "", ".DBF" ) )
RETURN NIL
ENDIF
hb_Default( @lCria, .F. )
hb_Default( @lZera, .F. )
hb_Default( @cNewTable, cTable )
cTable := Upper( cTable )
SELECT 0
USE ( cTable ) ALIAS DbfDb
oStru := dbStruct()
cKeyName := "ID" + iif( Left( cTable, 2 ) $ "JP,HL", Substr( cTable, 3 ), cTable )
USE
cSql := "CREATE TABLE IF NOT EXISTS " + cNewTable + " ( " + cKeyName + " INT(9) NOT NULL AUTO_INCREMENT, "
FOR nCont = 1 TO Len( oStru )
IF oStru[ nCont, DBS_NAME ] != cKeyName
cSql += oStru[ nCont, DBS_NAME ] + " "
DO CASE
CASE oStru[ nCont, DBS_TYPE ] == "N"
IF oStru[ nCont, DBS_DEC ] == 0
cSql += " INT( " + Ltrim( Str( oStru[ nCont, DBS_LEN ] ) ) + " ) DEFAULT 0"
ELSE
cSql += " DOUBLE( " + Ltrim( Str( oStru[ nCont, DBS_LEN ] ) ) + " , " + Ltrim( Str( oStru[ nCont, DBS_DEC ] ) ) + " ) DEFAULT 0"
ENDIF
CASE oStru[ nCont, DBS_TYPE ] == "C"
IF oStru[ nCont, DBS_LEN ] < 250
cSql += " VARCHAR( " + Ltrim( Str( oStru[ nCont, DBS_LEN ] ) ) + " ) DEFAULT '' "
ELSE
cSql += " TEXT"
ENDIF
CASE oStru[ nCont, DBS_TYPE ] == "D"
cSql += " DATE "
CASE oStru[ nCont, DBS_TYPE ] == "M"
cSql += " TEXT "
ENDCASE
cSql += " , "
ENDIF
NEXT
cSql += " PRIMARY KEY ( " + cKeyName + " )"
cSql += " )"
cSql += ";"
SayScroll( "Salvando no MySql " + cTable )
IF lCria
cnGERAL:ExecuteCmd( cSql )
ENDIF
IF lZera
cnGERAL:ExecuteCmd( "TRUNCATE TABLE " + cNewTable )
ENDIF
IF ! lTransfere
SELECT ( nSelect )
RETURN NIL
ENDIF
SELECT 0
USE ( cTable ) ALIAS DbfDb
GrafTempo( "Processando " + cTable )
cSqlFix := "INSERT INTO " + cNewTable + " ( "
FOR nCont = 1 TO FCount()
cSqlFix += FieldName( nCont )
IF nCont != FCount()
cSqlFix += ", "
ENDIF
NEXT
cSqlFix += " ) VALUES "
cTxt := ""
DO WHILE ! Eof()
GrafTempo( RecNo(), LastRec() )
Inkey()
cSql := "( "
FOR nCont = 1 TO FCount()
xValue := FieldGet( nCont )
DO CASE
CASE ValType( xValue ) == "N"
cSql += NumberSql( xValue )
CASE ValType( xValue ) == "D"
cSql += DateSql( xValue )
CASE ValType( xValue ) == "C"
xValue := MySqlValidString( xValue )
cSql += StringSql( xValue )
OTHERWISE
cSql += "NULL"
ENDCASE
IF nCont != FCount()
cSql += ","
ENDIF
NEXT
cSql += " )"
IF Len( cTxt ) == 0
cTxt += cSqlFix
lBegin := .T.
ENDIF
IF ! lBegin
cTxt += ", "
ENDIF
lBegin := .F.
cTxt += cSql
IF Len( cTxt ) > MYSQL_MAX_CMDINSERT
cnGERAL:ExecuteCmd( cTxt )
cTxt := ""
ENDIF
SKIP
ENDDO
IF Len( cTxt ) != 0
cnGERAL:ExecuteCmd( cTxt )
ENDIF
USE
SELECT ( nSelect )
RETURN NIL
#define MYSQL_INSERT_COMPLETE 1
#define MYSQL_INSERT_NONAMES 2
FUNCTION cmdSQLInsert( nInsertType, cTableName )
LOCAL cSql := "", nCont, xValue
hb_Default( @nInsertType, MYSQL_INSERT_COMPLETE )
hb_Default( @cTableName, Alias() )
IF nInsertType == MYSQL_INSERT_COMPLETE
cSql := cSql + "INSERT INTO `" + cTableName + "` "
ENDIF
IF nInsertType == MYSQL_INSERT_COMPLETE
cSql += "( "
FOR nCont = 1 TO FCount()
cSql += "`" + FieldName( nCont ) + "`"
IF nCont != FCount()
cSql += ", "
ENDIF
NEXT
cSql += " ) "
cSql += "VALUES "
ENDIF
cSql += "( "
FOR nCont = 1 TO FCount()
xValue := FieldGet( nCont )
DO CASE
CASE ValType( xValue ) == "N"
cSql += NumberSql( xValue )
CASE ValType( xValue ) == "D"
cSql += DateSql( xValue )
CASE ValType( xValue ) == "C"
xValue := MySqlValidString( xValue )
cSql += StringSql( xValue )
OTHERWISE
cSql += "NULL"
ENDCASE
IF nCont != FCount()
cSql += ","
ENDIF
NEXT
cSql += " ) "
RETURN cSql
FUNCTION CopyRecordToMySql( cDatabase, cChaveAcesso )
LOCAL nCont, lInsert := .T., cnMySql := ADOClass():New( AppConexao() )
IF cChaveAcesso != NIL
lInsert := ( ADORecCount( cDatabase, cChaveAcesso ) == 0 )
ENDIF
WITH OBJECT cnMySql
:QueryCreate()
FOR nCont = 1 TO FCount()
:QueryAdd( FieldName( nCont ), FieldGet( nCont ) )
NEXT
IF lInsert
:QueryExecuteInsert( cDatabase )
ELSE
:QueryExecuteUpdate( cDatabase, cChaveAcesso )
ENDIF
ENDWITH
RETURN NIL
STATIC FUNCTION MySqlValidString( xValue )
xValue := StrTran( xValue, Chr(91), " " )
xValue := StrTran( xValue, Chr(93), " " )
xValue := StrTran( xValue, Chr(167), " " )
xValue := StrTran( xValue, Chr(128), "C" )
xValue := StrTran( xValue, Chr(135), "C" )
xValue := StrTran( xValue, Chr(166), "A" )
xValue := StrTran( xValue, Chr(198), "A" )
xValue := StrTran( xValue, Chr(0), "" )
//xValue := StrTran( xValue, Chr(95), "-" ) // usada em email barra inferior
xValue := StrTran( xValue, Chr(229), "O" )
xValue := StrTran( xValue, Chr(124), " " )
xValue := StrTran( xValue, Chr(141), " " )
xValue := StrTran( xValue, Chr(181), " " )
xValue := StrTran( xValue, Chr(162), " " )
xValue := StrTran( xValue, Chr(224), " " )
xValue := StrTran( xValue, Chr(133), " " )
xValue := StrTran( xValue, Chr(144), "E" )
xValue := StrTran( xValue, Chr(160), " " )
RETURN xValue
Usuários vendo este fórum: Nenhum usuário registrado online e 14 visitantes