Âåðñèÿ äëÿ ïå÷àòè òåìû

Íàæìèòå ñþäà äëÿ ïðîñìîòðà ýòîé òåìû â îáû÷íîì ôîðìàòå

MyDC.ru _ Äîïîëíèòåëüíûå áèáëèîòåêè äëÿ PtokaX _ Mysql

Àâòîð: Jaska 17.1.2009, 21:34

Óñòàíîâêà mysql íà PtokaX 0.4.1.1 ïîä unix îïèñàíà çäåñü - http://mydc.ru/topic597.html

Ïîñëå óñòàíîâêè ïðîâåðÿåì ðàáîòîñïîñîáíîñòü, ïèøåì ñêðèïò:

CODE

require "luasql.mysql"
mysql = assert(luasql.mysql())

db_name = "" -- èìÿ áä
db_host = "" -- õîñò
db_user = "" -- ïîëüçîâàòåëü
db_pass = "" -- ïàðîëü

con = assert(mysql:connect(db_name, db_user, db_pass, db_host))
cur = assert(con:execute("SELECT version()"))

Core.SendToAll("<mysql> MYSQL driver version is: "..luasql._MYSQLVERSION)
Core.SendToAll("<mysql> "..luasql._COPYRIGHT)
Core.SendToAll("<mysql> "..luasql._DESCRIPTION)
Core.SendToAll("<mysql> "..luasql._VERSION)

con:close()
mysql:close()


Åñëè âñå îê, òî óâèäèòå ïðèìåðíî ñëåäóùåå:

Êîä
<mysql> MYSQL driver version is: 5.0.45
<mysql> Copyright © 2003-2007 Kepler Project
<mysql> LuaSQL is a simple interface from Lua to a DBMS
<mysql> LuaSQL 2.1.1


Íåáîëüøîé ïðèìåð ðàáîòû ñ mysql â lua.

CODE
require "luasql.mysql"
mysql = assert(luasql.mysql())

db_name = "joomla"
db_host = "localhost"
db_user = "root"
db_pass = "õõõõõõõõõõõõõ"

con = assert(mysql:connect(db_name, db_user, db_pass, db_host))

function ChatArrival(tUser,sData)
local _,_,sCmd = sData:find"%b<>%s+(%S+)|"
if sCmd == "+1" then
for id, name, nick in rows(con, "SELECT * FROM `jos_users`") do
Core.SendToAll("ID -> "..id.."\nNAME -> "..name.."\nNICK -> "..nick)
end
return true
end
end

function rows (connection, sql_statement)
local cursor = assert (connection:execute (sql_statement))
return function ()
return cursor:fetch()
end
end

con:close()
mysql:close()


Âûøå â ïðèìåðå ÿ ïîäêëþ÷àëñÿ ê áàçå äàííûõ áåñïëàòíîé CMS Joomla è âûâîäèë Id, Èìÿ ïîëüçîâàòåëÿ è åãî Íèê.

Âñÿ íåîáõîäèìàÿ èíôîðìàöèÿ î ïðîåêòå LuaSQL - http://mydc.ru/r/?http://www.keplerproject.org/luasql/manual.html#introduction

Àâòîð: Parad0x 23.2.2011, 10:00

Çäðàâñòâóéòå, ïîäñêàæèòå êàê ñîáðàòü luasql ïîä centos 5.5

