Commit fac5730549689c974f7cd14a8a4fec4e6bffbdef

Authored by Silvan Calarco
1 parent 6e5e4496d7
Exists in master

Fix Sqlite3 weird problem by adding compile option -fno-toplevel-reorder

Showing 2 changed files with 15 additions and 10 deletions Inline Diff

1 find_package(ZLIB REQUIRED) 1 find_package(ZLIB REQUIRED)
2 find_package(PkgConfig) 2 find_package(PkgConfig)
3 set(THREADS_PREFER_PTHREAD_FLAG ON) 3 set(THREADS_PREFER_PTHREAD_FLAG ON)
4 find_package(Threads REQUIRED) 4 find_package(Threads REQUIRED)
5 pkg_check_modules(RPM REQUIRED rpm) 5 pkg_check_modules(RPM REQUIRED rpm)
6 pkg_check_modules(SQLITE3 REQUIRED sqlite3) 6 pkg_check_modules(SQLITE3 REQUIRED sqlite3)
7 find_library(LIBIBERTY NAMES iberty) 7 find_library(LIBIBERTY NAMES iberty)
8 8
9 include_directories(include) 9 include_directories(include)
10 10
11 string(REPLACE "." ";" VERSION_LIST ${RPM_VERSION}) 11 string(REPLACE "." ";" VERSION_LIST ${RPM_VERSION})
12 list(GET VERSION_LIST 0 RPM_VERSION_MAJOR) 12 list(GET VERSION_LIST 0 RPM_VERSION_MAJOR)
13 list(GET VERSION_LIST 1 RPM_VERSION_MINOR) 13 list(GET VERSION_LIST 1 RPM_VERSION_MINOR)
14 list(GET VERSION_LIST 2 RPM_VERSION_MICRO) 14 list(GET VERSION_LIST 2 RPM_VERSION_MICRO)
15 15
16 add_compile_definitions( 16 add_compile_definitions(
17 PACKAGE="Distromatic" 17 PACKAGE="Distromatic"
18 PACKAGE_VERSION="1.5.0" 18 PACKAGE_VERSION="1.5.0"
19 DEFAULT_CONFIGFILE="/etc/distromatic.conf" 19 DEFAULT_CONFIGFILE="/etc/distromatic.conf"
20 off64_t=__off64_t 20 off64_t=__off64_t
21 RPM_VERSION_MAJOR=${RPM_VERSION_MAJOR} 21 RPM_VERSION_MAJOR=${RPM_VERSION_MAJOR}
22 RPM_VERSION_MINOR=${RPM_VERSION_MINOR} 22 RPM_VERSION_MINOR=${RPM_VERSION_MINOR}
23 RPM_VERSION_MICRO=${RPM_VERSION_MICRO} 23 RPM_VERSION_MICRO=${RPM_VERSION_MICRO}
24 LOCALEDIR="${LOCALEDIR}" 24 LOCALEDIR="${LOCALEDIR}"
25 ) 25 )
26 26
27 add_executable(distromatic 27 add_executable(distromatic
28 buildtools.c 28 buildtools.c
29 changelog.c 29 changelog.c
30 distromatic.c 30 distromatic.c
31 functions.c 31 functions.c
32 reports.c 32 reports.c
33 headerlist.c 33 headerlist.c
34 requirelist.c 34 requirelist.c
35 rpmfunctions.c 35 rpmfunctions.c
36 backend-sqlite3.c 36 backend-sqlite3.c
37 ) 37 )
38 38
39 target_link_libraries(distromatic 39 target_link_libraries(distromatic
40 Threads::Threads 40 Threads::Threads
41 ${RPM_LIBRARIES} 41 ${RPM_LIBRARIES}
42 ${ZLIB_LIBRARIES} 42 ${ZLIB_LIBRARIES}
43 ${SQLITE3_LIBRARIES} 43 ${SQLITE3_LIBRARIES}
44 ${LIBIBERTY} 44 ${LIBIBERTY}
45 ) 45 )
46 target_include_directories(distromatic PUBLIC ${RPM_INCLUDE_DIRS}) 46 target_include_directories(distromatic PUBLIC ${RPM_INCLUDE_DIRS})
47 target_compile_options(distromatic PUBLIC -O2 -g -Wall -std=gnu11 -pedantic ${RPM_CFLAGS_OTHER}) 47 #
48 # NOTE: -fno-toplevel-reorder required to prevent Sqlite3 weird problems
49 #
50 target_compile_options(distromatic PUBLIC -O2 -fno-toplevel-reorder -g -Wall -std=gnu11 -pedantic ${RPM_CFLAGS_OTHER})
48 51
49 add_executable(distroquery 52 add_executable(distroquery
50 distroquery.c 53 distroquery.c
51 functions.c 54 functions.c
52 headerlist.c 55 headerlist.c
53 requirelist.c 56 requirelist.c
54 rpmfunctions.c 57 rpmfunctions.c
55 changelog.c 58 changelog.c
56 ) 59 )
57 60
58 target_link_libraries(distroquery 61 target_link_libraries(distroquery
59 Threads::Threads 62 Threads::Threads
60 ${RPM_LIBRARIES} 63 ${RPM_LIBRARIES}
61 ${ZLIB_LIBRARIES} 64 ${ZLIB_LIBRARIES}
62 ${SQLITE3_LIBRARIES} 65 ${SQLITE3_LIBRARIES}
63 ${LIBIBERTY} 66 ${LIBIBERTY}
64 ) 67 )
65 target_include_directories(distroquery PUBLIC ${RPM_INCLUDE_DIRS}) 68 target_include_directories(distroquery PUBLIC ${RPM_INCLUDE_DIRS})
66 69
67 install( 70 install(
68 TARGETS distromatic 71 TARGETS distromatic
69 DESTINATION ${CMAKE_INSTALL_PREFIX}/bin 72 DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
70 ) 73 )
71 74
72 install( 75 install(
73 TARGETS distroquery 76 TARGETS distroquery
74 DESTINATION /var/www/cgi-bin/ 77 DESTINATION /var/www/cgi-bin/
75 ) 78 )
76 79
src/backend-sqlite3.c
1 /* 1 /*
2 * distromatic - tool for RPM based repositories 2 * distromatic - tool for RPM based repositories
3 * 3 *
4 * Copyright (C) 2013-2020 by Silvan Calarco <silvan.calarco@mambasoft.it> 4 * Copyright (C) 2013-2020 by Silvan Calarco <silvan.calarco@mambasoft.it>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify it under 6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of version 2 of the GNU General Public License as published by the 7 * the terms of version 2 of the GNU General Public License as published by the
8 * Free Software Foundation. 8 * Free Software Foundation.
9 * 9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT 10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY, to the extent permitted by law; without even the implied 11 * ANY WARRANTY, to the extent permitted by law; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details. 13 * See the GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License along with 15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18 */ 18 */
19 19
20 #include <sqlite3.h> 20 #include <sqlite3.h>
21 #include "headerlist.h" 21 #include "headerlist.h"
22 #include "changelog.h" 22 #include "changelog.h"
23 #include "backend-sqlite3.h" 23 #include "backend-sqlite3.h"
24 #include "functions.h" 24 #include "functions.h"
25 25
26 char sqlite3_query[PATH_MAX]; 26 char sqlite3_query[PATH_MAX];
27 sqlite3_stmt *stmt; 27 sqlite3_stmt *stmt;
28 28
29 #define sqlite3_transaction_maxsize 10485760 29 #define sqlite3_transaction_maxsize 10485760
30 long sqlite3_transaction_size; 30 long sqlite3_transaction_size;
31 31
32 int SQLite_init_table(sqlite3 *db, const char* table_name, const char* table_query) { 32 int SQLite_init_table(sqlite3 *db, const char* table_name, const char* table_query) {
33 33
34 char myquery[PATH_MAX]; 34 char myquery[PATH_MAX];
35 35
36 snprintf(myquery, PATH_MAX, "CREATE TABLE IF NOT EXISTS %s(%s)", table_name, table_query); 36 snprintf(myquery, PATH_MAX, "CREATE TABLE IF NOT EXISTS %s(%s)", table_name, table_query);
37 37
38 if (sqlite3_exec(db, myquery, 0, 0, 0)) { 38 if (sqlite3_exec(db, myquery, 0, 0, 0)) {
39 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", myquery, sqlite3_errmsg(db)); 39 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", myquery, sqlite3_errmsg(db));
40 return 2; 40 return 2;
41 } 41 }
42 return 0; 42 return 0;
43 } 43 }
44 44
45 int SQLite_begin_transaction(sqlite3 *db) { 45 int SQLite_begin_transaction(sqlite3 *db) {
46 46
47 if (sqlite3_exec(db, "BEGIN TRANSACTION;", 0, 0, 0)) { 47 if (sqlite3_exec(db, "BEGIN TRANSACTION;", 0, 0, 0)) {
48 fprintf(stderr, "ERROR: SQLite: (BEGIN TRANSACTION) %s\n", sqlite3_errmsg(db)); 48 fprintf(stderr, "ERROR: SQLite: (BEGIN TRANSACTION) %s\n", sqlite3_errmsg(db));
49 return 1; 49 return 1;
50 } 50 }
51 51
52 sqlite3_transaction_size = 0; 52 sqlite3_transaction_size = 0;
53 return 0; 53 return 0;
54 } 54 }
55 55
56 int SQLite_commit_transaction(sqlite3 *db) { 56 int SQLite_commit_transaction(sqlite3 *db) {
57 if (sqlite3_exec(db, "COMMIT;", 0, 0, 0)) { 57 if (sqlite3_exec(db, "COMMIT;", 0, 0, 0)) {
58 fprintf(stderr, "ERROR: SQLite: (COMMIT) %s\n", sqlite3_errmsg(db)); 58 fprintf(stderr, "ERROR: SQLite: (COMMIT) %s\n", sqlite3_errmsg(db));
59 return 1; 59 return 1;
60 } 60 }
61 sqlite3_transaction_size = 0; 61 sqlite3_transaction_size = 0;
62 return 0; 62 return 0;
63 } 63 }
64 64
65 int SQLite_print_contents_subtree(sqlite3 *db, 65 int SQLite_print_contents_subtree(sqlite3 *db,
66 struct fileTree* ft, 66 struct fileTree* ft,
67 struct configTag* ct, 67 struct configTag* ct,
68 int arch) { 68 int arch) {
69 69
70 int thisrep, i; 70 int thisrep, i;
71 71
72 while (ft) { 72 while (ft) {
73 i = 0; 73 i = 0;
74 thisrep = 0; 74 thisrep = 0;
75 for (i = 0; i < ft->numproviders; i++) { 75 for (i = 0; i < ft->numproviders; i++) {
76 if (ft->provider[i]->altrepository == ct->repository_level) { 76 if (ft->provider[i]->altrepository == ct->repository_level) {
77 thisrep = 1; 77 thisrep = 1;
78 break; 78 break;
79 } 79 }
80 } 80 }
81 if (thisrep) { 81 if (thisrep) {
82 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO files VALUES(%ld,?,%ld,%ld,%ld,%d);", 82 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO files VALUES(%ld,?,%ld,%ld,%ld,%d);",
83 ft->id, 83 ft->id,
84 (ft->firstchild?ft->firstchild->id:-1), 84 (ft->firstchild?ft->firstchild->id:-1),
85 (ft->next?ft->next->id:-1), 85 (ft->next?ft->next->id:-1),
86 (ft->parent?ft->parent->id:-1), 86 (ft->parent?ft->parent->id:-1),
87 ft->numproviders); 87 ft->numproviders);
88 sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL); 88 sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL);
89 sqlite3_bind_text(stmt, 1, ft->name, -1, SQLITE_STATIC); 89 sqlite3_bind_text(stmt, 1, ft->name, -1, SQLITE_STATIC);
90 if (sqlite3_step(stmt) != SQLITE_DONE) { 90 if (sqlite3_step(stmt) != SQLITE_DONE) {
91 fprintf(stderr, "ERROR: sqlite3_step: %s (%s)\n", sqlite3_errmsg(db), sqlite3_query); 91 fprintf(stderr, "ERROR: sqlite3_step: %s (%s)\n", sqlite3_errmsg(db), sqlite3_query);
92 return 1; 92 return 1;
93 } 93 }
94 sqlite3_finalize(stmt); 94 sqlite3_finalize(stmt);
95 95
96 sqlite3_transaction_size += strlen(sqlite3_query); 96 sqlite3_transaction_size += strlen(sqlite3_query);
97 if (sqlite3_transaction_size >= sqlite3_transaction_maxsize) { 97 if (sqlite3_transaction_size >= sqlite3_transaction_maxsize) {
98 SQLite_commit_transaction(db); 98 SQLite_commit_transaction(db);
99 SQLite_begin_transaction(db); 99 SQLite_begin_transaction(db);
100 } 100 }
101 101
102 if (ft->firstchild) { 102 if (ft->firstchild) {
103 if (SQLite_print_contents_subtree(db, ft->firstchild, ct, arch)) return 1; 103 if (SQLite_print_contents_subtree(db, ft->firstchild, ct, arch)) return 1;
104 } 104 }
105 } 105 }
106 ft=ft->next; 106 ft=ft->next;
107 } 107 }
108 return 0; 108 return 0;
109 } 109 }
110 110
111 #define SQLITE_TABLE_files "id INTEGER PRIMARY KEY, "\ 111 #define SQLITE_TABLE_files "id INTEGER PRIMARY KEY, "\
112 "name STRING, firstchild INTEGER, next INTEGER, parent INTEGER, numproviders INTEGER" 112 "name STRING, firstchild INTEGER, next INTEGER, parent INTEGER, numproviders INTEGER"
113 /* struct headerList **provider; */ 113 /* struct headerList **provider; */
114 114
115 #define SQLITE_TABLE_packages_files_rel "id INTEGER PRIMARY KEY, id_package INTEGER, id_file INTEGER, "\ 115 #define SQLITE_TABLE_packages_files_rel "id INTEGER PRIMARY KEY, id_package INTEGER, id_file INTEGER, "\
116 "id_user INTEGER, id_group INTEGER, flags INTEGER, "\ 116 "id_user INTEGER, id_group INTEGER, flags INTEGER, "\
117 "name STRING, version STRING, release STRING" 117 "name STRING, version STRING, release STRING"
118 #define SQLITE_TABLE_fileusers "id INTEGER PRIMARY KEY, name STRING" 118 #define SQLITE_TABLE_fileusers "id INTEGER PRIMARY KEY, name STRING"
119 #define SQLITE_TABLE_filegroups "id INTEGER PRIMARY KEY, name STRING" 119 #define SQLITE_TABLE_filegroups "id INTEGER PRIMARY KEY, name STRING"
120 120
121 int generateSQLite_files(struct configTag* ct, sqlite3 *db, int arch) { 121 int generateSQLite_files(struct configTag* ct, sqlite3 *db, int arch) {
122 122
123 int i; 123 int i;
124 struct headerList* currpackage; 124 struct headerList* currpackage;
125 struct fileUserList *fileUser = ct->fileuserlist[arch]; 125 struct fileUserList *fileUser = ct->fileuserlist[arch];
126 struct fileGroupList *fileGroup = ct->filegrouplist[arch]; 126 struct fileGroupList *fileGroup = ct->filegrouplist[arch];
127 127
128 snprintf(sqlite3_query, PATH_MAX, "packages_files_rel"); 128 snprintf(sqlite3_query, PATH_MAX, "packages_files_rel");
129 SQLite_init_table(db, sqlite3_query, SQLITE_TABLE_packages_files_rel); 129 SQLite_init_table(db, sqlite3_query, SQLITE_TABLE_packages_files_rel);
130 130
131 snprintf(sqlite3_query, PATH_MAX, "files"); 131 snprintf(sqlite3_query, PATH_MAX, "files");
132 SQLite_init_table(db, sqlite3_query, SQLITE_TABLE_files); 132 SQLite_init_table(db, sqlite3_query, SQLITE_TABLE_files);
133 133
134 snprintf(sqlite3_query, PATH_MAX, "fileusers"); 134 snprintf(sqlite3_query, PATH_MAX, "fileusers");
135 SQLite_init_table(db, sqlite3_query, SQLITE_TABLE_fileusers); 135 SQLite_init_table(db, sqlite3_query, SQLITE_TABLE_fileusers);
136 136
137 snprintf(sqlite3_query, PATH_MAX, "filegroups"); 137 snprintf(sqlite3_query, PATH_MAX, "filegroups");
138 SQLite_init_table(db, sqlite3_query, SQLITE_TABLE_filegroups); 138 SQLite_init_table(db, sqlite3_query, SQLITE_TABLE_filegroups);
139 139
140 while (fileUser) { 140 while (fileUser) {
141 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO fileusers VALUES(%ld,?);", 141 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO fileusers VALUES(%ld,?);",
142 fileUser->id); 142 fileUser->id);
143 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { 143 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) {
144 fprintf(stderr, "ERROR: sqlite3_prepare_v2: %s (%s)\n", sqlite3_errmsg(db), sqlite3_query); 144 fprintf(stderr, "ERROR: sqlite3_prepare_v2: %s (%s)\n", sqlite3_errmsg(db), sqlite3_query);
145 return 1; 145 return 1;
146 } 146 }
147 sqlite3_bind_text(stmt, 1, fileUser->name, -1, SQLITE_STATIC); 147 sqlite3_bind_text(stmt, 1, fileUser->name, -1, SQLITE_STATIC);
148 if (sqlite3_step(stmt) != SQLITE_DONE) { 148 if (sqlite3_step(stmt) != SQLITE_DONE) {
149 fprintf(stderr, "ERROR: sqlite3_step: %s (%s)\n", sqlite3_query, sqlite3_errmsg(db)); 149 fprintf(stderr, "ERROR: sqlite3_step: %s (%s)\n", sqlite3_query, sqlite3_errmsg(db));
150 return 3; 150 return 3;
151 } 151 }
152 sqlite3_finalize(stmt); 152 sqlite3_finalize(stmt);
153 fileUser = fileUser->next; 153 fileUser = fileUser->next;
154 } 154 }
155 155
156 while (fileGroup) { 156 while (fileGroup) {
157 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO filegroups VALUES(%ld,?);", 157 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO filegroups VALUES(%ld,?);",
158 fileGroup->id); 158 fileGroup->id);
159 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { 159 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) {
160 fprintf(stderr, "ERROR: sqlite3_prepare_v2: %s (%s)\n", sqlite3_errmsg(db), sqlite3_query); 160 fprintf(stderr, "ERROR: sqlite3_prepare_v2: %s (%s)\n", sqlite3_errmsg(db), sqlite3_query);
161 return 1; 161 return 1;
162 } 162 }
163 sqlite3_bind_text(stmt, 1, fileGroup->name, -1, SQLITE_STATIC); 163 sqlite3_bind_text(stmt, 1, fileGroup->name, -1, SQLITE_STATIC);
164 if (sqlite3_step(stmt) != SQLITE_DONE) { 164 if (sqlite3_step(stmt) != SQLITE_DONE) {
165 fprintf(stderr, "ERROR: sqlite3_step: %s (%s)\n", sqlite3_query, sqlite3_errmsg(db)); 165 fprintf(stderr, "ERROR: sqlite3_step: %s (%s)\n", sqlite3_query, sqlite3_errmsg(db));
166 return 3; 166 return 3;
167 } 167 }
168 sqlite3_finalize(stmt); 168 sqlite3_finalize(stmt);
169 fileGroup = fileGroup->next; 169 fileGroup = fileGroup->next;
170 } 170 }
171 171
172 SQLite_begin_transaction(db); 172 SQLite_begin_transaction(db);
173 if (SQLite_print_contents_subtree(db, ct->filetree[arch], ct, arch)) return 1; 173 if (SQLite_print_contents_subtree(db, ct->filetree[arch], ct, arch)) return 1;
174 174
175 currpackage = ct->headerlist[arch]; 175 currpackage = ct->headerlist[arch];
176 while (currpackage) { 176 while (currpackage) {
177 if (currpackage->altrepository == ct->repository_level) { 177 if (currpackage->altrepository == ct->repository_level) {
178 /* packages <-> files relations */ 178 /* packages <-> files relations */
179 for (i = 0; i < currpackage->filenamecount; i++) { 179 for (i = 0; i < currpackage->filenamecount; i++) {
180 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO packages_files_rel VALUES(NULL,%ld,%ld,%ld,%ld,%d,?,?,?);", 180 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO packages_files_rel VALUES(NULL,%ld,%ld,%ld,%ld,%d,?,?,?);",
181 currpackage->id, 181 currpackage->id,
182 currpackage->file[i]->id, 182 currpackage->file[i]->id,
183 currpackage->fileuser[i]->id, 183 currpackage->fileuser[i]->id,
184 currpackage->filegroup[i]->id, 184 currpackage->filegroup[i]->id,
185 currpackage->fileflags[i]); 185 currpackage->fileflags[i]);
186 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { 186 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) {
187 fprintf(stderr, "ERROR: sqlite3_prepare_v2: %s (%s)\n", sqlite3_errmsg(db), sqlite3_query); 187 fprintf(stderr, "ERROR: sqlite3_prepare_v2: %s (%s)\n", sqlite3_errmsg(db), sqlite3_query);
188 return 1; 188 return 1;
189 } 189 }
190 sqlite3_bind_text(stmt, 1, currpackage->name, -1, SQLITE_STATIC); 190 sqlite3_bind_text(stmt, 1, currpackage->name, -1, SQLITE_STATIC);
191 sqlite3_bind_text(stmt, 2, currpackage->version, -1, SQLITE_STATIC); 191 sqlite3_bind_text(stmt, 2, currpackage->version, -1, SQLITE_STATIC);
192 sqlite3_bind_text(stmt, 3, currpackage->release, -1, SQLITE_STATIC); 192 sqlite3_bind_text(stmt, 3, currpackage->release, -1, SQLITE_STATIC);
193 if (sqlite3_step(stmt) != SQLITE_DONE) { 193 if (sqlite3_step(stmt) != SQLITE_DONE) {
194 fprintf(stderr, "ERROR: sqlite3_step: %s (%s)\n", sqlite3_query, sqlite3_errmsg(db)); 194 fprintf(stderr, "ERROR: sqlite3_step: %s (%s)\n", sqlite3_query, sqlite3_errmsg(db));
195 return 3; 195 return 3;
196 } 196 }
197 sqlite3_finalize(stmt); 197 sqlite3_finalize(stmt);
198 sqlite3_transaction_size += strlen(sqlite3_query); 198 sqlite3_transaction_size += strlen(sqlite3_query);
199 if (sqlite3_transaction_size >= sqlite3_transaction_maxsize) { 199 if (sqlite3_transaction_size >= sqlite3_transaction_maxsize) {
200 SQLite_commit_transaction(db); 200 SQLite_commit_transaction(db);
201 SQLite_begin_transaction(db); 201 SQLite_begin_transaction(db);
202 } 202 }
203 } 203 }
204 } 204 }
205 currpackage = currpackage->next; 205 currpackage = currpackage->next;
206 } 206 }
207 SQLite_commit_transaction(db); 207 SQLite_commit_transaction(db);
208 return 0; 208 return 0;
209 } 209 }
210 210
211 #define SQLITE_TABLE_provided "id INTEGER PRIMARY KEY, "\ 211 #define SQLITE_TABLE_provided "id INTEGER PRIMARY KEY, "\
212 "name STRING, flags INTEGER, numproviders INTEGER" 212 "name STRING, flags INTEGER, numproviders INTEGER"
213 213
214 int generateSQLite_provided(struct configTag* ct, sqlite3 *db, int arch) { 214 int generateSQLite_provided(struct configTag* ct, sqlite3 *db, int arch) {
215 215
216 struct providedList* provided; 216 struct providedList* provided;
217 int i, thisrep; 217 int i, thisrep;
218 218
219 snprintf(sqlite3_query, PATH_MAX, "provided"); 219 SQLite_init_table(db, "provided", SQLITE_TABLE_provided);
220 SQLite_init_table(db, sqlite3_query, SQLITE_TABLE_provided);
221 SQLite_begin_transaction(db); 220 SQLite_begin_transaction(db);
222 221
223 provided = ct->providedlist_idx[arch][0]; 222 provided = ct->providedlist_idx[arch][0];
224 while (provided) { 223 while (provided) {
225 i = 0; 224 i = 0;
226 thisrep = 0; 225 thisrep = 0;
227 for (i = 0; i < provided->numproviders; i++) { 226 for (i = 0; i < provided->numproviders; i++) {
228 if (provided->provider[i]->altrepository == ct->repository_level) { 227 if (provided->provider[i]->altrepository == ct->repository_level) {
229 thisrep = 1; 228 thisrep = 1;
230 break; 229 break;
231 } 230 }
232 } 231 }
233 if (thisrep) { 232 if (thisrep) {
234 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO provided VALUES(%ld,?,%ld,%d);", 233 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO provided VALUES(%ld,?,%ld,%d);",
235 provided->id, 234 provided->id,
236 provided->flags, 235 provided->flags,
237 provided->numproviders); 236 provided->numproviders);
238 sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL); 237 if (sqlite3_prepare_v3(db, sqlite3_query, -1, 0, &stmt, NULL)) {
239 sqlite3_bind_text(stmt, 1, provided->name, -1, SQLITE_STATIC); 238 fprintf(stderr, "ERROR: sqlite3_prepare_v2: %s (%s)\n", sqlite3_errmsg(db), sqlite3_query);
240 if (sqlite3_step(stmt) != SQLITE_DONE) { 239 return 1;
240 }
241 sqlite3_bind_text(stmt, 1, provided->name, -1, SQLITE_STATIC);
242 if (sqlite3_step(stmt) != SQLITE_DONE) {
241 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); 243 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
242 return 1; 244 return 3;
243 } 245 }
244 sqlite3_finalize(stmt); 246 sqlite3_finalize(stmt);
245 } 247 }
246 provided = provided->next; 248 provided = provided->next;
247 } 249 }
248 SQLite_commit_transaction(db); 250 SQLite_commit_transaction(db);
249 return 0; 251 return 0;
250 } 252 }
251 253
252 #define SQLITE_TABLE_packagers "id INTEGER PRIMARY KEY, "\ 254 #define SQLITE_TABLE_packagers "id INTEGER PRIMARY KEY, "\
253 "name STRING, role INTEGER, changes_count INTEGER, packages_count INTEGER" 255 "name STRING, role INTEGER, changes_count INTEGER, packages_count INTEGER"
254 /* char *alias[PACKAGER_MAXALIASES]; */ 256 /* char *alias[PACKAGER_MAXALIASES]; */
255 257
256 int generateSQLite_packagers(sqlite3 *db) { 258 int generateSQLite_packagers(sqlite3 *db) {
257 259
258 struct Packager* packager = firstPackager(); 260 struct Packager* packager = firstPackager();
259 261
260 SQLite_init_table(db, "packagers", SQLITE_TABLE_packagers); 262 SQLite_init_table(db, "packagers", SQLITE_TABLE_packagers);
261 SQLite_begin_transaction(db); 263 SQLite_begin_transaction(db);
262 264
263 while (packager) { 265 while (packager) {
264 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO packagers VALUES(NULL,?,%d,%d,%d);", 266 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO packagers VALUES(NULL,?,%d,%d,%d);",
265 packager->role, 267 packager->role,
266 packager->changes_count, 268 packager->changes_count,
267 packager->packages_count); 269 packager->packages_count);
268 270
269 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { 271 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) {
270 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); 272 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
271 } 273 }
272 sqlite3_bind_text(stmt, 1, packager->name, -1, SQLITE_STATIC); 274 sqlite3_bind_text(stmt, 1, packager->name, -1, SQLITE_STATIC);
273 if (sqlite3_step(stmt) != SQLITE_DONE) { 275 if (sqlite3_step(stmt) != SQLITE_DONE) {
274 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); 276 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
275 return 3; 277 return 3;
276 } 278 }
277 packager->id = sqlite3_last_insert_rowid(db); 279 packager->id = sqlite3_last_insert_rowid(db);
278 sqlite3_finalize(stmt); 280 sqlite3_finalize(stmt);
279 packager = packager->next; 281 packager = packager->next;
280 } 282 }
281 SQLite_commit_transaction(db); 283 SQLite_commit_transaction(db);
282 return 0; 284 return 0;
283 } 285 }
284 286
285 long generateSQLite_add_changelog(sqlite3 *db, struct changeLog* firstchangelog, long id_source) { 287 long generateSQLite_add_changelog(sqlite3 *db, struct changeLog* firstchangelog, long id_source) {
286 288
287 struct changeLog* changelog = firstchangelog; 289 struct changeLog* changelog = firstchangelog;
288 long lastchangelogid = 0; 290 long lastchangelogid = 0;
289 291
290 while (changelog) { 292 while (changelog) {
291 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO changelog VALUES(NULL,%ld,%ld,%ld,?,?);", 293 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO changelog VALUES(NULL,%ld,%ld,%ld,?,?);",
292 id_source, 294 id_source,
293 changelog->time, 295 changelog->time,
294 changelog->pkg->id); 296 changelog->pkg->id);
295 297
296 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { 298 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) {
297 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); 299 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
298 } 300 }
299 sqlite3_bind_text(stmt, 1, changelog->release, -1, SQLITE_STATIC); 301 sqlite3_bind_text(stmt, 1, changelog->release, -1, SQLITE_STATIC);
300 sqlite3_bind_text(stmt, 2, changelog->text, -1, SQLITE_STATIC); 302 sqlite3_bind_text(stmt, 2, changelog->text, -1, SQLITE_STATIC);
301 if (sqlite3_step(stmt) != SQLITE_DONE) { 303 if (sqlite3_step(stmt) != SQLITE_DONE) {
302 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); 304 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
303 return 3; 305 return 3;
304 } 306 }
305 changelog->id = sqlite3_last_insert_rowid(db); 307 changelog->id = sqlite3_last_insert_rowid(db);
306 lastchangelogid = changelog->id; 308 lastchangelogid = changelog->id;
307 sqlite3_finalize(stmt); 309 sqlite3_finalize(stmt);
308 changelog = changelog->next; 310 changelog = changelog->next;
309 } 311 }
310 return lastchangelogid; 312 return lastchangelogid;
311 } 313 }
312 314
313 #define SQLITE_TABLE_packages "id INTEGER PRIMARY KEY, "\ 315 #define SQLITE_TABLE_packages "id INTEGER PRIMARY KEY, "\
314 "name STRING, altrepository INTEGER, epoch INTEGER, version STRING, release STRING, summary STRING, "\ 316 "name STRING, altrepository INTEGER, epoch INTEGER, version STRING, release STRING, summary STRING, "\
315 "groupdescr STRING, description STRING, size INTEGER, id_source INTEGER" 317 "groupdescr STRING, description STRING, size INTEGER, id_source INTEGER"
316 318
317 #define SQLITE_TABLE_obsoletes "id INTEGER PRIMARY KEY, "\ 319 #define SQLITE_TABLE_obsoletes "id INTEGER PRIMARY KEY, "\
318 "id_package INTEGER, obsoletename STRING, obsoleteflags INTEGER, obsoleteversion STRING" 320 "id_package INTEGER, obsoletename STRING, obsoleteflags INTEGER, obsoleteversion STRING"
319 321
320 #define SQLITE_TABLE_provides "id INTEGER PRIMARY KEY, "\ 322 #define SQLITE_TABLE_provides "id INTEGER PRIMARY KEY, "\
321 "id_package INTEGER, id_provided INTEGER, provideflags INTEGER, provideversion STRING" 323 "id_package INTEGER, id_provided INTEGER, provideflags INTEGER, provideversion STRING"
322 324
323 #define SQLITE_TABLE_requires "id INTEGER PRIMARY KEY, "\ 325 #define SQLITE_TABLE_requires "id INTEGER PRIMARY KEY, "\
324 "id_package INTEGER, id_provided STRING, requireflags INTEGER, requireversion STRING" 326 "id_package INTEGER, id_provided STRING, requireflags INTEGER, requireversion STRING"
325 327
326 int 328 int
327 generateSQLite_packages(struct configTag *ct, sqlite3 *db, int arch) { 329 generateSQLite_packages(struct configTag *ct, sqlite3 *db, int arch) {
328 330
329 struct headerList* currpackage; 331 struct headerList* currpackage;
330 int i; 332 int i;
331 333
332 SQLite_init_table(db, "packages", SQLITE_TABLE_packages); 334 SQLite_init_table(db, "packages", SQLITE_TABLE_packages);
333 SQLite_init_table(db, "obsoletes", SQLITE_TABLE_obsoletes); 335 SQLite_init_table(db, "obsoletes", SQLITE_TABLE_obsoletes);
334 SQLite_init_table(db, "provides", SQLITE_TABLE_provides); 336 SQLite_init_table(db, "provides", SQLITE_TABLE_provides);
335 SQLite_init_table(db, "requires", SQLITE_TABLE_requires); 337 SQLite_init_table(db, "requires", SQLITE_TABLE_requires);
336 SQLite_begin_transaction(db); 338 SQLite_begin_transaction(db);
337 339
338 currpackage = ct->headerlist[arch]; 340 currpackage = ct->headerlist[arch];
339 while (currpackage) { 341 while (currpackage) {
340 if (currpackage->altrepository == ct->repository_level) { 342 if (currpackage->altrepository == ct->repository_level) {
341 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO packages VALUES(NULL,?,%d,%ld,?,?,?,?,?,%ld,%ld);", 343 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO packages VALUES(NULL,?,%d,%ld,?,?,?,?,?,%ld,%ld);",
342 currpackage->altrepository, 344 currpackage->altrepository,
343 currpackage->epoch, 345 currpackage->epoch,
344 currpackage->size, 346 currpackage->size,
345 currpackage->sourceheader->id); 347 currpackage->sourceheader->id);
346 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { 348 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) {
347 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); 349 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
348 return 1; 350 return 1;
349 } 351 }
350 352
351 sqlite3_bind_text(stmt, 1, currpackage->name, -1, SQLITE_STATIC); 353 sqlite3_bind_text(stmt, 1, currpackage->name, -1, SQLITE_STATIC);
352 sqlite3_bind_text(stmt, 2, currpackage->version, -1, SQLITE_STATIC); 354 sqlite3_bind_text(stmt, 2, currpackage->version, -1, SQLITE_STATIC);
353 sqlite3_bind_text(stmt, 3, currpackage->release, -1, SQLITE_STATIC); 355 sqlite3_bind_text(stmt, 3, currpackage->release, -1, SQLITE_STATIC);
354 sqlite3_bind_text(stmt, 4, currpackage->summary, -1, SQLITE_STATIC); 356 sqlite3_bind_text(stmt, 4, currpackage->summary, -1, SQLITE_STATIC);
355 sqlite3_bind_text(stmt, 5, currpackage->group, -1, SQLITE_STATIC); 357 sqlite3_bind_text(stmt, 5, currpackage->group, -1, SQLITE_STATIC);
356 sqlite3_bind_text(stmt, 6, currpackage->description, -1, SQLITE_STATIC); 358 sqlite3_bind_text(stmt, 6, currpackage->description, -1, SQLITE_STATIC);
357 359
358 if (sqlite3_step(stmt) != SQLITE_DONE) { 360 if (sqlite3_step(stmt) != SQLITE_DONE) {
359 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); 361 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
360 return 3; 362 return 3;
361 } 363 }
362 currpackage->id = sqlite3_last_insert_rowid(db); 364 currpackage->id = sqlite3_last_insert_rowid(db);
363 sqlite3_finalize(stmt); 365 sqlite3_finalize(stmt);
364 366
365 /* obsoletes */ 367 /* obsoletes */
366 for (i = 0; i < currpackage->obsoletecount; i++) { 368 for (i = 0; i < currpackage->obsoletecount; i++) {
367 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO obsoletes VALUES(NULL,%ld,?,%d,?);", 369 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO obsoletes VALUES(NULL,%ld,?,%d,?);",
368 currpackage->id, 370 currpackage->id,
369 currpackage->obsoleteflags[i]); 371 currpackage->obsoleteflags[i]);
370 372
371 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { 373 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) {
372 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); 374 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
373 } 375 }
374 sqlite3_bind_text(stmt, 1, currpackage->obsoletename[i], -1, SQLITE_STATIC); 376 sqlite3_bind_text(stmt, 1, currpackage->obsoletename[i], -1, SQLITE_STATIC);
375 sqlite3_bind_text(stmt, 2, currpackage->obsoleteversion[i], -1, SQLITE_STATIC); 377 sqlite3_bind_text(stmt, 2, currpackage->obsoleteversion[i], -1, SQLITE_STATIC);
376 if (sqlite3_step(stmt) != SQLITE_DONE) { 378 if (sqlite3_step(stmt) != SQLITE_DONE) {
377 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); 379 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
378 return 3; 380 return 3;
379 } 381 }
380 sqlite3_finalize(stmt); 382 sqlite3_finalize(stmt);
381 } 383 }
382 384
383 /* provides */ 385 /* provides */
384 for (i = 0; i < currpackage->providecount; i++) { 386 for (i = 0; i < currpackage->providecount; i++) {
385 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO provides VALUES(NULL,%ld,%ld,%d,?);", 387 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO provides VALUES(NULL,%ld,%ld,%d,?);",
386 currpackage->id, 388 currpackage->id,
387 currpackage->provided[i]->id, 389 currpackage->provided[i]->id,
388 currpackage->provideflags[i]); 390 currpackage->provideflags[i]);
389 391
390 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { 392 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) {
391 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); 393 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
392 } 394 }
393 sqlite3_bind_text(stmt, 1, currpackage->provideversion[i], -1, SQLITE_STATIC); 395 sqlite3_bind_text(stmt, 1, currpackage->provideversion[i], -1, SQLITE_STATIC);
394 if (sqlite3_step(stmt) != SQLITE_DONE) { 396 if (sqlite3_step(stmt) != SQLITE_DONE) {
395 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); 397 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
396 return 3; 398 return 3;
397 } 399 }
398 sqlite3_finalize(stmt); 400 sqlite3_finalize(stmt);
399 } 401 }
400 402
401 /* requires */ 403 /* requires */
402 for (i = 0; i < currpackage->requirecount; i++) { 404 for (i = 0; i < currpackage->requirecount; i++) {
403 if (currpackage->require[i]->resolved) { 405 if (currpackage->require[i]->resolved) {
404 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO requires VALUES(NULL,%ld,%ld,%ld,?);", 406 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO requires VALUES(NULL,%ld,%ld,%ld,?);",
405 currpackage->id, 407 currpackage->id,
406 currpackage->require[i]->resolved->id, 408 currpackage->require[i]->resolved->id,
407 currpackage->require[i]->flags); 409 currpackage->require[i]->flags);
408 410
409 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { 411 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) {
410 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); 412 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
411 } 413 }
412 sqlite3_bind_text(stmt, 1, currpackage->require[i]->version, -1, SQLITE_STATIC); 414 sqlite3_bind_text(stmt, 1, currpackage->require[i]->version, -1, SQLITE_STATIC);
413 if (sqlite3_step(stmt) != SQLITE_DONE) { 415 if (sqlite3_step(stmt) != SQLITE_DONE) {
414 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); 416 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
415 return 3; 417 return 3;
416 } 418 }
417 sqlite3_finalize(stmt); 419 sqlite3_finalize(stmt);
418 } else if (strstr(currpackage->require[i]->name,"rpmlib(") != currpackage->require[i]->name) { 420 } else if (strstr(currpackage->require[i]->name,"rpmlib(") != currpackage->require[i]->name) {
419 fprintf(stderr, "WARNING: package %s require %s not in provided list\n", currpackage->name, currpackage->require[i]->name); 421 fprintf(stderr, "WARNING: package %s require %s not in provided list\n", currpackage->name, currpackage->require[i]->name);
420 } 422 }
421 } 423 }
422 } 424 }
423 currpackage = currpackage->next; 425 currpackage = currpackage->next;
424 } 426 }
425 SQLite_commit_transaction(db); 427 SQLite_commit_transaction(db);
426 return 0; 428 return 0;
427 } 429 }
428 430
429 #define SQLITE_TABLE_sources_source "id INTEGER PRIMARY KEY, id_source INTEGER, source STRING" 431 #define SQLITE_TABLE_sources_source "id INTEGER PRIMARY KEY, id_source INTEGER, source STRING"
430 #define SQLITE_TABLE_sources_patch "id INTEGER PRIMARY KEY, id_source INTEGER, patch STRING" 432 #define SQLITE_TABLE_sources_patch "id INTEGER PRIMARY KEY, id_source INTEGER, patch STRING"
431 #define SQLITE_TABLE_sources "id INTEGER PRIMARY KEY, "\ 433 #define SQLITE_TABLE_sources "id INTEGER PRIMARY KEY, "\
432 "name STRING, altrepository INTEGER, epoch INTEGER, version STRING, release STRING, summary STRING, id_packager INTEGER, "\ 434 "name STRING, altrepository INTEGER, epoch INTEGER, version STRING, release STRING, summary STRING, id_packager INTEGER, "\
433 "groupdescr STRING, description STRING, url STRING, license STRING, arch STRING, buildarchs STRING, " \ 435 "groupdescr STRING, description STRING, url STRING, license STRING, arch STRING, buildarchs STRING, " \
434 "excludearch STRING, buildtime INTEGER, size INTEGER, id_changelog INTEGER" 436 "excludearch STRING, buildtime INTEGER, size INTEGER, id_changelog INTEGER"
435 //#define SQLITE_TABLE_sources_files_rel "id INTEGER PRIMARY KEY, id_source INTEGER, id_files INTEGER" 437 //#define SQLITE_TABLE_sources_files_rel "id INTEGER PRIMARY KEY, id_source INTEGER, id_files INTEGER"
436 //#define SQLITE_TABLE_sources_provided_rel "id INTEGER PRIMARY KEY, id_source INTEGER, id_provided INTEGER" 438 //#define SQLITE_TABLE_sources_provided_rel "id INTEGER PRIMARY KEY, id_source INTEGER, id_provided INTEGER"
437 #define SQLITE_TABLE_changelog "id INTEGER PRIMARY KEY, "\ 439 #define SQLITE_TABLE_changelog "id INTEGER PRIMARY KEY, "\
438 "id_source INTEGER, time INTEGER, id_packager INTEGER, release STRING, text STRING" 440 "id_source INTEGER, time INTEGER, id_packager INTEGER, release STRING, text STRING"
439 #define SQLITE_TABLE_buildrequires "id INTEGER PRIMARY KEY, "\ 441 #define SQLITE_TABLE_buildrequires "id INTEGER PRIMARY KEY, "\
440 "id_source INTEGER, buildrequirename STRING, buildrequireflags INTEGER, buildrequireversion STRING" 442 "id_source INTEGER, buildrequirename STRING, buildrequireflags INTEGER, buildrequireversion STRING"
441 443
442 int 444 int
443 generateSQLite_sources(struct configTag *ct, sqlite3 *db) { 445 generateSQLite_sources(struct configTag *ct, sqlite3 *db) {
444 446
445 struct headerSourceList* currsource; 447 struct headerSourceList* currsource;
446 int i; 448 int i;
447 long nextchangelogid = 1; 449 long nextchangelogid = 1;
448 450
449 SQLite_init_table(db, "sources", SQLITE_TABLE_sources); 451 SQLite_init_table(db, "sources", SQLITE_TABLE_sources);
450 SQLite_init_table(db, "sources_source", SQLITE_TABLE_sources_source); 452 SQLite_init_table(db, "sources_source", SQLITE_TABLE_sources_source);
451 SQLite_init_table(db, "sources_patch", SQLITE_TABLE_sources_patch); 453 SQLite_init_table(db, "sources_patch", SQLITE_TABLE_sources_patch);
452 // SQLite_init_table(db, "sources_files_rel", SQLITE_TABLE_sources_files_rel); 454 // SQLite_init_table(db, "sources_files_rel", SQLITE_TABLE_sources_files_rel);
453 // SQLite_init_table(db, "sources_provided_rel", SQLITE_TABLE_sources_provided_rel); 455 // SQLite_init_table(db, "sources_provided_rel", SQLITE_TABLE_sources_provided_rel);
454 SQLite_init_table(db, "changelog", SQLITE_TABLE_changelog); 456 SQLite_init_table(db, "changelog", SQLITE_TABLE_changelog);
455 SQLite_init_table(db, "buildrequires", SQLITE_TABLE_buildrequires); 457 SQLite_init_table(db, "buildrequires", SQLITE_TABLE_buildrequires);
456 SQLite_begin_transaction(db); 458 SQLite_begin_transaction(db);
457 459
458 currsource = ct->headersourcelist; 460 currsource = ct->headersourcelist;
459 while (currsource != NULL) { 461 while (currsource != NULL) {
460 if (currsource->altrepository == ct->repository_level) { 462 if (currsource->altrepository == ct->repository_level) {
461 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO sources VALUES(%ld,?,%d,%ld,?,?,?,%ld,?,?,?,?,?,?,?,%ld,%ld,%ld);", 463 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO sources VALUES(%ld,?,%d,%ld,?,?,?,%ld,?,?,?,?,?,?,?,%ld,%ld,%ld);",
462 currsource->id, 464 currsource->id,
463 currsource->altrepository, 465 currsource->altrepository,
464 currsource->epoch, 466 currsource->epoch,
465 currsource->packager->id, 467 currsource->packager->id,
466 currsource->buildtime, 468 currsource->buildtime,
467 currsource->size, 469 currsource->size,
468 (currsource->changelog?nextchangelogid:0)); 470 (currsource->changelog?nextchangelogid:0));
469 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { 471 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) {
470 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); 472 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
471 } 473 }
472 474
473 sqlite3_bind_text(stmt, 1, currsource->name, -1, SQLITE_STATIC); 475 sqlite3_bind_text(stmt, 1, currsource->name, -1, SQLITE_STATIC);
474 sqlite3_bind_text(stmt, 2, currsource->version, -1, SQLITE_STATIC); 476 sqlite3_bind_text(stmt, 2, currsource->version, -1, SQLITE_STATIC);
475 sqlite3_bind_text(stmt, 3, currsource->release, -1, SQLITE_STATIC); 477 sqlite3_bind_text(stmt, 3, currsource->release, -1, SQLITE_STATIC);
476 sqlite3_bind_text(stmt, 4, currsource->summary, -1, SQLITE_STATIC); 478 sqlite3_bind_text(stmt, 4, currsource->summary, -1, SQLITE_STATIC);
477 sqlite3_bind_text(stmt, 5, currsource->group, -1, SQLITE_STATIC); 479 sqlite3_bind_text(stmt, 5, currsource->group, -1, SQLITE_STATIC);
478 sqlite3_bind_text(stmt, 6, currsource->description, -1, SQLITE_STATIC); 480 sqlite3_bind_text(stmt, 6, currsource->description, -1, SQLITE_STATIC);
479 sqlite3_bind_text(stmt, 7, currsource->url, -1, SQLITE_STATIC); 481 sqlite3_bind_text(stmt, 7, currsource->url, -1, SQLITE_STATIC);
480 sqlite3_bind_text(stmt, 8, currsource->license, -1, SQLITE_STATIC); 482 sqlite3_bind_text(stmt, 8, currsource->license, -1, SQLITE_STATIC);
481 sqlite3_bind_text(stmt, 9, currsource->arch, -1, SQLITE_STATIC); 483 sqlite3_bind_text(stmt, 9, currsource->arch, -1, SQLITE_STATIC);
482 sqlite3_bind_text(stmt, 10, currsource->buildarchs, -1, SQLITE_STATIC); 484 sqlite3_bind_text(stmt, 10, currsource->buildarchs, -1, SQLITE_STATIC);
483 sqlite3_bind_text(stmt, 11, currsource->excludearch, -1, SQLITE_STATIC); 485 sqlite3_bind_text(stmt, 11, currsource->excludearch, -1, SQLITE_STATIC);
484 486
485 if (sqlite3_step(stmt) != SQLITE_DONE) { 487 if (sqlite3_step(stmt) != SQLITE_DONE) {
486 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); 488 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
487 return 3; 489 return 3;
488 } 490 }
489 currsource->id = sqlite3_last_insert_rowid(db); 491 currsource->id = sqlite3_last_insert_rowid(db);
490 sqlite3_finalize(stmt); 492 sqlite3_finalize(stmt);
491 493
492 /* source */ 494 /* source */
493 if (currsource->source) { 495 if (currsource->source) {
494 i=0; 496 i=0;
495 while (currsource->source[i]) { 497 while (currsource->source[i]) {
496 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO sources_source VALUES(NULL,%ld,?);", 498 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO sources_source VALUES(NULL,%ld,?);",
497 currsource->id); 499 currsource->id);
498 500
499 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { 501 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) {
500 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); 502 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
501 } 503 }
502 sqlite3_bind_text(stmt, 1, currsource->source[i], -1, SQLITE_STATIC); 504 sqlite3_bind_text(stmt, 1, currsource->source[i], -1, SQLITE_STATIC);
503 if (sqlite3_step(stmt) != SQLITE_DONE) { 505 if (sqlite3_step(stmt) != SQLITE_DONE) {
504 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); 506 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
505 return 3; 507 return 3;
506 } 508 }
507 sqlite3_finalize(stmt); 509 sqlite3_finalize(stmt);
508 i++; 510 i++;
509 } 511 }
510 } 512 }
511 513
512 /* patch */ 514 /* patch */
513 if (currsource->patch) { 515 if (currsource->patch) {
514 i=0; 516 i=0;
515 while (currsource->patch[i]) { 517 while (currsource->patch[i]) {
516 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO sources_patch VALUES(NULL,%ld,?);", 518 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO sources_patch VALUES(NULL,%ld,?);",
517 currsource->id); 519 currsource->id);
518 520
519 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { 521 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) {
520 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); 522 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
521 } 523 }
522 sqlite3_bind_text(stmt, 1, currsource->patch[i], -1, SQLITE_STATIC); 524 sqlite3_bind_text(stmt, 1, currsource->patch[i], -1, SQLITE_STATIC);
523 if (sqlite3_step(stmt) != SQLITE_DONE) { 525 if (sqlite3_step(stmt) != SQLITE_DONE) {
524 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); 526 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
525 return 3; 527 return 3;
526 } 528 }
527 sqlite3_finalize(stmt); 529 sqlite3_finalize(stmt);
528 i++; 530 i++;
529 } 531 }
530 } 532 }
531 533
532 /* buildrequires */ 534 /* buildrequires */
533 for (i = 0; i < currsource->requirecount; i++) { 535 for (i = 0; i < currsource->requirecount; i++) {
534 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO buildrequires VALUES(NULL,%ld,?,%ld,?);", 536 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO buildrequires VALUES(NULL,%ld,?,%ld,?);",
535 currsource->id, 537 currsource->id,
536 currsource->require[i]->flags); 538 currsource->require[i]->flags);
537 539
538 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { 540 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) {
539 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); 541 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
540 } 542 }
541 sqlite3_bind_text(stmt, 1, currsource->require[i]->name, -1, SQLITE_STATIC); 543 sqlite3_bind_text(stmt, 1, currsource->require[i]->name, -1, SQLITE_STATIC);
542 sqlite3_bind_text(stmt, 2, currsource->require[i]->version, -1, SQLITE_STATIC); 544 sqlite3_bind_text(stmt, 2, currsource->require[i]->version, -1, SQLITE_STATIC);
543 if (sqlite3_step(stmt) != SQLITE_DONE) { 545 if (sqlite3_step(stmt) != SQLITE_DONE) {
544 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); 546 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
545 return 3; 547 return 3;
546 } 548 }
547 sqlite3_finalize(stmt); 549 sqlite3_finalize(stmt);
548 } 550 }
549 551
550 /* sources <-> provided relations (buildrequirements) */ 552 /* sources <-> provided relations (buildrequirements) */
551 /* for (i=0; i<currsource->providecount; i++) { 553 /* for (i=0; i<currsource->providecount; i++) {
552 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO sources_provided_rel VALUES(NULL,%d,%d);", 554 snprintf(sqlite3_query, PATH_MAX, "INSERT INTO sources_provided_rel VALUES(NULL,%d,%d);",
553 currsource->id, 555 currsource->id,
554 currsource->required[i]->id); 556 currsource->required[i]->id);
555 557
556 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { 558 if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) {
557 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); 559 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
558 } 560 }
559 if (sqlite3_step(stmt) != SQLITE_DONE) { 561 if (sqlite3_step(stmt) != SQLITE_DONE) {
560 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); 562 fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
561 return 3; 563 return 3;
562 } 564 }
563 sqlite3_finalize(stmt); 565 sqlite3_finalize(stmt);
564 }*/ 566 }*/
565 567
566 if (currsource->changelog) { 568 if (currsource->changelog) {
567 nextchangelogid = generateSQLite_add_changelog(db, currsource->changelog, currsource->id) + 1; 569 nextchangelogid = generateSQLite_add_changelog(db, currsource->changelog, currsource->id) + 1;
568 } 570 }
569 } 571 }
570 currsource = currsource->next; 572 currsource = currsource->next;
571 } 573 }
572 SQLite_commit_transaction(db); 574 SQLite_commit_transaction(db);
573 return 0; 575 return 0;
574 } 576 }
575 577
576 int 578 int
577 generateSQLiteFiles(struct configTag *ct) 579 generateSQLiteFiles(struct configTag *ct)
578 { 580 {
579 sqlite3 *db = NULL; 581 sqlite3 *db = NULL;
580 char dbname[PATH_MAX]; 582 char dbname[PATH_MAX];
581 int i; 583 int i;
582 584
583 for (i = 0; i < ARCHS_MAX && ct->arch[i]; i++) { 585 for (i = 0; i < ARCHS_MAX && ct->arch[i]; i++) {
584 snprintf(dbname, PATH_MAX, "%s%s-%s-files.db", ct->repository_dir, ct->tag, ct->arch[i]); 586 snprintf(dbname, PATH_MAX, "%s%s-%s-files.db", ct->repository_dir, ct->tag, ct->arch[i]);
585 unlink(dbname); 587 unlink(dbname);
586 588
587 if (sqlite3_open_v2(dbname, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL)) { 589 if (sqlite3_open_v2(dbname, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL)) {
588 logmsg(LOG_ERROR, "sqlite3_open_v2: %s (%s)", dbname, sqlite3_errmsg(db)); 590 logmsg(LOG_ERROR, "sqlite3_open_v2: %s (%s)", dbname, sqlite3_errmsg(db));
589 if (db) sqlite3_close(db); 591 if (db) sqlite3_close(db);
590 return 1; 592 return 1;
591 } 593 }
592 if (generateSQLite_files(ct, db, i)) return 1; 594 if (generateSQLite_files(ct, db, i)) return 1;
593 if (db) sqlite3_close(db); 595 if (db) sqlite3_close(db);
594 } 596 }
595 return 0; 597 return 0;
596 } 598 }
597 599
598 int 600 int
599 generateSQLite(struct configTag *ct) 601 generateSQLite(struct configTag *ct)
600 { 602 {
601 sqlite3 *db = NULL; 603 sqlite3 *db = NULL;
602 char dbname[PATH_MAX]; 604 char dbname[PATH_MAX];
603 int i; 605 int i;
604 606
605 for (i = 0; i < ARCHS_MAX && ct->arch[i]; i++) { 607 for (i = 0; i < ARCHS_MAX && ct->arch[i]; i++) {
606 snprintf(dbname, PATH_MAX, "%s%s-%s.db", ct->repository_dir, ct->tag, ct->arch[i]); 608 snprintf(dbname, PATH_MAX, "%s%s-%s.db", ct->repository_dir, ct->tag, ct->arch[i]);
607 unlink(dbname); 609 unlink(dbname);
608 610
609 if (sqlite3_open_v2(dbname, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL)) { 611 if (sqlite3_open_v2(dbname, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL)) {
610 logmsg(LOG_ERROR, "sqlite3_open_v2: %s %s", sqlite3_errmsg(db), dbname); 612 logmsg(LOG_ERROR, "sqlite3_open_v2: %s %s", sqlite3_errmsg(db), dbname);
611 if (db) sqlite3_close(db); 613 if (db) sqlite3_close(db);
612 return 1; 614 return 1;
613 } 615 }
614 616
615 if (generateSQLite_packages(ct, db, i)) return 1; 617 if (generateSQLite_packages(ct, db, i)) return 1;
616 if (generateSQLite_provided(ct, db, i)) return 1; 618 if (generateSQLite_provided(ct, db, i)) return 1;
617 sqlite3_close(db); 619 sqlite3_close(db);
618 } 620 }
619 621
620 snprintf(dbname, PATH_MAX, "%s%s-sources.db", ct->repository_dir, ct->tag); 622 snprintf(dbname, PATH_MAX, "%s%s-sources.db", ct->repository_dir, ct->tag);
621 unlink(dbname); 623 unlink(dbname);
622 624
623 if (sqlite3_open_v2(dbname, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL)) { 625 if (sqlite3_open_v2(dbname, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL)) {
624 if (db) sqlite3_close(db); 626 if (db) sqlite3_close(db);
625 return 1; 627 return 1;
626 } 628 }
627 629
628 generateSQLite_sources(ct, db); 630 generateSQLite_sources(ct, db);
629 generateSQLite_packagers(db); 631 generateSQLite_packagers(db);
630 632
631 sqlite3_close(db); 633 sqlite3_close(db);
632 return 0; 634 return 0;
633 } 635 }