GNOME Bugzilla – Bug 540823
SQLite returns data that needs special free methods
Last modified: 2008-07-30 21:46:36 UTC
Some data returned by SQLite cannot be freed using standard methods. The data are error messages and table data. A flawed but non-crashing solution is to add two new data types: + [Compact] + [Immutable] + [CCode (cname = "char", const_cname = "const char", free_function = "sqlite3_free")] + public class sqlitestring { + [CCode (cname = "g_strdup")] + public string to_string (); + } + + [Compact] + [Immutable] + [CCode (cname = "char*", const_cname = "const char*", free_function = "sqlite3_free_table")] + public class sqlitetable { + } And change the method signatures of exec and get_table: - public int exec (string sql, Callback? sqlite3_callback = null, void* data = null, out string errmsg = null); + public int exec (string sql, Callback? sqlite3_callback = null, void* data = null, out sqlitestring errmsg = null); - public int get_table (string sql, out string[] resultp, ref int nrow, ref int ncolumn, out string errmsg); + public int get_table (string sql, out sqlitetable resultp, out int nrow, out int ncolumn, out sqlitestring errmsg); The error message part works fine like this, the table part doesn't cause errors, but is unusable in Vala. If you access the table data with an [Import ()]ed C method, it does work.
Here is something that work just fine: Change get_table and free_table of sqlite3.vapi with this: [NoArrayLength] public int get_table (string sql, out weak string[] resultp, ref int nrow, ref int ncolumn, out weak string errmsg); [NoArrayLength] public static void free_table (string[] result); Remember to use nrow and ncolumn to manage resultp. Don't use resultp.length it always return 0.
Thanks for the bug report. This particular bug has already been reported into our bug tracking system, but please feel free to report any further bugs you find. *** This bug has been marked as a duplicate of 542235 ***