lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I have compiled Lua5.1.2, sqlite3.5.1 and luasqlite2.0.2 for an ARM architecture. Everything seems to work fine, but with lua sqlite we have some problems.

First of all, I can create a database and insert any sql statement using db:exec(). The problem comes when I have some variables, in which I have to use an insert function to put them in the sql statement. In this case, I use a db:prepare where I put all the sql statements with the variables. The code I used is:

require "sqlite3"

-- This is the insert function where I pass all the variables for the sql statement

function insert_ip(id, messageID, correlationID, participantID, sender, receiver, time, formatID, ip_address, fifoID)
  args = { } = id
  args.messageID = messageID
  args.correlationID = correlationID
  args.participantID = participantID
  args.sender = sender
  args.receiver = receiver
  args.time = time
  args.formatID = formatID
  args.message = ip_address
  args.fifoID = fifoID
  --Here is where the program fails!!

function Main(ip)

http = require "socket.http"

--open or create a database which is called "gestion.sqlite3"

local db = assert('gestion.sqlite3'))

--create a table T1. This it seems to work fine


    id            INTEGER PRIMARY KEY,
    messageID        INTEGER,
    correlationID    INTEGER,
    participantID    INTEGER,
    sender        INTEGER,
    receiver          INTEGER,
    time        TIMESTAMP,
    formatID        INTEGER,
    message        INTEGER,
    fifoID        INTEGER 

stmt = db:prepare[[
  INSERT INTO T1 VALUES (:id, :messageID, :correlationID, :participantID, :sender, :receiver, :time, :formatID, :message, :fifoID);

--call the insert_ip function

insert_ip(1, 0, 0, 0, 1, 0,"2009-01-09 08:00:00" , 0, ip, 0)

The programs fails when tries to execute "insert_stmt:exec()", and fails with the code: "Segmentation fault".

I have compiled and execute the program in a Linux PC and it works without any problem. It seems to be a problem with the memory, but I have no idea the reason and how it could be solved.

Please, any help would be appreciate.

Thank you for your time

Julio Mora