|
|
LoriotPro
scripting documentation |
This example explains how to add DataBase access function to the embedded LoriotPro script language. The library is available on the Kepler project web site http://www.keplerproject.org/ .
Example :
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function ODBC_DisplayTable(conn,sql_request)
cur=conn:execute(sql_request);
if cur == nil then
lp.Print("SQL CCMDB_DisplayTable Cur Fail\n");
return 0
end;
row = cur:fetch ({},"n"); -- the rows will be indexed by field names
if row==nil then
lp.Print("SQL CCMDB_DisplayTable fetch Fail\n");
cur:close();
return 0;
end
j=table.getn(row);
lp.Print("\n");
if row then
while row do
line="";
k=table.getn(row);
lp.Print("[",k);
for i=1,j do
line=line..row[i].."|\t";
lp.Print(">");
lp.Print(".");
lp.Print(row[i]);
lp.Print(" | \t");
end
lp.Print("]\n");
--lp.Print(line,"\n");
row = cur:fetch (row,"n"); -- reusing the table of results
end
end
cur:close();
return 1;
end
--------------------------------------------------------------------------------
-- main programme
--------------------------------------------------------------------------------
lp_buffer="ok";
lp_value=1;
if lp.IsDebugMode()==1 then
lib,init=lp.LoadLibrary(lp.GetPath().."/lua_odbcd.dll","luaopen_luasqlodbc");
else
lib,init=lp.LoadLibrary(lp.GetPath().."/lua_odbc.dll","luaopen_luasqlodbc");
end
if lib==nil then error("odbc lib not loaded \n") end;
lp.Print("Load odbc library (",lp.GetVersion(),")\n");
init();
env=luasql.odbc();
if env then
conn=env:connect("Loriotpro","root","");
if conn~=nil then
lp.Print("Connected to DSN :","Loriotpro","\n");
--ODBC_DisplayTable(conn,"Select * FROM loriot_events WHERE l_reference=101
LIMIT 100;");
ODBC_DisplayTable(conn,"Select * FROM loriot_events LIMIT 10;");
conn:close();
else
lp.Print("Error to connect DSN : Loriotpro\n");
end
env:close();
end
cur:close();
conn:close();
env:close();
lp.Print("pass\n");
www.loriotpro.com
|
|