Coder Social home page Coder Social logo

luasql's People

Contributors

amdmi3 avatar andreasbhansen avatar blumf avatar bobcalco avatar cazfi avatar chaitanyad48 avatar cpu avatar davidalphafox avatar deining avatar echiesse avatar essgeeeich avatar gnarz avatar hishamhm avatar ignacio avatar ir4t4 avatar jk77 avatar juanper avatar kcousins avatar laigor avatar mcepl avatar mpeterv avatar ousnius avatar rafis avatar rmarquis avatar saspivey98 avatar seanpringle avatar timn avatar tomasguisasola avatar tst2005 avatar w-oertl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

luasql's Issues

Error in making

gcc -O2 -std=gnu99 -Wall -Wmissing-prototypes -Wmissing-declarations -pedantic -fPIC -I/usr/include/lua5.1 -DLUASQL_VERSION_NUMBER='"2.3.4"' -c src/luasql.c -o src/luasql.o gcc -O2 -std=gnu99 -Wall -Wmissing-prototypes -Wmissing-declarations -pedantic -fPIC -I/usr/include/lua5.1 -DLUASQL_VERSION_NUMBER='"2.3.4"' src/ls_mysql.c -o src/mysql.so -shared src/luasql.o -I/usr/include/mysql -L/usr/lib -lmysqlclient -lz src/ls_mysql.c:19:19: error: mysql.h: No such file or directory src/ls_mysql.c:69: error: expected specifier-qualifier-list before ‘MYSQL’ src/ls_mysql.c:77: error: expected specifier-qualifier-list before ‘MYSQL_RES’ src/ls_mysql.c:130: warning: ISO C forbids forward references to ‘enum’ types src/ls_mysql.c:130: warning: ‘enum enum_field_types’ declared inside parameter list src/ls_mysql.c:130: warning: its scope is only this definition or declaration, which is probably not what you want src/ls_mysql.c:130: error: parameter 1 (‘type’) has incomplete type src/ls_mysql.c: In function ‘getcolumntype’: src/ls_mysql.c:133: error: ‘FIELD_TYPE_VAR_STRING’ undeclared (first use in this function) src/ls_mysql.c:133: error: (Each undeclared identifier is reported only once src/ls_mysql.c:133: error: for each function it appears in.) src/ls_mysql.c:133: error: ‘FIELD_TYPE_STRING’ undeclared (first use in this function) src/ls_mysql.c:135: error: ‘FIELD_TYPE_DECIMAL’ undeclared (first use in this function) src/ls_mysql.c:135: error: ‘FIELD_TYPE_SHORT’ undeclared (first use in this function) src/ls_mysql.c:135: error: ‘FIELD_TYPE_LONG’ undeclared (first use in this function) src/ls_mysql.c:136: error: ‘FIELD_TYPE_FLOAT’ undeclared (first use in this function) src/ls_mysql.c:136: error: ‘FIELD_TYPE_DOUBLE’ undeclared (first use in this function) src/ls_mysql.c:136: error: ‘FIELD_TYPE_LONGLONG’ undeclared (first use in this function) src/ls_mysql.c:137: error: ‘FIELD_TYPE_INT24’ undeclared (first use in this function) src/ls_mysql.c:137: error: ‘FIELD_TYPE_YEAR’ undeclared (first use in this function) src/ls_mysql.c:137: error: ‘FIELD_TYPE_TINY’ undeclared (first use in this function) src/ls_mysql.c:139: error: ‘FIELD_TYPE_TINY_BLOB’ undeclared (first use in this function) src/ls_mysql.c:139: error: ‘FIELD_TYPE_MEDIUM_BLOB’ undeclared (first use in this function) src/ls_mysql.c:140: error: ‘FIELD_TYPE_LONG_BLOB’ undeclared (first use in this function) src/ls_mysql.c:140: error: ‘FIELD_TYPE_BLOB’ undeclared (first use in this function) src/ls_mysql.c:142: error: ‘FIELD_TYPE_DATE’ undeclared (first use in this function) src/ls_mysql.c:142: error: ‘FIELD_TYPE_NEWDATE’ undeclared (first use in this function) src/ls_mysql.c:144: error: ‘FIELD_TYPE_DATETIME’ undeclared (first use in this function) src/ls_mysql.c:146: error: ‘FIELD_TYPE_TIME’ undeclared (first use in this function) src/ls_mysql.c:148: error: ‘FIELD_TYPE_TIMESTAMP’ undeclared (first use in this function) src/ls_mysql.c:150: error: ‘FIELD_TYPE_ENUM’ undeclared (first use in this function) src/ls_mysql.c:150: error: ‘FIELD_TYPE_SET’ undeclared (first use in this function) src/ls_mysql.c:152: error: ‘FIELD_TYPE_NULL’ undeclared (first use in this function) src/ls_mysql.c: In function ‘create_colinfo’: src/ls_mysql.c:164: error: ‘MYSQL_FIELD’ undeclared (first use in this function) src/ls_mysql.c:164: error: ‘fields’ undeclared (first use in this function) src/ls_mysql.c:167: warning: implicit declaration of function ‘mysql_fetch_fields’ src/ls_mysql.c:167: error: ‘cur_data’ has no member named ‘my_res’ src/ls_mysql.c:173: error: type of formal parameter 1 is incomplete src/ls_mysql.c: In function ‘cur_nullify’: src/ls_mysql.c:189: warning: implicit declaration of function ‘mysql_free_result’ src/ls_mysql.c:189: error: ‘cur_data’ has no member named ‘my_res’ src/ls_mysql.c: In function ‘cur_fetch’: src/ls_mysql.c:201: error: ‘MYSQL_RES’ undeclared (first use in this function) src/ls_mysql.c:201: error: ‘res’ undeclared (first use in this function) src/ls_mysql.c:201: error: ‘cur_data’ has no member named ‘my_res’ src/ls_mysql.c:203: error: ‘MYSQL_ROW’ undeclared (first use in this function) src/ls_mysql.c:203: error: expected ‘;’ before ‘row’ src/ls_mysql.c:204: error: ‘row’ undeclared (first use in this function) src/ls_mysql.c:209: warning: implicit declaration of function ‘mysql_fetch_lengths’ src/ls_mysql.c: In function ‘cur_numrows’: src/ls_mysql.c:319: warning: implicit declaration of function ‘mysql_num_rows’ src/ls_mysql.c:319: error: ‘cur_data’ has no member named ‘my_res’ src/ls_mysql.c: At top level: src/ls_mysql.c:327: error: expected declaration specifiers or ‘...’ before ‘MYSQL_RES’ src/ls_mysql.c: In function ‘create_cursor’: src/ls_mysql.c:337: error: ‘cur_data’ has no member named ‘my_res’ src/ls_mysql.c:337: error: ‘result’ undeclared (first use in this function) src/ls_mysql.c: In function ‘conn_gc’: src/ls_mysql.c:351: warning: implicit declaration of function ‘mysql_close’ src/ls_mysql.c:351: error: ‘conn_data’ has no member named ‘my_conn’ src/ls_mysql.c: In function ‘escape_string’: src/ls_mysql.c:380: warning: implicit declaration of function ‘mysql_real_escape_string’ src/ls_mysql.c:380: error: ‘conn_data’ has no member named ‘my_conn’ src/ls_mysql.c: In function ‘conn_execute’: src/ls_mysql.c:398: warning: implicit declaration of function ‘mysql_real_query’ src/ls_mysql.c:398: error: ‘conn_data’ has no member named ‘my_conn’ src/ls_mysql.c:400: warning: implicit declaration of function ‘mysql_error’ src/ls_mysql.c:400: error: ‘conn_data’ has no member named ‘my_conn’ src/ls_mysql.c:403: error: ‘MYSQL_RES’ undeclared (first use in this function) src/ls_mysql.c:403: error: ‘res’ undeclared (first use in this function) src/ls_mysql.c:403: warning: implicit declaration of function ‘mysql_store_result’ src/ls_mysql.c:403: error: ‘conn_data’ has no member named ‘my_conn’ src/ls_mysql.c:404: warning: implicit declaration of function ‘mysql_field_count’ src/ls_mysql.c:404: error: ‘conn_data’ has no member named ‘my_conn’ src/ls_mysql.c:407: error: too many arguments to function ‘create_cursor’ src/ls_mysql.c:412: warning: implicit declaration of function ‘mysql_affected_rows’ src/ls_mysql.c:412: error: ‘conn_data’ has no member named ‘my_conn’ src/ls_mysql.c:416: error: ‘conn_data’ has no member named ‘my_conn’ src/ls_mysql.c: In function ‘conn_commit’: src/ls_mysql.c:427: error: ‘conn_data’ has no member named ‘my_conn’ src/ls_mysql.c: In function ‘conn_rollback’: src/ls_mysql.c:437: error: ‘conn_data’ has no member named ‘my_conn’ src/ls_mysql.c: In function ‘conn_setautocommit’: src/ls_mysql.c:448: error: ‘conn_data’ has no member named ‘my_conn’ src/ls_mysql.c:451: error: ‘conn_data’ has no member named ‘my_conn’ src/ls_mysql.c: In function ‘conn_getlastautoid’: src/ls_mysql.c:463: warning: implicit declaration of function ‘mysql_insert_id’ src/ls_mysql.c:463: error: ‘conn_data’ has no member named ‘my_conn’ src/ls_mysql.c: At top level: src/ls_mysql.c:470: error: expected declaration specifiers or ‘...’ before ‘MYSQL’ src/ls_mysql.c: In function ‘create_connection’: src/ls_mysql.c:477: error: ‘conn_data’ has no member named ‘my_conn’ src/ls_mysql.c:477: error: ‘my_conn’ undeclared (first use in this function) src/ls_mysql.c: In function ‘env_connect’: src/ls_mysql.c:495: error: ‘MYSQL’ undeclared (first use in this function) src/ls_mysql.c:495: error: ‘conn’ undeclared (first use in this function) src/ls_mysql.c:499: warning: implicit declaration of function ‘mysql_init’ src/ls_mysql.c:503: warning: implicit declaration of function ‘mysql_real_connect’ src/ls_mysql.c:511: error: too many arguments to function ‘create_connection’ src/ls_mysql.c: In function ‘luaopen_luasql_mysql’: src/ls_mysql.c:605: error: expected ‘)’ before ‘MYSQL_SERVER_VERSION’ src/ls_mysql.c:605: error: too few arguments to function ‘lua_pushlstring’ make: *** [src/mysql.so] Error 1

