mwild1 / luadbi

Multi-backend SQL database library for Lua
MIT License
38 stars 14 forks source link

enum fields seems not correct in lua-dbi #21

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago

I got some gap like "ØîxÑ6" or partical content of an varchar field if i 
fetch an enum field with lua-dbi

lua-dbi-0.5-2,lua-5.1.4-4,mysql-5.1.69,mysql-5.1.69 server,CentOS 6.4 64bit 

mysql> describe dp_public;
+--------------------+-----------------------------+------+-----+----------+----
------------+
| Field              | Type                        | Null | Key | Default  | 
Extra          |
+--------------------+-----------------------------+------+-----+----------+----
------------+
| id                 | int(10)                     | NO   | PRI | NULL     | 
auto_increment |
| destination_number | varchar(64)                 | NO   |     |          |    
            |
| direction          | enum('internal','external') | NO   |     | internal |    
            |
| bridge             | varchar(64)                 | NO   |     |          |    
            |
+--------------------+-----------------------------+------+-----+----------+----
------------+

mysql> select * from dp_public; 
+----+--------------------+-----------+---------------+
| id | destination_number | direction | bridge        |
+----+--------------------+-----------+---------------+
|  4 | playrand           | internal  | 172.20.120.76 |
+----+--------------------+-----------+---------------+

-- Logging
LOGLEVEL = "info"

-- Progname
PROGNAME = "doit.lua"

-- functions
function logger(message)
    print(LOGLEVEL,"["..PROGNAME.."] "..message.."\n")
end

function mysqldp(u)
    if u == nil then
        return
    end

    local dbh = assert(DBI.Connect('MySQL', mydb, myuser, mypass, myhost))
    --local sth = assert(dbh:prepare('SELECT `id`, `direction`, `bridge` FROM `dp_public` WHERE id=4 LIMIT 1'))
    local sth = assert(dbh:prepare('SELECT `direction` FROM `dp_public` WHERE id=4 LIMIT 1'))
    sth:execute()

    row = sth:fetch ({}, "a")
    if not row then
        return
    end
logger("row.direction " ..row.direction)
    id = row.id
    direction = row.direction
    destination_number = row.destination_number
    target = row.bridge
logger("direction "..direction)

    dbh:close()
    sth:close()

    return id,destination_number,direction,target
end

number='playrand'
mysqldp(number)

lua doit.lua 
info    [sqluser.lua] row.direction internalØîxÑ6
info    [sqluser.lua] direction internalØîxÑ6

Original issue reported on code.google.com by khorsm...@gmail.com on 3 Jun 2013 at 1:40

GoogleCodeExporter commented 8 years ago
I believe this is fixed in the latest commits, as I couldn't reproduce it when 
testing with the current code. I'll close this issue, but if you still have 
problems feel free to re-open it.

Original comment by MWild1 on 30 Jul 2014 at 10:07