Trouble inserting data into an sqlite3 database
#12
Sorry for the really, really late response. I just gave up on it basically.

Current code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function ExecuteStatement(sql, parameters)
    local db = sqlite3.open(PLUGIN:GetLocalFolder() .. "/database.sqlite3");
    local stmt = db:prepare(sql);
 
    if not (parameters == nil) then
        for key, value in pairs(parameters) do
            stmt:bind(key, value)
            stmt:step();
        end
        --stmt:bind_names(parameters);
        --stmt:step();
    end
 
    local result;
    if (sql:match("SELECT")) then
        local x = 1;
        for row in stmt:urows() do
            result = row;
            x = x + 1;
            LOG("TEST");
        end
        --LOG(stmt);
    elseif (sql:match("INSERT")) then
        --result = stmt:last_insert_rowid();
        LOG("INSERT");
    else
        LOG("NOTHING");
    end
 
    stmt:finalize();
 
    db:close();
 
    if not (result == nil) then
        return result;
    else
        return 0;
    end
end

I'm 100% sure that the SELECT query I'm running should return at least 1 row. However, it doesn't go into the loop even once. It doesn't break, it just doesn't run properly.

I've tried urows, nrows and rows, but none of them seem to do anything.
Reply
Thanks given by:


Messages In This Thread
RE: Trouble inserting data into an sqlite3 database - by PureTryOut - 01-15-2016, 05:27 AM



Users browsing this thread: 1 Guest(s)