sqlite3 32-bit problem

In a 32 bit build, retrieving int columns results in the number truncated to 32 bits.

Test case:

sqlite3 test.sqlite 'create table T(n integer);insert into T values(4294967297);'
echo 'print(require "luasql.sqlite3".sqlite3():connect "temp.sqlite":execute "select * from T":fetch())' > test.lua
lua test.lua

Prints 1 on systems where ptrdiff_t is 32 bits.

The following fix extends it to the maximum precision available with Lua (beyond that it's always possible to cast to string, which is the workaround I've used for now):

diff --git a/src/ls_sqlite3.c b/src/ls_sqlite3.c
index 150073c..b2acbe1 100644
--- a/src/ls_sqlite3.c
+++ b/src/ls_sqlite3.c
@@ -126,7 +126,7 @@ static int finalize(lua_State *L, cur_data *cur) {
 static void push_column(lua_State *L, sqlite3_stmt *vm, int column) {
   switch (sqlite3_column_type(vm, column)) {
   case SQLITE_INTEGER:
-    lua_pushinteger(L, sqlite3_column_int64(vm, column));
+    lua_pushnumber(L, (lua_Number)sqlite3_column_int64(vm, column));
     break;
   case SQLITE_FLOAT:
     lua_pushnumber(L, sqlite3_column_double(vm, column));

About LuaSQL.ODBC

Hi.

I am interested in using LuaSQL.ODBC. How could I use a connectionstring for connecting to a database?

Thanks.

HERNAN CANO M.
Systems Analyst - Programmer

Handle boolean fields correctly in Postgres

LuaSQL doesn't convert boolean fields to Lua boolean values when reading from a Postgres database but instead leaves them as strings "t" or "f". This makes for awkward code because both of those values evaluate as true in Lua.

It's not safe either to loop through the results and convert "f" to false because there can be string columns with the value "f". The only safe way to handle boolean columns is to query the column types for every table you select from, then loop through the results and convert "f" to false only for boolean columns. This is a lot of extra work to make types map natively like they ought to...

Compatibility with lua 5.3: Handling integers

Hi,

I have been using luasql successfully in Lua 5.1 using the ODBC connector. However I have recently upgraded Lua version to 5.3 which supports integers and changes the stringification of numbers (as stated in the lua docs not strictly a backwards incompatibility due to the lack of definition) but lua sql is pushing them into Lua all as numbers, without making distinction between integers and floats.

From DB I read integers and I would like to treat them as such in Lua; now I work around it by doing a math.modf afters getting the result set; how ever if the driver did it, it would be much better.

Regards.

Bug installing luasql-postgresql on Windows?

Hi,
I'm failing to install the postgreSQL rock. Here're my steps:

Using"VS2013 x64 Cross Tools Command Prompt3", and entering the luarocks install
luasql-postgres PGSQL_DIR="C:\Program Files\PostgreSQL\9.3" I get the message below.

Installing https://rocks.moonscript.org/luasql-postgres-2.3.0-1.src.rock...
Using https://rocks.moonscript.org/luasql-postgres-2.3.0-1.src.rock... switching
to 'build' mode
cl /MD /O2 -c -Fosrc/luasql.obj -IC:/Program Files/Osmose/Lua/5.1/include/ src/l
uasql.c -IC:\Program Files\PostgreSQL\9.3/include
Microsoft (R) C/C++ Optimizing Compiler Version 18.00.21005.1 for x64
Copyright (C) Microsoft Corporation. All rights reserved.

luasql.c
cl /MD /O2 -c -Fosrc/ls_postgres.obj -IC:/Program Files/Osmose/Lua/5.1/include/
src/ls_postgres.c -IC:\Program Files\PostgreSQL\9.3/include
Microsoft (R) C/C++ Optimizing Compiler Version 18.00.21005.1 for x64
Copyright (C) Microsoft Corporation. All rights reserved.

ls_postgres.c
src/ls_postgres.c(374) : error C2057: expected constant expression
src/ls_postgres.c(374) : error C2466: cannot allocate an array of constant size
0
src/ls_postgres.c(374) : error C2133: 'to' : unknown size

Error: Build error: Failed compiling object src/ls_postgres.obj


Initially, when entering simply luarocks install luasql-postgres, I had the following message:
Error: Could not find expected file pg_config.h, or pg_config.h for PGSQL -- you
may have to install PGSQL in your system and/or pass PGSQL_DIR or PGSQL_INCDIR
to the luarocks command. Example: luarocks install luasql-postgres PGSQL_DIR=/us
r/local

Following the reply from luarocks-developers, this might be a bug in luasql.postgres and I should do a bug report/provide a pull request:
http://sourceforge.net/p/luarocks/mailman/message/32917969/

Thanks for the support!
Cheers,
Alex

Calling a simple MySQL select stored procedure returns can't return a result set in the given context

I have a mysql stored procedure like this:

_CREATE DEFINER=root@localhostPROCEDUREget_record`( In mKey varchar(300) )
BEGIN

Select * from table_name where column_name = mkey;

END`_

And in LUA, I call it using the luasql.mysql:

_`local qry_str = "Call get_record('"..mkey.."')"
cur = assert (con:execute(qry_str))

row = cur:fetch ({}, "a")
`_
It returns the following error after executing it:

LuaSQL: error executing query. MySQL: PROCEDURE dbname.get_record can't return a result set in the given context

Calling that stored procedure in MySQL workbench works as expected.

Does luasql supports this type of procedure? And if it does, how do I call it via lua?

Thanks!

install problem

how to install in mac.
my lua path is: /usr/local/lib/lua

Still active ?

Hello,

I've submitted an update for ls_oci8.c and ls_odbc.c to support bind variables to the mail adr. on the keplerproject.org page
but i didn't get any response.
ist this project still active ?

regards,
gw

Unix Socket Support for mysql

I needed, support for unix socket connection, so I added it. But it would be a nice feature for others, too. I simply changed in file ls_mysql.c in func env_connect at line 489:

    const char *sourcename = luaL_checkstring(L, 2);
    const char *username = luaL_optstring(L, 3, NULL);
    const char *password = luaL_optstring(L, 4, NULL);
    const char *host = luaL_optstring(L, 5, NULL);
    const char *unixsocket = NULL;
    const char *localhost = "localhost";
    if(host[0] == '/'){
            unixsocket = host;
            host = localhost;
    }
    const int port = luaL_optinteger(L, 6, 0);

and at line 509

    if (!mysql_real_connect(conn, host, username, password,
            sourcename, port, unixsocket, 0))
    {

Of course a nicer implementation would be preferable, also there had to be an #ifdef WIN32 or simular to check for the current OS.

LuaSQL ODBC

The Luasql-odbc connection aborts when MS SQL columns with data types ntext, nchar, or nvarchar are selected. Not sure if this is correctable in the ODBC driver. Normal ANSI ASCII char and Extended ASCII character work fine text, char, and varchar data types in the existing driver. However, need to use ntext, nchar, or nvarchar for Unicocde (UTF-8) characters. Is there a solution for this?

[ODBC] char/SQLCHAR casting needed

Throughout the ls_odbc.c code there is mixing of char and SQLCHAR types. Not a real problem but will need casting to avoid compile warnings.

NULL fields generate no column name with fetch "a"?

The program here uses "a" setting on fetching to get column names to put stuff inside (example: as it loops through rows, it can go adding things to each column, or it can use column names to dynamically print a page that dumps all columns).

But if the contents of the field on the first row is null, it doesn't return the columns either, breaking stuff. (for example by creating a webpage that has columns than needed when dumping data if by bad luck several of the first fetched data had NULLs in those columns in first place).

Linux mysql.h

So while trying to install luasql for mysql I get the error:

Error: Could not find header file for MYSQL
  No file mysql.h in /usr/local/include
  No file mysql.h in /usr/include

and Google isn't helping, Google responds to me just with ways on Windows or how to use MySQL in C++

So where and how do I get the missing files?

tests/odbc.lua - typo in variable name

Hello LuaSQL team,

Thanks for providing this LuaSQL interface. Keep up the good work!

Found a typo is tests/odbc.lua that causes the "drop table" test in test.lua to report a failure when testing with an SQL Server database, even though the table was dropped successfully.

On line 30 of odbc.lua, variable DROP_TABLE_RETURN_VALUE0 should be renamed to DROP_TABLE_RETURN_VALUE (drop the 0) to fix.

Can create a pull request if needed.

Regards
jk77

Error: "LINK: fatal error LNK1181: cannot open input file 'C:\gcc-lua-install\lua\bin\lua53.lib'."

Hello . I have a problem. Hope you can help me. Here is the problem:

I need to install luasql in my computer for my data in MySQL. I already installed lua and luarocks. I run luarocks in Visual STudio COmmand Promt to install luasql command prompt but I got the error mentioned above.
Note that I already change the config file of luarocks with this code:

LUALIB = 'lua53.lib'. (By the way, how can I have this file?)
I really need your help help. I already spend a day on it and I follow what they did in lunarmodules/luafilesystem#22. Thanks in advance.

[ODBC] SQLINTEGER used instead of SQLLEN

ls_odbc.c around line 496

A call to SQLRowCount is passed a pointer to a SQLINTEGER instead of SQLLEN

This seems to be an hangover from 32-bit ODBC where SQLLEN was SQLINTEGER, but in 64-bit systems is an INT64

bad luasql._VERSION

The value of luasql._VERSION is hard coded in src/luasql.c.

There is only one rockspec for LuaSQL-SQLite3 with tarball version 2.2.0,
after installation, it gives "LuaSQL 2.1.2".

About LuaSQL, SQLite3, FireBird and ODBC

Hello, friends.

This message is for the team in charge of LuaSQL, specifically SQLite3, FireBird and ODBC connection.

I am interested in make tests to LuaSQL using SQLite3 and FireBird, and ODBC for the same both.

I would like you to guide me.

For starting I would like you to provide me with the respective LuaSQL DLLs for Lua v5.3.2 and/or Lua v5.3.3.

Thanks, friends.

HERNAN CANO M
Systems Analyst - Programmer

env_connect postgres libpq memory leak

Before I go down this rabbit hole, a quick question in case I'm missing something obvious:

Ubuntu 14.04 LTS
lua-sql-postgres:amd64 2.3.0-3

Am seeing a memory leak when luasql fails to connect to Postgres. Memory footprint increases steadily for a long-running script with persistent connections that periodically attempts to reconnect to a database that is temporarily offline.

Is it intentional that ls_postgres.c env_connect() does not call PQfinish() when PQstatus() returns CONNECTION_BAD? At first glance it looks like a failed PGconn struct will never be seen by conn_gc().

According to libpq docs [1] PQfinish() should be called even when a PQstatus() returns CONNECTION_BAD in order to release any memory allocated by libpq during the connection attempt.

[1] http://www.postgresql.org/docs/9.5/static/libpq-connect.html#LIBPQ-PQFINISH

Cant use variables in mySQL Query

I'm trying to use a variable in the Where = field of the SQL Query. With the code below, it says expecting a ) near test. When I try to change it to: WHERE firstname = '"..test.."'"), I get "attempt to concatenate a nil value"

Can someone tell me if this is a bug or just the wrong syntax? Thanks


local test = Gyovo

local env = luasql.mysql()
local con = env:connect("db_name","root","password","localhost","3306")
cur = con:execute("SELECT name FROM characters WHERE firstname = '"test"'")
row = cur:fetch ({}, "a")
while row do
print(string.format("%s", row.characters))

end
cursor:close()
conn:close()
env:close()

compiler warning in src/ls_mysql.c

From recent master:

$ make mysql
[...snip...]
src/ls_mysql.c: In function `cur_nullify':
src/ls_mysql.c:193: warning: control reaches end of non-void function
$

About LuaSQL-ODBC-SQLite3

Hello, friends.

This message is about LuaSQL, specifically ODBC connection.

I am trying to use SQLite with the Lua language. I found a DLL (not LuaSQL) and I try it. But I discover that it only runs with Lua v5.1.

I want to use the last version of the Lua language (I am trying v5.3.2, but I see today that v5.3.3 has come). And also I want to use it with the last version of SQLite.

My new scenario is: I want to use Lua with SQLite through LuaSQL. But I need to understand something....

I have found that every Lua utility that I want to "use" needs to be "compiled" from C-sources (or C++, or any...).
And also LuaSQL-SQLite3 (please consider from now to on, that I am not interested in using SQLite v2) seems to need to be compiled.

I conclude this because I have not found any DLL in the GitHub download (of LuaSQL or any other tool).

Next I am going to say this lecture about a possible scenario in my environment and I want you correct me where necesary.

If I compile LuaSQL-SQLite3 it only will run in the exact version of Lua with it be compiled and with the exact version of SQLite with it be compiled.
If I would want change Lua (.EXE and .DLL) for another higher version, LuaSQL-SQLite3 will not run.
If I would want change SQLite (.DLL) for another higher version, LuaSQL-SQLite3 will not run.
((Please say yes or no to this comment))

Then I turn my mind to LuaSQL-ODBC.
I (Hernan Cano) consider that if I change SQLite for a higher version, I still could use LuaSQL-SQLite3 (say "LuaSQL-ODBC-SQLite3 do will run") because the ODBC.DLL in LuaSQL is the same and the string connection that I use for connecting is the same.

Please: I need an environment where I could change the version of Lua (I understand that the Lua.EXE and the Lua.DLL must be the same version) without needing to change SQLite.

And: I need the same environment where I could change the version of SQLite without needing to change Lua.

For what I understand, I could not do that if I would use LuaSQL-SQLite, but I think I have BETTER probabilities if I use LuaSQL-ODBC (I say BETTER, not the maximum).
((Please say something to this comment))

If with LuaSQL-ODBC my probabilities could be better, I would prefer to download the DLL or all the binaries from respective URLs; but also I will accept to have to compile the binaries (why all these Lua tools do not come in DLL? I do not see a reason for this).

Clarify me these doubts of mine.

Thanks, friends.

HERNAN CANO M
Systems Analyst - Programmer

Seemly there is no way to set the encoding settings

I have a program here using LuaSQL that keeps getting mojibake out of the server, I am in Brazil, and it return brazillian-related stuff wrong.

raw byte dumps of the DB, and of the luasql results, show it is converting utf8 in the DB to something that looks like ucs2

for example, my first first name is Hélder, the é character in utf8 is c3a9, and this is what the DB dumps, and also the return value when using "SELECT HEX", but the byte dump when querying with luasql is E9, that is the ucs2 encoding of the character.

I did a "SHOW VARIABLES" on LuaSQL, and it defaults to latin1 and swedish, but I couldn't figure how to configure it to connect properly in first place.

The best I could find is that I would need the function "mysql_options" but I didn't found it in the source code here anywhere. (I am using binary distribution, so maybe I still missed it).

About LuaSQL.ODBC.pull28

Hello, friends.

This message is for the team in charge of LuaSQL, specifically ODBC connection.

In January-2015 I put a request; I remember that it was numered with 27.

And you put a request numbered 28, that is in the TXT that I send join to this message.
LuaSQL.ODBC.url_pull28.txt

It referes to using an string connection instead a DSN.

In the pull 28 you states that the modification was done. I have the sources of the change.

But I see today that it is no in the 2016-06-22 download.

I would want to know what happend with this: Is it not posible to apply the adjusment? Is it not possible to use a string-connection instead a DSN? Is DSN the only way to ODBC-connect from Lua because a string-connection is not possible?

Thanks, friends.

HERNAN CANO M
Systems Analyst - Programmer

LuaSQL.ODBC.url_pull28.txt

Can not fetch result after calling procedure

local res=assert(con:execute("CALL Procedure_name('"..parameter.."')"))
while row do
row = res:fetch ({}, "a")
end

After this calling another query and see:
LuaSQL: error executing query. MySQL: Commands out of sync; you can't run this command now

This error means that driver can not free result and next query can not be executed,
This happens only with procedures.

I tried
res:close()
but it is not works for this too. So as I cnow it automaticly closes when fetched null value.

tests/test.lua - "escape" test fails for ODBC driver

Hello LuaSQL team,

The "escape" test in tests/test.lua fails when testing with the ODBC driver since "escape" is not defined in luaL_Reg connection_methods[] of create_metatables() in src/ls_odbc.c.

Since ODBC can be used to connect to a variety of different database types, I'm not sure what to suggest here. Perhaps change test.lua to verify that method 'escape' exists before trying to call CONN:escape, and pass the test with a "Not Implemented" message instead of "OK !"?

Regards
jk77

Connection and env close() method causes a 5 second delay in synchronous lua script

I have an script on lua. Which works just fine using the luasql-mysql 2.3.0-1 rock, since the update to luasql-mysql 2.3.5-1 the close() methods create a delay (more like a sleep) of approx 5 Seconds, and then the script continues to run.
`sqlenv = assert (luasql.mysql())
sqlcon = assert (sqlenv:connect(database,database_username,database_password,database_host))

sqlcon:close()
sqlenv:close()`

The close method for connection and environment causes this issue, I downgraded my rock to luasql-mysql 2.3.0-1 and the issue was gone.

ls_postgres.c

I'm able to build Lua and LuaSQL with Embarcadero C++ Builder Rad Studio but had to make the following code modification to ls_postgres.c

The offending line, because len is not constant is not legal code. I imagine some compilers just deal with it.
char to[len * sizeof(char) * 2 +1];

/*
** Escapes a string for use within an SQL statement.
** Returns a string with the escaped string.
/
static int conn_escape (lua_State *L)
{
int rval = 0;
conn_data *conn = getconnection (L);
size_t len;
const char *from = luaL_checklstring (L, 2, &len);
const size_t tolen = len * sizeof(char) * 2 + 1;
char *to = malloc(tolen);
int error;
len = PQescapeStringConn (conn->pg_conn, to, from, len, &error);
if (error == 0)
{ /
success ! */
lua_pushlstring (L, to, len);
rval = 1;
}
else
rval = luasql_failmsg (L, "cannot escape string. PostgreSQL: ", PQerrorMessage (conn->pg_conn));

free(to);
return(rval);
}

Out of Memory

I am receiving Out of Memory issue while executing queries using LuaSQL. Can any one please help me on this. I have closed the connection properly, but still i am receiving this error.

Cannot connect to MySQL on CentOS 7

I'm trying to compile LuaSQL on CentOS 7 but whatever I try I can't make the module actually connect to a database:

# LuaSQL: Error connecting to database. MySQL: Can't connect to MySQL server on 'x.x.x.x' (111)

CentOS 7 is installed with:

mariadb-devel-5.5.47-1.el7_2.x86_64
mariadb-5.5.47-1.el7_2.x86_64
mariadb-libs-5.5.47-1.el7_2.x86_64
lua-5.1.4-14.el7.x86_64
lua-devel-5.1.4-14.el7.x86_64

I'm building luasql-2.3.1 using the following config:

DRIVER_LIBS_mysql ?= -L/usr/lib64/mysql -lmysqlclient -lz
DRIVER_INCS_mysql ?= -I/usr/include/mysql
LUA_LIBDIR ?= /usr/lib64
LUA_INC ?= /usr/include

# make mysql
gcc -O2 -std=gnu99 -Wall -Wmissing-prototypes -Wmissing-declarations -pedantic -fPIC  -I/usr/include -DLUASQL_VERSION_NUMBER='"2.3.1"'  -c src/luasql.c -o src/luasql.o
gcc -O2 -std=gnu99 -Wall -Wmissing-prototypes -Wmissing-declarations -pedantic -fPIC  -I/usr/include -DLUASQL_VERSION_NUMBER='"2.3.1"'  src/ls_mysql.c -o src/mysql.so -shared src/luasql.o -I/usr/include/mysql -L/usr/lib64/mysql -lmysqlclient -lz
src/ls_mysql.c: In function ‘cur_nullify’:
src/ls_mysql.c:193:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^

It seems to be generating a valid mysql.so:

# ldd src/mysql.so 
 linux-vdso.so.1 =>  (0x00007fff909bd000)
 libmysqlclient.so.18 => /usr/lib64/mysql/libmysqlclient.so.18 (0x00007f743479b000)
 libz.so.1 => /lib64/libz.so.1 (0x00007f7434585000)
 libc.so.6 => /lib64/libc.so.6 (0x00007f74341c3000)
 libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f7433fa7000)
 libssl.so.10 => /lib64/libssl.so.10 (0x00007f7433d3a000)
 libcrypto.so.10 => /lib64/libcrypto.so.10 (0x00007f7433951000)
 libdl.so.2 => /lib64/libdl.so.2 (0x00007f743374d000)
 libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f7433445000)
 libm.so.6 => /lib64/libm.so.6 (0x00007f7433142000)
 /lib64/ld-linux-x86-64.so.2 (0x00007f7434ea9000)
 libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f7432ef6000)
 libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f7432c11000)
 libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f7432a0c000)
 libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f74327da000)
 libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f74325c4000)
 libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f74323b4000)
 libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f74321b0000)
 libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f7431f96000)
 libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f7431d70000)
 libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f7431b0f000)
 liblzma.so.5 => /lib64/liblzma.so.5 (0x00007f74318ea000)

But whenever I use this module it simply fails to connect to MariaDB with the above listed error message. A test connection from the command line works without issues:

# mysql -u[..] -p[..] -h[..]
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 5.5.47-MariaDB-log MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

SELinux is disabled:

# sestatus 
SELinux status:                 disabled

Anyone got LuaSQL successfully built on CentOS 7 or have any idea what's going wrong here?

LuaSQL: unknown type

I used the luasql.oci8 driver to connect the Oracle database. My code is as follow:
db_oci8.lua:

local driver = require "luasql.oci8"
local env = driver.oci8()
local con = env:connect("myserviceName", "username", "password")
local cur = con.execute "select * from test"
nums = cur:numrows()

cur:close()
con:close()
env:close()

When I run my code. (luajit db_oci8.lua). There are something wrong on my code, the error message is as follow:
luajit: LuaSQL: unknown type.

Why occour to this issue?

Not able to install lua-sql

I tried to install luasql both mysql and jdbc version. I am struggling to install these. Spent days doing this. Will Appreciate any help. I installed LUA 5.1 from
https://code.google.com/p/luaforwindows/downloads/list

1. lua-jdbc

C:\Program Files (x86)\LuaRocks\2.2>luarocks install luasql-jdbc

Error: No results matching query were found.

2. lua-mysql

C:\Program Files (x86)\LuaRocks\2.2>luarocks install luasql-mysql
Installing https://rocks.moonscript.org/luasql-mysql-2.3.0-1.src.rock...
Using https://rocks.moonscript.org/luasql-mysql-2.3.0-1.src.rock... switching to 'build' mode

Error: Could not find expected file mysql.h, or mysql.h for MYSQL -- you may have to install MYSQL in your system and/or pass MYSQL_DIR or MYSQL_INCDIR to the luarocks command. Example: luarocks install luasql-mysql MYSQL_DIR=/usr/local

I tried to install with MYSQL_DIR. But no help

Can't initialize character set latin1

It trouble us for a long time . When there are a lot connections and there may be an error LuaSQL: error connecting to database. MySQL: Can't initialize character set latin1 (path: /usr/share/mysql/charsets/ Is there any way to help us find the problem? we use centos 6.5 for the server and libmysqlclient16 from yum.

luasql 5.2

Hello,

We have installed the latest version of Freeswitch and we are attempting to install luasql to use it on one of our scripts. We have installed it as per the instructions, but for some reason it puts it as lua5.1. when we run it through Freeswitch, Freeswitch is asking for 5.2. We created a simlink and below is the error we get. Is there a way to force luasql with 5.2 . According to the instruction it should be compatible.

2013-12-30 07:33:30.352599 [ERR] mod_lua.cpp:199 error loading module 'luasql.mysql' from file '/usr/local/lib/lua/5.2/luasql/mysql.so':
/usr/local/lib/lua/5.2/luasql/mysql.so: undefined symbol: lua_getfield
stack traceback:
[C]: in ?
[C]: in function 'require'
/usr/local/freeswitch/scripts/callerID.lua:6: in main chunk

Thanks,

luasql.postgres: SIGSEGV and crash if conn:escape(string) and returned string >8199 bytes

This sample script

local luasql = require "luasql.postgres"
local env = assert(luasql.postgres())
local conn = assert(env:connect(<your conn string here>))

for i=4080,5000,1 do
        local s1 = string.rep("'", i)
        local s2 = conn:escape(s1)
        print(string.format("s1=%i, s2=%i", string.len(s1), string.len(s2)))
end

will be failed after s1=4099, s2=8198 iteration and generate either SIGSEGV, or random error like:

s1=4099, s2=8198
Segmentation fault
s1=4099, s2=8198
lua: bad argument #1 to 'string.len' (string expected, got function)
stack traceback:
        [C]: in function 'string.len'
        [C]: in function 'len'
        ./bla2.lua:8: in main chunk
        [C]: in ?

some insights after brief looking to code:
luaL_Buffer b; - default buffer size of 8192
char *to = luaL_buffinitsize (L, &b, 2*len+1); - not checking actual returned buffer size
luaL_buffinit (L, &b); - init buffer with default size of 8192 regardles of len
len = PQescapeStringConn (conn->pg_conn, to, from, len, &error); - len parameter does not take into account an actual buffer size

Environment:

root@srv1:/opt/bla/scripts# lua -v
Lua 5.2.3  Copyright (C) 1994-2013 Lua.org, PUC-Rio

root@srv1:/opt/bla/scripts# uname -a
Linux srv1 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt20-1+deb8u3 (2016-01-17) x86_64 GNU/Linux

root@srv1:/opt/bla/scripts# luarocks show luasql-postgres

LuaSQL-Postgres 2.3.3-1 - Database connectivity for Lua (Postgres driver)

LuaSQL is a simple interface from Lua to a DBMS. It enables a Lua program to
connect to databases, execute arbitrary SQL statements and retrieve results in
a row-by-row cursor fashion.

License:        MIT/X11
Homepage:       http://www.keplerproject.org/luasql/
Installed in:   /usr/local

Modules:
        luasql.postgres (/usr/local/lib/lua/5.2/luasql/postgres.so)

[ODBC] NCHAR, WCHAR, Unicode Support

This is a common issue with the LuaSQL.ODBC driver, so I'm folding several tickets into this one.

Problem

The ODBC driver only supports local codepage text, running into Unicode text, such as NCHAR columns, doesn't work.

Fetching uses SQLGetData with SQL_C_CHAR type, Executing uses SQLPrepare rather than SQLPrepareW

So, just mod the code to use the WCHAR types? Well... apart from the overhead of transliterating all the text, that has two issues:

  1. That could easily break existing code that expects local codepage data
  2. WCHAR support is tricky cross platform. ODBC expects UCS-2 form like Windows in general. *nix uses UTF32, but the ODBC API still runs on UCS-2.

Proposed Solution

  1. Make some transliteration functions to handle UCS-2 <-> UTF8 conversion across all platforms
    • Win32 API has MultiByteToWideChar etc. functions for this
    • *nix system can expect iconv? Is that true for Macs also?
  2. Create new functions utf8_execute and utf8_fetch that support the WCHAR data. Also add local_execute/fetch functions that just link to the existing ones.
  3. Some kind of connection option to flip the default execute and fetch functions.

Comment, etc. appreciated...

Fetching result of stored procedure returns single record

When I try to fetch the result of a stored procedure it returns only one record.

res, err, errno, sqlstate = db:query("call icenter.queryUserOTHistorySessionRB(4780,'2016-03-01 00:00:00','2016-04-30 23:59:59');");

That's the result:

[{"LogoffTime":"2016-04-14 07:30:00","user_id":4780,"resource_id":1335,"ResourceName":"WTH5401171","InuseTime":54000,"IdleTime":0,"LogonTime":"2016-04-13 16:30:00"}]

Is it true that LuaSQL doesn't support fetching results from stored procedures?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.