Ëîã êîíñîëè
Êîä
# make
gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -ansi -pedantic -I../compat/src -I/opt/local/include -I/usr/local/include    -c -o src/luasql.o src/luasql.c
gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -ansi -pedantic -I../compat/src -I/opt/local/include -I/usr/local/include    -c -o src/ls_sqlite3.o src/ls_sqlite3.c
src/ls_sqlite3.c:14:21: error: sqlite3.h: Íåò òàêîãî ôàéëà èëè êàòàëîãà
src/ls_sqlite3.c:41: îøèáêà: expected specifier-qualifier-list before ‘sqlite3’
src/ls_sqlite3.c:51: îøèáêà: expected specifier-qualifier-list before ‘sqlite3_stmt’
src/ls_sqlite3.c: In function ‘finalize’:
src/ls_sqlite3.c:95: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_finalize’
src/ls_sqlite3.c:95: îøèáêà: ‘cur_data’ has no member named ‘sql_vm’
src/ls_sqlite3.c:95: îøèáêà: ‘SQLITE_OK’ undeclared (first use in this function)
src/ls_sqlite3.c:95: îøèáêà: (Each undeclared identifier is reported only once
src/ls_sqlite3.c:95: îøèáêà: for each function it appears in.)
src/ls_sqlite3.c:97: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_errmsg’
src/ls_sqlite3.c:97: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_db_handle’
src/ls_sqlite3.c:97: îøèáêà: ‘cur_data’ has no member named ‘sql_vm’
src/ls_sqlite3.c:97: ïðåäóïðåæäåíèå: assignment makes pointer from integer without a cast
src/ls_sqlite3.c:98: îøèáêà: ‘cur_data’ has no member named ‘sql_vm’
src/ls_sqlite3.c:105: îøèáêà: ‘cur_data’ has no member named ‘sql_vm’
src/ls_sqlite3.c: In function ‘cur_fetch’:
src/ls_sqlite3.c:116: îøèáêà: ‘sqlite3_stmt’ undeclared (first use in this function)
src/ls_sqlite3.c:116: îøèáêà: ‘vm’ undeclared (first use in this function)
src/ls_sqlite3.c:116: îøèáêà: ‘cur_data’ has no member named ‘sql_vm’
src/ls_sqlite3.c:117: ïðåäóïðåæäåíèå: ISO C90 forbids mixed declarations and code
src/ls_sqlite3.c:122: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_step’
src/ls_sqlite3.c:125: îøèáêà: ‘SQLITE_DONE’ undeclared (first use in this function)
src/ls_sqlite3.c:128: îøèáêà: ‘SQLITE_ROW’ undeclared (first use in this function)
src/ls_sqlite3.c:141: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_column_text’
src/ls_sqlite3.c:141: ïðåäóïðåæäåíèå: ïðèâåäåíèå ê òèïó óêàçàòåëÿ îò öåëîãî äðóãîãî ðàçìåðà
src/ls_sqlite3.c:153: ïðåäóïðåæäåíèå: ïðèâåäåíèå ê òèïó óêàçàòåëÿ îò öåëîãî äðóãîãî ðàçìåðà
src/ls_sqlite3.c:165: ïðåäóïðåæäåíèå: ïðèâåäåíèå ê òèïó óêàçàòåëÿ îò öåëîãî äðóãîãî ðàçìåðà
src/ls_sqlite3.c: In function ‘cur_close’:
src/ls_sqlite3.c:187: îøèáêà: ‘cur_data’ has no member named ‘sql_vm’
src/ls_sqlite3.c: Íà âåðõíåì óðîâíå:
src/ls_sqlite3.c:230: îøèáêà: expected declaration specifiers or ‘...’ before ‘sqlite3_stmt’
src/ls_sqlite3.c: In function ‘create_cursor’:
src/ls_sqlite3.c:245: îøèáêà: ‘cur_data’ has no member named ‘sql_vm’
src/ls_sqlite3.c:245: îøèáêà: ‘sql_vm’ undeclared (first use in this function)
src/ls_sqlite3.c:254: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_column_name’
src/ls_sqlite3.c:254: ïðåäóïðåæäåíèå: passing argument 2 of ‘lua_pushstring’ makes pointer from integer without a cast
src/ls_sqlite3.c:263: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_column_decltype’
src/ls_sqlite3.c:263: ïðåäóïðåæäåíèå: passing argument 2 of ‘lua_pushstring’ makes pointer from integer without a cast
src/ls_sqlite3.c: In function ‘conn_close’:
src/ls_sqlite3.c:291: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_close’
src/ls_sqlite3.c:291: îøèáêà: ‘conn_data’ has no member named ‘sql_conn’
src/ls_sqlite3.c: In function ‘conn_escape’:
src/ls_sqlite3.c:299: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_mprintf’
src/ls_sqlite3.c:299: ïðåäóïðåæäåíèå: initialization makes pointer from integer without a cast
src/ls_sqlite3.c:307: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_free’
src/ls_sqlite3.c: In function ‘conn_execute’:
src/ls_sqlite3.c:322: îøèáêà: ‘sqlite3_stmt’ undeclared (first use in this function)
src/ls_sqlite3.c:322: îøèáêà: ‘vm’ undeclared (first use in this function)
src/ls_sqlite3.c:323: ïðåäóïðåæäåíèå: ISO C90 forbids mixed declarations and code
src/ls_sqlite3.c:327: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_prepare’
src/ls_sqlite3.c:327: îøèáêà: ‘conn_data’ has no member named ‘sql_conn’
src/ls_sqlite3.c:328: îøèáêà: ‘SQLITE_OK’ undeclared (first use in this function)
src/ls_sqlite3.c:330: îøèáêà: ‘conn_data’ has no member named ‘sql_conn’
src/ls_sqlite3.c:330: ïðåäóïðåæäåíèå: assignment makes pointer from integer without a cast
src/ls_sqlite3.c:340: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_column_count’
src/ls_sqlite3.c:343: îøèáêà: ‘SQLITE_ROW’ undeclared (first use in this function)
src/ls_sqlite3.c:343: îøèáêà: ‘SQLITE_DONE’ undeclared (first use in this function)
src/ls_sqlite3.c:345: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_reset’
src/ls_sqlite3.c:346: îøèáêà: ñëèøêîì ìíîãî àðãóìåíòîâ â âûçîâå ôóíêöèè ‘create_cursor’
src/ls_sqlite3.c:353: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_changes’
src/ls_sqlite3.c:353: îøèáêà: ‘conn_data’ has no member named ‘sql_conn’
src/ls_sqlite3.c:358: ïðåäóïðåæäåíèå: assignment makes pointer from integer without a cast
src/ls_sqlite3.c: In function ‘conn_commit’:
src/ls_sqlite3.c:380: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_exec’
src/ls_sqlite3.c:380: îøèáêà: ‘conn_data’ has no member named ‘sql_conn’
src/ls_sqlite3.c:382: îøèáêà: ‘SQLITE_OK’ undeclared (first use in this function)
src/ls_sqlite3.c: In function ‘conn_rollback’:
src/ls_sqlite3.c:408: îøèáêà: ‘conn_data’ has no member named ‘sql_conn’
src/ls_sqlite3.c:409: îøèáêà: ‘SQLITE_OK’ undeclared (first use in this function)
src/ls_sqlite3.c: In function ‘conn_getlastautoid’:
src/ls_sqlite3.c:425: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_last_insert_rowid’
src/ls_sqlite3.c:425: îøèáêà: ‘conn_data’ has no member named ‘sql_conn’
src/ls_sqlite3.c: In function ‘conn_setautocommit’:
src/ls_sqlite3.c:442: îøèáêà: ‘conn_data’ has no member named ‘sql_conn’
src/ls_sqlite3.c:449: îøèáêà: ‘conn_data’ has no member named ‘sql_conn’
src/ls_sqlite3.c:450: îøèáêà: ‘SQLITE_OK’ undeclared (first use in this function)
src/ls_sqlite3.c: Íà âåðõíåì óðîâíå:
src/ls_sqlite3.c:467: îøèáêà: expected declaration specifiers or ‘...’ before ‘sqlite3’
src/ls_sqlite3.c: In function ‘create_connection’:
src/ls_sqlite3.c:476: îøèáêà: ‘conn_data’ has no member named ‘sql_conn’
src/ls_sqlite3.c:476: îøèáêà: ‘sql_conn’ undeclared (first use in this function)
src/ls_sqlite3.c: In function ‘env_connect’:
src/ls_sqlite3.c:490: îøèáêà: ‘sqlite3’ undeclared (first use in this function)
src/ls_sqlite3.c:490: îøèáêà: ‘conn’ undeclared (first use in this function)
src/ls_sqlite3.c:491: ïðåäóïðåæäåíèå: ISO C90 forbids mixed declarations and code
src/ls_sqlite3.c:495: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_open’
src/ls_sqlite3.c:496: îøèáêà: ‘SQLITE_OK’ undeclared (first use in this function)
src/ls_sqlite3.c:498: ïðåäóïðåæäåíèå: assignment makes pointer from integer without a cast
src/ls_sqlite3.c:506: îøèáêà: ñëèøêîì ìíîãî àðãóìåíòîâ â âûçîâå ôóíêöèè ‘create_connection’
make: *** [src/ls_sqlite3.o] Îøèáêà 1

