SQLite fail without error

Started by EK.IceFlake, Mar 06, 2015, 11:10 AM

Previous topic - Next topic

EK.IceFlake

Hi guys!
I was making a vehicle system for my server, for some reason sqlite doesnt want to work when adding a vehicle
class Vehicles
{
    function Add(model, pos, angle, world, price, color1, color2)
    {
        print("Creating vehicle");
        local v = ::CreateVehicle(model, world, pos, angle, color1, color2);
        ::QuerySQL(::Sqlite.db, "insert into vehicles values (" + v.ID + ", " + model + ", " + color1 + ", " + color2 + ", " + price + ", 'null', 'null', " + world + ", " + pos.x + ", " + pos.y + ", " + pos.z + ")");
        printf("Created vehicle:\n  -Model: %i\n  -ID: %i\n  -Location: %f, %f, %f\n  -Angle: %f\n  -World: %i\n  -Price: %i\n  -Colors: %i, %i", model, v.ID, pos.x, pos.y, pos.z, angle, world, price, color1, color2);
        return 1;
    }
function Count()
{
    local v = 0, q = ::QuerySQL(::Sqlite.db, "select * from vehicles");
    while (::GetSQLColumnData(q, 0))
    {
        v += 1;::GetSQLNextRow(q);
    }
    return v;::FreeSQLQuery(q);
}
}

function onPlayerCommand(player, command, arguments)
{
local params;
if (arguments != null) params = split(arguments, " ");
else params = split("", " ");
if (command == "cveh")
{
    if (params.len() < 3) EMessagePlayer(player, ErrorMessage("Invalid parameters, /cveh model price color1 color2"));
    else
    {
    Vehicles.Add(params[0].tointeger(), player.Pos, player.Angle, player.World, params[1].tointeger(), params[2].tointeger(), params[3].tointeger());
    return 1;
}
}
return 1;
}
Inside SQLite.Config()
::QuerySQL(db, "create table if not exists vehicles (id integer primary key not null, model integer, color1 integer, color2 integer, price integer, owner text, lcowner text, world integer, x real, y real, z real, angle real)");
I write /cv ... ... ..., vehicle appears but when I restart server, it prints no vehicles and none are created.
Thanks for help

Kratos_


You're using db in create table while Sqlite.db for the Insert Operation. The General Syntax for these operations in SQLite is :-

Quotelocal sql_primary_instruction_handler = QuerySQL( < Which database ?? > , < Which Instruction ?? > );    // Product of database handler

Instruction is any valid SQL Query.
In the middle of chaos , lies opportunity.

.

I would like to add on @Kratos_'s quote that the returned handle it's is not an instruction. I's actually called a result handle because you will receive the result of your query. Irrelevant to the topic but just in case.
.

Kratos_

#3
Thanx for adding . By primary_instruction_handler , I simply mean that this line should be added before making use of its products like column_data_handler , next_row_switch_handler , Query_Cleanup_Handler etc . Although , these operations are manufactured in
SQL SELECT Statement which itself is given in QuerySQL =  primary_instruction handler ( aka result_handler as you said ) .
In the middle of chaos , lies opportunity.

EK.IceFlake

Quote from: Kratos_ on Mar 06, 2015, 11:27 AMYou're using db in create table while Sqlite.db for the Insert Operation. The General Syntax for these operations in SQLite is :-

Quotelocal sql_primary_instruction_handler = QuerySQL( < Which database ?? > , < Which Instruction ?? > );    // Product of database handler

Instruction is any valid SQL Query.
Where I'm using db, that function is inside the Sqlite class (in Sqlite.Init()). Nothing wrong. So back to the topic, why isn't this working?

EK.IceFlake

Fixed, I used integer and real datatype instead of float.