| 31 |
31 |
| 32 #include <dbutils/dbutils.h> |
32 #include <dbutils/dbutils.h> |
| 33 #include <dbutils/sqlite.h> |
33 #include <dbutils/sqlite.h> |
| 34 #include <dbutils/db.h> |
34 #include <dbutils/db.h> |
| 35 |
35 |
| |
36 #include <cx/buffer.h> |
| |
37 #include <cx/printf.h> |
| |
38 |
| 36 const char *sql_create_table_person = |
39 const char *sql_create_table_person = |
| 37 "create table if not exists Person (" |
40 "create table if not exists Person (" |
| 38 "person_id integer primary key autoincrement, " |
41 "person_id integer primary key autoincrement, " |
| 39 "name text, " |
42 "name text, " |
| 40 "email text, " |
43 "email text, " |
| 159 dbuObjectBuilderAddAdditionalQuery(builder, role, roleQuery); |
162 dbuObjectBuilderAddAdditionalQuery(builder, role, roleQuery); |
| 160 CxList *persons = dbuObjectBuilderGetList(builder); |
163 CxList *persons = dbuObjectBuilderGetList(builder); |
| 161 if(persons) { |
164 if(persons) { |
| 162 CxIterator i = cxListIterator(persons); |
165 CxIterator i = cxListIterator(persons); |
| 163 cx_foreach(Person *, p, i) { |
166 cx_foreach(Person *, p, i) { |
| 164 printf("{ person_id = %" PRId64 ", name = \"%s\", email = \"%s\", age = %d, iscustomer = %s, hash = %" PRIu64 " }\n", |
167 CxBuffer rolebuffer; |
| 165 p->person_id, p->name.ptr, p->email.ptr, p->age, p->iscustomer ? "true" : "false", p->hash); |
168 cxBufferInit(&rolebuffer, NULL, 256, 0, CX_BUFFER_AUTO_EXTEND|CX_BUFFER_FREE_CONTENTS); |
| |
169 cxBufferPut(&rolebuffer, '['); |
| |
170 if(p->roles) { |
| |
171 CxIterator r = cxListIterator(p->roles); |
| |
172 char *addseparator = ""; |
| |
173 cx_foreach(Role *, role, r) { |
| |
174 cx_bprintf(&rolebuffer, "%s{ role_id = %d, name = \"%s\"}", addseparator, role->role_id, role->name.ptr); |
| |
175 addseparator = ", "; |
| |
176 } |
| |
177 } |
| |
178 cxBufferPut(&rolebuffer, ']'); |
| |
179 cxBufferPut(&rolebuffer, 0); |
| |
180 printf("{ person_id = %" PRId64 ", name = \"%s\", email = \"%s\", age = %d, iscustomer = %s, hash = %" PRIu64 " roles = %s }\n", |
| |
181 p->person_id, p->name.ptr, p->email.ptr, p->age, p->iscustomer ? "true" : "false", p->hash, rolebuffer.space); |
| |
182 |
| |
183 cxBufferDestroy(&rolebuffer); |
| 166 } |
184 } |
| 167 } else { |
185 } else { |
| 168 fprintf(stderr, "Error\n"); |
186 fprintf(stderr, "Error\n"); |
| 169 } |
187 } |
| 170 |
188 |