Re: code page
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: code page
- From: Marco Antonio Abreu <mabreu.ti@...>
- Date: 2009年5月13日 16:39:24 -0300
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 .. "'"
else
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'
else
return 'false'
end
else
return string.format( "N'%s'", string.gsub( tostring( valor ), "'", "\\'" ) ) --> o 'N' é para resolver os acentos
end
end
end
return cmd:gsub( '(%$)([%w%_]+)', trocaPalavra ) -- pega um cifrao seguido de uma palavra
end
...
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?
tks
Marco
2009年5月13日 Ignacio Burgueño
<ignaciob@inconcertcc.com>
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.
Regards,
Ignacio
--
Marco Antonio Abreu
Analista de Sistemas
- References:
- code page, Marco Antonio Abreu
- Re: code page, Ignacio Burgueño
- Re: code page, Marco Antonio Abreu
- Re: code page, Ignacio Burgueño
- Re: code page, Ignacio Burgueño
- Re: code page, Marco Antonio Abreu
- Re: code page, David Given
- Re: code page, Ignacio Burgueño
- Re: code page, Marco Antonio Abreu
- Re: code page, Ignacio Burgueño