lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Of course, Ignacio. Follow below...

I have some queries which retrieve the values from the MS SQL. Then I use these queries to insert into the MySQL tables. I use the function ParseCommand to replace the vales in the insert queries with the corresponding values. It searches for a $name and substitute it for its value in a table.

After it a execute the query directly to the MySQL connection.

local function parseCommand( cmd, row, id )
    local function trocaPalavra( _, p )
        if p == 'id' then
            return tostring( id )
        elseif p == 'dtsync' then
            return dtsync
        elseif p == 'dtagora' then
            return dtagora
        elseif p == 'unidade' then
            return "'" .. unidade_atual .. "'"
            local valor = row[ p ]
            local tipo = type( valor )
            if tipo == 'number' then
                return tostring( valor )
            elseif tipo == 'nil' then
                return 'NULL'
            elseif tipo == 'boolean' then
                if valor then
                    return 'true'
                    return 'false'
                return string.format( "N'%s'", string.gsub( tostring( valor ), "'", "\\'" ) ) --> o 'N' é para resolver os acentos

    return cmd:gsub( '(%$)([%w%_]+)', trocaPalavra ) -- pega um cifrao seguido de uma palavra
tabelas = { feriado = { selectSQL = "...", insertSQL = "INSERT INTO feriado( unidade, data, tipo ) VALUES( $unidade, $data, $tipo ) ON DUPLICATE KEY UPDATE unidade = $unidade, data = "" tipo = $tipo" }, ... }
for _, tabela in pairs( tabelas ) do
  row = curSQLServer:fetch( {}, 'a' )
  newid = newid + 1
  sql = parseCommand( tabela.insertSQL, row, newid )
  ra, msg = conMySQL:execute( sql )
end -- for(tabelas)

What do you think?

2009/5/13 Ignacio Burgueño <>
Marco Antonio Abreu wrote:
Hi Ignacio,
The DLL works, don't trancate the vales any more. But now returns the problem writing wrong chars (garbage) at the destination database. In our example, it now writes 'Flávia' in the field even with the 'N' flag before the string. Should we resolve it with a gsub substituition or you know a better solution?

Well, I think that this is a different problem. This time I think your utf-8 encoded strings gets blindly treated as iso-8859-1. As David suggested, you need to check the pipeline Lua -> LuaSql -> MySql and see where it breaks.

Can you show some code? Mostrly regarding the part you write to MySql.


Marco Antonio Abreu
Analista de Sistemas