Re: [Vala] Strange Behaviour?
- From: Thomas Jollans <t jollybox de>
- To: vala-list gnome org
- Subject: Re: [Vala] Strange Behaviour?
- Date: Wed, 27 Jun 2012 10:55:18 +0200
On 06/27/2012 09:12 AM, Peter Cartwright wrote:
Hello Vala-ites!
I'm working with the Mysql package and I'm stuck with something.
row1 = results.fetch_row ();
row2 = results.fetch_row ();
row1 and row2 are unique. No problem.
But..
fields1 = field_results.fetch_fields ();
fields2 = field_results.fetch_fields ();
fields1 seems to interfere with fields2. Are they pointing to the same
memory space?
Is this expected behaviour?
That sounds reasonable - I don't know the MySQL API, but I had a quick
look at the C API docs and it they don't say that the user has to clean
up the returned pointers, which implies that the library takes care of
it, which means it's only safe to use the result immediately after
obtaining it.
The usual way to use an API like this is to go through the results in a
loop and save the data you need in your own data structures.
T
In the code example below (with output) you can see that a reference kept
to the first fetch_fields() (temp) get overwritten (garbled?) by subsequent
fetch_fields().
Code Example:
--------------------------------
var row = results.fetch_row ();
var table = row[0];
var field_results = _DB.db.list_fields (table);
var fields = field_results.fetch_fields ();
var temp = fields;
stdout.printf("1)\n");
stdout.printf(" %s\n", table);
stdout.printf(" %s\n", fields[0].name);
stdout.printf("temp: %s\n", temp[0].name);
row = results.fetch_row ();
table = row[0];
field_results = _DB.db.list_fields (table);
fields = field_results.fetch_fields ();
stdout.printf("2)\n");
stdout.printf(" %s\n", table);
stdout.printf(" %s\n", fields[0].name);
stdout.printf("temp: %s\n", temp[0].name);
row = results.fetch_row ();
table = row[0];
field_results = _DB.db.list_fields (table);
fields = field_results.fetch_fields ();
stdout.printf("3)\n");
stdout.printf(" %s\n", table);
stdout.printf(" %s\n", fields[0].name);
stdout.printf("temp: %s\n", temp[0].name);
row = results.fetch_row ();
table = row[0];
field_results = _DB.db.list_fields (table);
fields = field_results.fetch_fields ();
stdout.printf("4)\n");
stdout.printf(" %s\n", table);
stdout.printf(" %s\n", fields[0].name);
stdout.printf("temp: %s\n", temp[0].name);
row = results.fetch_row ();
table = row[0];
field_results = _DB.db.list_fields (table);
fields = field_results.fetch_fields ();
stdout.printf("5)\n");
stdout.printf(" %s\n", table);
stdout.printf(" %s\n", fields[0].name);
stdout.printf("temp: %s\n", temp[0].name);
Output:
---------------------------
1)
AreaAccessAuthorisation
idAreaAccess
temp: idAreaAccess
2)
AreaClosedTimes
idAreaClosedTimes
temp: idAreaAccess
3)
AreaOpenAndClosedTimes
idAreaOpenTimes
temp: idAreaOpenTimes
4)
AreaOpenTimes
idAreaOpenTimes
temp: idAreaOpenTimes
5)
Areas
idAreas
temp:
cheers,
Peter
_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]