SA-MP Forums Archive
Is there any way to convert ini codes to sqllite?? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Is there any way to convert ini codes to sqllite?? (/showthread.php?tid=604943)



Is there any way to convert ini codes to sqllite?? - GhostHacker - 12.04.2016

Hello mates i really want help in this is there any ways to convert a ini script to sqllite ??


Re: Is there any way to convert ini codes to sqllite?? - itsCody - 12.04.2016

Learn the SQL language, then look up some tutorials about SQLite on the forums.


Re: Is there any way to convert ini codes to sqllite?? - GhostHacker - 12.04.2016

So there isnt any way to convert??


Re: Is there any way to convert ini codes to sqllite?? - itsCody - 12.04.2016

Yes, you can convert any script to SQL.


Re: Is there any way to convert ini codes to sqllite?? - Gammix - 12.04.2016

You can convert an INI file to a SQL row using a trick PAWN code.

Source:
pawn Код:
#pragma dynamic (20000)

#define MAX_STRING_SIZE (256)
#define MAX_INI_FIELDS (32)

stock SQL_Convert(const file[], DB:db, const table[])
{
    new File:h = fopen(file, io_read);
    if (! h)
        return printf("[initosql.inc] - ERROR: Cannot open file '%s'.", file);

    if (db == DB:0)
        return printf("[initosql.inc] - ERROR: Cannot open database file(.db) 'handle: %i'.", _:db);

    if (! table[0])
        return print("[initosql.inc] - ERROR: No table name entered.");

    new read[MAX_STRING_SIZE];
    new pos;

    new field[MAX_INI_FIELDS][32], value[MAX_INI_FIELDS][MAX_STRING_SIZE];
    new count;

    while (fread(h, read))
    {
        if (! read[0])
            continue;

        pos = strfind(read, "=");
        strmid(field[count], read, 0, ((read[pos - 1] == ' ') ? (pos - 1) : (pos)));
        strmid(value[count], read, ((read[pos + 1] == ' ') ? (pos + 1) : (pos)), strlen(read));

        count++;
    }
   
    new query[MAX_INI_FIELDS * MAX_STRING_SIZE + 256];
    format(query, sizeof (query), "INSERT INTO `%s` (", table);
    for (new i; i < count; i++)
    {
        if (i == (count - 1))
            format(query, sizeof (query), "%s`%s`) VALUES(", query, field[i]);
        else
            format(query, sizeof (query), "%s`%s`, ", query, field[i]);
    }
    for (new i; i < count; i++)
    {
        if (i == (count - 1))
            format(query, sizeof (query), "%s'%q')", query, value[i]);
        else
            format(query, sizeof (query), "%s'%q', ", query, value[i]);
    }
    db_query(db, query);

    fclose(h);

    return printf("[initosql.inc] - SUCCESS: INI file '%s' was successfilly contverted to SQLite row in table '%s'.", file, table);
}
Usage:
pawn Код:
main()
{
    new DB:db = db_open("Test.db");
    db_query(db, "CREATE TABLE IF NOT EXISTS `Users` (`Name` TEXT PRIMARY KEY, `Score` INTEGER)");
   
    /*
    test.ini has the following lines
    - Name = Gammix
    - Score = 69
    */

    SQL_Convert("test.ini", db, "users");

    db_close(db);
}



Re: Is there any way to convert ini codes to sqllite?? - GhostHacker - 12.04.2016

Yeah thanks Gammix i knew this trick but it only converts ini files but is there any way to convert the script to sqllite


Re: Is there any way to convert ini codes to sqllite?? - ScIrUsna - 12.04.2016

Impossible


Re: Is there any way to convert ini codes to sqllite?? - saffierr - 12.04.2016

You have to learn the SQL first...


Re: Is there any way to convert ini codes to sqllite?? - introzen - 12.04.2016

Learn SQL and use "find and replace" as good as possible. Other than that, I don't know of any way.


Re: Is there any way to convert ini codes to sqllite?? - GhostHacker - 16.04.2016

ok is there any way to convert the mysql to sqllite?? (i learned sqllite now )