/*
 * RSSuper Database vapi - exports SQLite bindings for use by dependent modules
 */

[CCode (cheader_filename = "sqlite3.h")]
namespace SQLite {
    [CCode (cname = "sqlite3", free_function = "sqlite3_close")]
    public class DB {
        [CCode (cname = "sqlite3_open")]
        public static int open(string filename, out DB db);
        
        [CCode (cname = "sqlite3_close")]
        public int close();
        
        [CCode (cname = "sqlite3_exec")]
        public int exec(string sql, DBCallback? callback = null, void* arg = null, [CCode (array_length = false)] out string? errmsg = null);
        
        [CCode (cname = "sqlite3_errmsg")]
        public unowned string errmsg();
        
        [CCode (cname = "sqlite3_prepare_v2")]
        public int prepare_v2(string zSql, int nByte, out Stmt stmt, void* pzTail = null);
    }
    
    [CCode (cname = "sqlite3_stmt", free_function = "sqlite3_finalize")]
    public class Stmt {
        [CCode (cname = "sqlite3_step")]
        public int step();
        
        [CCode (cname = "sqlite3_column_count")]
        public int column_count();
        
        [CCode (cname = "sqlite3_column_text")]
        public unowned string column_text(int i);
        
        [CCode (cname = "sqlite3_column_int")]
        public int column_int(int i);
        
        [CCode (cname = "sqlite3_column_double")]
        public double column_double(int i);
        
        [CCode (cname = "sqlite3_bind_text")]
        public int bind_text(int i, string z, int n, void* x);
        
        [CCode (cname = "sqlite3_bind_int")]
        public int bind_int(int i, int val);
        
        [CCode (cname = "sqlite3_bind_double")]
        public int bind_double(int i, double val);
        
        [CCode (cname = "sqlite3_bind_null")]
        public int bind_null(int i);
        
        [CCode (cname = "sqlite3_finalize")]
        public int finalize();
    }
    
    [CCode (cname = "SQLITE_OK")]
    public const int SQLITE_OK;
    [CCode (cname = "SQLITE_ROW")]
    public const int SQLITE_ROW;
    [CCode (cname = "SQLITE_DONE")]
    public const int SQLITE_DONE;
    [CCode (cname = "SQLITE_ERROR")]
    public const int SQLITE_ERROR;
    
    [CCode (simple_type = true)]
    public delegate int DBCallback(void* arg, int argc, string[] argv, string[] col_names);
}