Àâòîð: mariner 23.2.2011, 14:04

äëÿ íà÷àëà îòêðûòü õîòÿ áû êîíôèã ñáîðêè.

Àâòîð: Parad0x 23.2.2011, 23:01

Ïîòîðîïèëñÿ ñ íàïèñàíèåì ïîñòà big_smile.gif
Îòêðûë êîíôèã, ïîäïðàâèë, äàëåå make è ïîëó÷àåì òàê:

console
Êîä
# make
export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -ansi -pedantic -I/root/compat-5.1r5 -I/usr/include/mysql -I/usr/local/include  -o src/mysql.so -shared  src/luasql.o src/ls_mysql.o  -L/usr/lib/mysql -lmysqlclient -lz
/usr/bin/ld: src/luasql.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
src/luasql.o: could not read symbols: Bad value
collect2: âûïîëíåíèå ld çàâåðøèëîñü ñ êîäîì âîçâðàòà 1
make: *** [src/mysql.so] Îøèáêà 1

config
Êîä
# Driver (leave uncommented ONLY the line with the name of the driver)
T= mysql
#T= oci8
#T= odbc
#T= postgres
#T= sqlite
#T=sqlite3

# Installation directories

# Default prefix
PREFIX = /usr/local

# System's libraries directory (where binary libraries are installed)
LUA_LIBDIR= $(PREFIX)/lib/lua/5.1

