After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 540823 - SQLite returns data that needs special free methods
SQLite returns data that needs special free methods
Status: RESOLVED DUPLICATE of bug 542235
Product: vala
Classification: Core
Component: Bindings
0.3.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2008-06-29 22:19 UTC by Phil Housley
Modified: 2008-07-30 21:46 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Phil Housley 2008-06-29 22:19:38 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.
Comment 1 Matias 2008-07-15 15:24:56 UTC
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.

Comment 2 Jürg Billeter 2008-07-30 21:46:36 UTC
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 ***