Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: EK.IceFlake on Mar 06, 2015, 11:10 AM

Title: SQLite fail without error
Post by: EK.IceFlake on Mar 06, 2015, 11:10 AM
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
Title: Re: SQLite fail without error
Post by: Kratos_ on Mar 06, 2015, 11:27 AM

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.
Title: Re: SQLite fail without error
Post by: . on Mar 06, 2015, 11:40 AM
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.
Title: Re: SQLite fail without error
Post by: Kratos_ on Mar 06, 2015, 11:54 AM
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 ) .
Title: Re: SQLite fail without error
Post by: EK.IceFlake on Mar 06, 2015, 01:36 PM
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?
Title: Re: SQLite fail without error
Post by: EK.IceFlake on Mar 09, 2015, 12:31 PM
Fixed, I used integer and real datatype instead of float.