# System's lua directory (where Lua libraries are installed)
LUA_DIR= $(PREFIX)/share/lua/5.1

# Lua includes directory
LUA_INC= $(PREFIX)/include

# Lua version number (first and second digits of target version)
LUA_VERSION_NUM= 514

# OS dependent
LIB_OPTION= -shared #for Linux
#LIB_OPTION= -bundle -undefined dynamic_lookup #for MacOS X

LIBNAME= $T.so
COMPAT_DIR= /root/compat-5.1r5

# Compilation parameters
# Driver specific
######## MySQL
DRIVER_LIBS= -L/usr/lib/mysql -lmysqlclient -lz
DRIVER_INCS= -I/usr/include/mysql
######## Oracle OCI8
#DRIVER_LIBS= -L/home/oracle/OraHome1/lib -lz -lclntsh
#DRIVER_INCS= -I/home/oracle/OraHome1/rdbms/demo -I/home/oracle/OraHome1/rdbms/public
######## PostgreSQL
#DRIVER_LIBS= -L/usr/local/pgsql/lib -lpq
#DRIVER_INCS= -I/usr/local/pgsql/include
######## SQLite
#DRIVER_LIBS= -lsqlite
#DRIVER_INCS=
######## SQLite3
#DRIVER_LIBS= -L/opt/local/lib -lsqlite3
#DRIVER_INCS= -I/opt/local/include
######## ODBC
#DRIVER_LIBS= -L/usr/local/lib -lodbc
#DRIVER_INCS= -DUNIXODBC -I/usr/local/include

WARN= -Wall -Wmissing-prototypes -Wmissing-declarations -ansi -pedantic
INCS= -I$(LUA_INC)
CFLAGS= -O2 $(WARN) -I$(COMPAT_DIR) $(DRIVER_INCS) $(INCS) $(DEFS)
CC= gcc

Àâòîð: mariner 23.2.2011, 23:13

Öèòàòà
/usr/bin/ld: src/luasql.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC

È îïÿòü ïîòîðîïèëñÿ.
Äîïèøè â ýòî ìåòñî
Êîä
# OS dependent
LIB_OPTION= -shared #for Linux

-fPIC

Àâòîð: Parad0x 23.2.2011, 23:17

Ñïàñèáî çà áûñòðûé îòâåò, íî:

console
Êîä
# make
export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -ansi -pedantic -I/root/compat-5.1r5 -I/usr/include/mysql -I/usr/local/include  -o src/mysql.so -shared -fPIC  src/luasql.o src/ls_mysql.o  -L/usr/lib/mysql -lmysqlclient -lz
/usr/bin/ld: src/luasql.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
src/luasql.o: could not read symbols: Bad value
collect2: âûïîëíåíèå ld çàâåðøèëîñü ñ êîäîì âîçâðàòà 1
make: *** [src/mysql.so] Îøèáêà 1

ò.å. íè÷åãî íå ïîìåíÿëîñü

Àâòîð: mariner 24.2.2011, 2:03

À make clean ñäåëàë êàê äîáàâèë?)

Àâòîð: Parad0x 24.2.2011, 19:58

åõ... â ëèíóêñå íîâè÷åê, êàê-òî è çàáûëîñü.
âîò êàê áû ñäåëàëbig_smile.gif

Êîä
gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -ansi -pedantic -I/root/compat-5.1r5 -I/usr/include/mysql -I/usr/local/include    -c -o src/luasql.o src/luasql.c
gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -ansi -pedantic -I/root/compat-5.1r5 -I/usr/include/mysql -I/usr/local/include    -c -o src/ls_mysql.o src/ls_mysql.c
In file included from src/ls_mysql.c:19:
/usr/include/mysql/mysql.h:129: ïðåäóïðåæäåíèå: ISO C90 íå ïîääåðæèâàåò òèï ‘long long’
export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -ansi -pedantic -I/root/compat-5.1r5 -I/usr/include/mysql -I/usr/local/include  -o src/mysql.so -shared -fPIC  src/luasql.o src/ls_mysql.o  -L/usr/lib/mysql -lmysqlclient -lz
/usr/bin/ld: src/luasql.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
src/luasql.o: could not read symbols: Bad value
collect2: âûïîëíåíèå ld çàâåðøèëîñü ñ êîäîì âîçâðàòà 1
make: *** [src/mysql.so] Îøèáêà 1

Àâòîð: mariner 24.2.2011, 20:10

Ñòðàííî. Ó ìåíÿ ñ òåìè ìîäèôèêàöèÿìè ñîáèðàåòñÿ.

Àâòîð: KCAHDEP 21.9.2013, 7:14

Äîáðîãî âðåìåíè ñóòîê. Óñòàíîâèë ïàêåòû liblua5.1-sql-mysql-2 liblua5.1-sql-mysql-dev íî ïðè âêëþ÷åíèè ëþáîãî ñêðèïòà èñïîëüçóþùåãî mysql âûâîäèò îøèáêó:

Êîä
21.09.2013 08:09:12 - /var/ptokax/scripts/ajaxchat.lua:198: attempt to index global 'luasql' (a nil value)
21.09.2013 08:09:12 - /var/ptokax/scripts/ajaxchat.lua:235: attempt to index global 'env' (a nil value)

os debian 7.1
mysql 5.5.31
lua 5.1
ptokax 4.1.2
Ïîäñêàæèòå ïîæàëóéñòà êàê ñ ýòèì áîðîòüñÿ.

Àâòîð: Saymon21 21.9.2013, 17:34

Êîä
luasql = require"luasql.mysql"
env = luasql.mysql()

Àâòîð: KCAHDEP 21.9.2013, 18:17

Öèòàòà(Saymon21 @ 21.9.2013, 18:34) *
Êîä
luasql = require"luasql.mysql"
env = luasql.mysql()

Ñïàñèáî îãðîìíîå, çàðàáîòàëî âñå!