Fossil SCM

Pulled in another round of memory optimizations in cson/sqlite3. Added a few minor error reporting cleanups in JSON mode.

stephan 2011-10-07 10:59 json-multitag-test
Commit 09e5fcd795ce5fe6e7157e5982283ee7bd2ef9c5
--- src/cson_amalgamation.c
+++ src/cson_amalgamation.c
@@ -2680,24 +2680,24 @@
26802680
cson_double_t i = 0.0;
26812681
cson_value_fetch_double( val, &i );
26822682
return i;
26832683
}
26842684
2685
-int cson_value_fetch_string( cson_value const * val, cson_string const ** dest )
2685
+int cson_value_fetch_string( cson_value const * val, cson_string ** dest )
26862686
{
26872687
if( ! val || ! dest ) return cson_rc.ArgError;
26882688
else if( ! cson_value_is_string(val) ) return cson_rc.TypeError;
26892689
else
26902690
{
2691
- if( dest ) *dest = (cson_string const *)val->value;
2691
+ if( dest ) *dest = CSON_STR(val);
26922692
return 0;
26932693
}
26942694
}
26952695
2696
-cson_string const * cson_value_get_string( cson_value const * val )
2696
+cson_string * cson_value_get_string( cson_value const * val )
26972697
{
2698
- cson_string const * rc = NULL;
2698
+ cson_string * rc = NULL;
26992699
cson_value_fetch_string( val, &rc );
27002700
return rc;
27012701
}
27022702
27032703
char const * cson_value_get_cstr( cson_value const * val )
@@ -5145,13 +5145,62 @@
51455145
cson_value_free(aryV);
51465146
return NULL;
51475147
}
51485148
}
51495149
5150
+
5151
+cson_value * cson_sqlite3_row_to_object2( sqlite3_stmt * st,
5152
+ cson_array * colNames )
5153
+{
5154
+ cson_value * rootV = NULL;
5155
+ cson_object * root = NULL;
5156
+ cson_string * colName = NULL;
5157
+ int i = 0;
5158
+ int rc = 0;
5159
+ cson_value * currentValue = NULL;
5160
+ int const colCount = sqlite3_column_count(st);
5161
+ if( !colCount || (colCount>cson_array_length_get(colNames)) ) {
5162
+ return NULL;
5163
+ }
5164
+ rootV = cson_value_new_object();
5165
+ if(!rootV) return NULL;
5166
+ root = cson_value_get_object(rootV);
5167
+ for( i = 0; i < colCount; ++i )
5168
+ {
5169
+ colName = cson_value_get_string( cson_array_get( colNames, i ) );
5170
+ if( ! colName ) goto error;
5171
+ currentValue = cson_sqlite3_column_to_value(st,i);
5172
+ if( ! currentValue ) currentValue = cson_value_null();
5173
+ rc = cson_object_set_s( root, colName, currentValue );
5174
+ if( 0 != rc )
5175
+ {
5176
+ cson_value_free( currentValue );
5177
+ goto error;
5178
+ }
5179
+ }
5180
+ goto end;
5181
+ error:
5182
+ cson_value_free( rootV );
5183
+ rootV = NULL;
5184
+ end:
5185
+ return rootV;
5186
+}
5187
+
51505188
51515189
cson_value * cson_sqlite3_row_to_object( sqlite3_stmt * st )
51525190
{
5191
+#if 0
5192
+ cson_value * arV = cson_sqlite3_column_names(st);
5193
+ cson_array * ar = NULL;
5194
+ cson_value * rc = NULL;
5195
+ if(!arV) return NULL;
5196
+ ar = cson_value_get_array(arV);
5197
+ assert( NULL != ar );
5198
+ rc = cson_sqlite3_row_to_object2(st, ar);
5199
+ cson_value_free(arV);
5200
+ return rc;
5201
+#else
51535202
cson_value * rootV = NULL;
51545203
cson_object * root = NULL;
51555204
char const * colName = NULL;
51565205
int i = 0;
51575206
int rc = 0;
@@ -5178,10 +5227,11 @@
51785227
error:
51795228
cson_value_free( rootV );
51805229
rootV = NULL;
51815230
end:
51825231
return rootV;
5232
+#endif
51835233
}
51845234
51855235
cson_value * cson_sqlite3_row_to_array( sqlite3_stmt * st )
51865236
{
51875237
cson_value * aryV = NULL;
@@ -5226,10 +5276,11 @@
52265276
else
52275277
{
52285278
cson_value * rootV = NULL;
52295279
cson_object * root = NULL;
52305280
cson_value * colsV = NULL;
5281
+ cson_array * cols = NULL;
52315282
cson_value * rowsV = NULL;
52325283
cson_array * rows = NULL;
52335284
cson_value * objV = NULL;
52345285
int rc = 0;
52355286
int const colCount = sqlite3_column_count(st);
@@ -5240,18 +5291,19 @@
52405291
if( ! colsV )
52415292
{
52425293
cson_value_free( rootV );
52435294
RETURN(cson_rc.AllocError);
52445295
}
5296
+ cols = cson_value_get_array(colsV);
5297
+ assert(NULL != cols);
52455298
root = cson_value_get_object(rootV);
52465299
rc = cson_object_set( root, "columns", colsV );
52475300
if( rc )
52485301
{
52495302
cson_value_free( colsV );
52505303
RETURN(rc);
52515304
}
5252
- colsV = NULL;
52535305
rowsV = cson_value_new_array();
52545306
if( ! rowsV ) RETURN(cson_rc.AllocError);
52555307
rc = cson_object_set( root, "rows", rowsV );
52565308
if( rc )
52575309
{
@@ -5260,11 +5312,11 @@
52605312
}
52615313
rows = cson_value_get_array(rowsV);
52625314
assert(rows);
52635315
while( SQLITE_ROW == sqlite3_step(st) )
52645316
{
5265
- objV = cson_sqlite3_row_to_object(st);
5317
+ objV = cson_sqlite3_row_to_object2(st, cols);
52665318
if( ! objV ) RETURN(cson_rc.UnknownError);
52675319
rc = cson_array_append( rows, objV );
52685320
if( rc )
52695321
{
52705322
cson_value_free( objV );
52715323
--- src/cson_amalgamation.c
+++ src/cson_amalgamation.c
@@ -2680,24 +2680,24 @@
2680 cson_double_t i = 0.0;
2681 cson_value_fetch_double( val, &i );
2682 return i;
2683 }
2684
2685 int cson_value_fetch_string( cson_value const * val, cson_string const ** dest )
2686 {
2687 if( ! val || ! dest ) return cson_rc.ArgError;
2688 else if( ! cson_value_is_string(val) ) return cson_rc.TypeError;
2689 else
2690 {
2691 if( dest ) *dest = (cson_string const *)val->value;
2692 return 0;
2693 }
2694 }
2695
2696 cson_string const * cson_value_get_string( cson_value const * val )
2697 {
2698 cson_string const * rc = NULL;
2699 cson_value_fetch_string( val, &rc );
2700 return rc;
2701 }
2702
2703 char const * cson_value_get_cstr( cson_value const * val )
@@ -5145,13 +5145,62 @@
5145 cson_value_free(aryV);
5146 return NULL;
5147 }
5148 }
5149
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5150
5151 cson_value * cson_sqlite3_row_to_object( sqlite3_stmt * st )
5152 {
 
 
 
 
 
 
 
 
 
 
 
5153 cson_value * rootV = NULL;
5154 cson_object * root = NULL;
5155 char const * colName = NULL;
5156 int i = 0;
5157 int rc = 0;
@@ -5178,10 +5227,11 @@
5178 error:
5179 cson_value_free( rootV );
5180 rootV = NULL;
5181 end:
5182 return rootV;
 
5183 }
5184
5185 cson_value * cson_sqlite3_row_to_array( sqlite3_stmt * st )
5186 {
5187 cson_value * aryV = NULL;
@@ -5226,10 +5276,11 @@
5226 else
5227 {
5228 cson_value * rootV = NULL;
5229 cson_object * root = NULL;
5230 cson_value * colsV = NULL;
 
5231 cson_value * rowsV = NULL;
5232 cson_array * rows = NULL;
5233 cson_value * objV = NULL;
5234 int rc = 0;
5235 int const colCount = sqlite3_column_count(st);
@@ -5240,18 +5291,19 @@
5240 if( ! colsV )
5241 {
5242 cson_value_free( rootV );
5243 RETURN(cson_rc.AllocError);
5244 }
 
 
5245 root = cson_value_get_object(rootV);
5246 rc = cson_object_set( root, "columns", colsV );
5247 if( rc )
5248 {
5249 cson_value_free( colsV );
5250 RETURN(rc);
5251 }
5252 colsV = NULL;
5253 rowsV = cson_value_new_array();
5254 if( ! rowsV ) RETURN(cson_rc.AllocError);
5255 rc = cson_object_set( root, "rows", rowsV );
5256 if( rc )
5257 {
@@ -5260,11 +5312,11 @@
5260 }
5261 rows = cson_value_get_array(rowsV);
5262 assert(rows);
5263 while( SQLITE_ROW == sqlite3_step(st) )
5264 {
5265 objV = cson_sqlite3_row_to_object(st);
5266 if( ! objV ) RETURN(cson_rc.UnknownError);
5267 rc = cson_array_append( rows, objV );
5268 if( rc )
5269 {
5270 cson_value_free( objV );
5271
--- src/cson_amalgamation.c
+++ src/cson_amalgamation.c
@@ -2680,24 +2680,24 @@
2680 cson_double_t i = 0.0;
2681 cson_value_fetch_double( val, &i );
2682 return i;
2683 }
2684
2685 int cson_value_fetch_string( cson_value const * val, cson_string ** dest )
2686 {
2687 if( ! val || ! dest ) return cson_rc.ArgError;
2688 else if( ! cson_value_is_string(val) ) return cson_rc.TypeError;
2689 else
2690 {
2691 if( dest ) *dest = CSON_STR(val);
2692 return 0;
2693 }
2694 }
2695
2696 cson_string * cson_value_get_string( cson_value const * val )
2697 {
2698 cson_string * rc = NULL;
2699 cson_value_fetch_string( val, &rc );
2700 return rc;
2701 }
2702
2703 char const * cson_value_get_cstr( cson_value const * val )
@@ -5145,13 +5145,62 @@
5145 cson_value_free(aryV);
5146 return NULL;
5147 }
5148 }
5149
5150
5151 cson_value * cson_sqlite3_row_to_object2( sqlite3_stmt * st,
5152 cson_array * colNames )
5153 {
5154 cson_value * rootV = NULL;
5155 cson_object * root = NULL;
5156 cson_string * colName = NULL;
5157 int i = 0;
5158 int rc = 0;
5159 cson_value * currentValue = NULL;
5160 int const colCount = sqlite3_column_count(st);
5161 if( !colCount || (colCount>cson_array_length_get(colNames)) ) {
5162 return NULL;
5163 }
5164 rootV = cson_value_new_object();
5165 if(!rootV) return NULL;
5166 root = cson_value_get_object(rootV);
5167 for( i = 0; i < colCount; ++i )
5168 {
5169 colName = cson_value_get_string( cson_array_get( colNames, i ) );
5170 if( ! colName ) goto error;
5171 currentValue = cson_sqlite3_column_to_value(st,i);
5172 if( ! currentValue ) currentValue = cson_value_null();
5173 rc = cson_object_set_s( root, colName, currentValue );
5174 if( 0 != rc )
5175 {
5176 cson_value_free( currentValue );
5177 goto error;
5178 }
5179 }
5180 goto end;
5181 error:
5182 cson_value_free( rootV );
5183 rootV = NULL;
5184 end:
5185 return rootV;
5186 }
5187
5188
5189 cson_value * cson_sqlite3_row_to_object( sqlite3_stmt * st )
5190 {
5191 #if 0
5192 cson_value * arV = cson_sqlite3_column_names(st);
5193 cson_array * ar = NULL;
5194 cson_value * rc = NULL;
5195 if(!arV) return NULL;
5196 ar = cson_value_get_array(arV);
5197 assert( NULL != ar );
5198 rc = cson_sqlite3_row_to_object2(st, ar);
5199 cson_value_free(arV);
5200 return rc;
5201 #else
5202 cson_value * rootV = NULL;
5203 cson_object * root = NULL;
5204 char const * colName = NULL;
5205 int i = 0;
5206 int rc = 0;
@@ -5178,10 +5227,11 @@
5227 error:
5228 cson_value_free( rootV );
5229 rootV = NULL;
5230 end:
5231 return rootV;
5232 #endif
5233 }
5234
5235 cson_value * cson_sqlite3_row_to_array( sqlite3_stmt * st )
5236 {
5237 cson_value * aryV = NULL;
@@ -5226,10 +5276,11 @@
5276 else
5277 {
5278 cson_value * rootV = NULL;
5279 cson_object * root = NULL;
5280 cson_value * colsV = NULL;
5281 cson_array * cols = NULL;
5282 cson_value * rowsV = NULL;
5283 cson_array * rows = NULL;
5284 cson_value * objV = NULL;
5285 int rc = 0;
5286 int const colCount = sqlite3_column_count(st);
@@ -5240,18 +5291,19 @@
5291 if( ! colsV )
5292 {
5293 cson_value_free( rootV );
5294 RETURN(cson_rc.AllocError);
5295 }
5296 cols = cson_value_get_array(colsV);
5297 assert(NULL != cols);
5298 root = cson_value_get_object(rootV);
5299 rc = cson_object_set( root, "columns", colsV );
5300 if( rc )
5301 {
5302 cson_value_free( colsV );
5303 RETURN(rc);
5304 }
 
5305 rowsV = cson_value_new_array();
5306 if( ! rowsV ) RETURN(cson_rc.AllocError);
5307 rc = cson_object_set( root, "rows", rowsV );
5308 if( rc )
5309 {
@@ -5260,11 +5312,11 @@
5312 }
5313 rows = cson_value_get_array(rowsV);
5314 assert(rows);
5315 while( SQLITE_ROW == sqlite3_step(st) )
5316 {
5317 objV = cson_sqlite3_row_to_object2(st, cols);
5318 if( ! objV ) RETURN(cson_rc.UnknownError);
5319 rc = cson_array_append( rows, objV );
5320 if( rc )
5321 {
5322 cson_value_free( objV );
5323
--- src/cson_amalgamation.h
+++ src/cson_amalgamation.h
@@ -863,11 +863,11 @@
863863
864864
Note that this routine does not convert non-String values to their
865865
string representations. (Adding that ability would add more
866866
overhead to every cson_value instance.)
867867
*/
868
-int cson_value_fetch_string( cson_value const * val, cson_string const ** str );
868
+int cson_value_fetch_string( cson_value const * val, cson_string ** str );
869869
870870
/**
871871
If cson_value_is_object(val) then this function assigns *obj to the underlying
872872
object value and returns 0, otherwise non-0 is returned and *obj is not modified.
873873
@@ -920,11 +920,11 @@
920920
921921
/**
922922
Simplified form of cson_value_fetch_string(). Returns NULL if val
923923
is-not-a string value.
924924
*/
925
-cson_string const * cson_value_get_string( cson_value const * val );
925
+cson_string * cson_value_get_string( cson_value const * val );
926926
927927
/**
928928
Returns a pointer to the NULL-terminated string bytes of str.
929929
The bytes are owned by string and will be invalided when it
930930
is cleaned up.
@@ -2187,10 +2187,30 @@
21872187
cson_sqlite3_column_to_value() is used to convert each column to a
21882188
JSON value, and the column names are taken from
21892189
sqlite3_column_name().
21902190
*/
21912191
cson_value * cson_sqlite3_row_to_object( sqlite3_stmt * st );
2192
+/**
2193
+ Functionally almost identical to cson_sqlite3_row_to_object(), the
2194
+ only difference being how the result objects gets its column names.
2195
+ st must be a freshly-step()'d handle holding a result row.
2196
+ colNames must be an Array with at least the same number of columns
2197
+ as st. If it has fewer, NULL is returned and this function has
2198
+ no side-effects.
2199
+
2200
+ For each column in the result set, the colNames entry at the same
2201
+ index is used for the column key. If a given entry is-not-a String
2202
+ then conversion will fail and NULL will be returned.
2203
+
2204
+ The one reason to prefer this over cson_sqlite3_row_to_object() is
2205
+ that this one can share the keys across multiple rows (or even
2206
+ other JSON containers), whereas the former makes fresh copies of
2207
+ the column names for each row.
2208
+
2209
+*/
2210
+cson_value * cson_sqlite3_row_to_object2( sqlite3_stmt * st,
2211
+ cson_array * colNames );
21922212
21932213
/**
21942214
Similar to cson_sqlite3_row_to_object(), but creates an Array
21952215
value which contains the JSON-form values of the given result
21962216
set row.
21972217
--- src/cson_amalgamation.h
+++ src/cson_amalgamation.h
@@ -863,11 +863,11 @@
863
864 Note that this routine does not convert non-String values to their
865 string representations. (Adding that ability would add more
866 overhead to every cson_value instance.)
867 */
868 int cson_value_fetch_string( cson_value const * val, cson_string const ** str );
869
870 /**
871 If cson_value_is_object(val) then this function assigns *obj to the underlying
872 object value and returns 0, otherwise non-0 is returned and *obj is not modified.
873
@@ -920,11 +920,11 @@
920
921 /**
922 Simplified form of cson_value_fetch_string(). Returns NULL if val
923 is-not-a string value.
924 */
925 cson_string const * cson_value_get_string( cson_value const * val );
926
927 /**
928 Returns a pointer to the NULL-terminated string bytes of str.
929 The bytes are owned by string and will be invalided when it
930 is cleaned up.
@@ -2187,10 +2187,30 @@
2187 cson_sqlite3_column_to_value() is used to convert each column to a
2188 JSON value, and the column names are taken from
2189 sqlite3_column_name().
2190 */
2191 cson_value * cson_sqlite3_row_to_object( sqlite3_stmt * st );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2192
2193 /**
2194 Similar to cson_sqlite3_row_to_object(), but creates an Array
2195 value which contains the JSON-form values of the given result
2196 set row.
2197
--- src/cson_amalgamation.h
+++ src/cson_amalgamation.h
@@ -863,11 +863,11 @@
863
864 Note that this routine does not convert non-String values to their
865 string representations. (Adding that ability would add more
866 overhead to every cson_value instance.)
867 */
868 int cson_value_fetch_string( cson_value const * val, cson_string ** str );
869
870 /**
871 If cson_value_is_object(val) then this function assigns *obj to the underlying
872 object value and returns 0, otherwise non-0 is returned and *obj is not modified.
873
@@ -920,11 +920,11 @@
920
921 /**
922 Simplified form of cson_value_fetch_string(). Returns NULL if val
923 is-not-a string value.
924 */
925 cson_string * cson_value_get_string( cson_value const * val );
926
927 /**
928 Returns a pointer to the NULL-terminated string bytes of str.
929 The bytes are owned by string and will be invalided when it
930 is cleaned up.
@@ -2187,10 +2187,30 @@
2187 cson_sqlite3_column_to_value() is used to convert each column to a
2188 JSON value, and the column names are taken from
2189 sqlite3_column_name().
2190 */
2191 cson_value * cson_sqlite3_row_to_object( sqlite3_stmt * st );
2192 /**
2193 Functionally almost identical to cson_sqlite3_row_to_object(), the
2194 only difference being how the result objects gets its column names.
2195 st must be a freshly-step()'d handle holding a result row.
2196 colNames must be an Array with at least the same number of columns
2197 as st. If it has fewer, NULL is returned and this function has
2198 no side-effects.
2199
2200 For each column in the result set, the colNames entry at the same
2201 index is used for the column key. If a given entry is-not-a String
2202 then conversion will fail and NULL will be returned.
2203
2204 The one reason to prefer this over cson_sqlite3_row_to_object() is
2205 that this one can share the keys across multiple rows (or even
2206 other JSON containers), whereas the former makes fresh copies of
2207 the column names for each row.
2208
2209 */
2210 cson_value * cson_sqlite3_row_to_object2( sqlite3_stmt * st,
2211 cson_array * colNames );
2212
2213 /**
2214 Similar to cson_sqlite3_row_to_object(), but creates an Array
2215 value which contains the JSON-form values of the given result
2216 set row.
2217
+5 -1
--- src/db.c
+++ src/db.c
@@ -880,15 +880,18 @@
880880
db_err("unable to find the name of a repository database");
881881
}
882882
}
883883
if( file_access(zDbName, R_OK) || file_size(zDbName)<1024 ){
884884
if( file_access(zDbName, 0) ){
885
+ g.json.resultCode = FSL_JSON_E_DB_NOT_FOUND;
885886
fossil_panic("repository does not exist or"
886887
" is in an unreadable directory: %s", zDbName);
887888
}else if( file_access(zDbName, R_OK) ){
889
+ g.json.resultCode = FSL_JSON_E_DENIED;
888890
fossil_panic("read permission denied for repository %s", zDbName);
889891
}else{
892
+ g.json.resultCode = FSL_JSON_E_DB_NOT_VALID;
890893
fossil_panic("not a valid repository: %s", zDbName);
891894
}
892895
}
893896
db_open_or_attach(zDbName, "repository");
894897
g.repositoryOpen = 1;
@@ -919,11 +922,11 @@
919922
}
920923
if( zRep==0 ){
921924
if( db_open_local()==0 ){
922925
goto rep_not_found;
923926
}
924
- zRep = db_lget("repository", 0);
927
+ zRep = db_lget("repository", 0)/*leak here*/;
925928
if( zRep==0 ){
926929
goto rep_not_found;
927930
}
928931
}
929932
db_open_repository(zRep);
@@ -931,10 +934,11 @@
931934
if( (bFlags & OPEN_ANY_SCHEMA)==0 ) db_verify_schema();
932935
return;
933936
}
934937
rep_not_found:
935938
if( (bFlags & OPEN_OK_NOT_FOUND)==0 ){
939
+ g.json.resultCode = FSL_JSON_E_DB_NOT_FOUND;
936940
fossil_fatal("use --repository or -R to specify the repository database");
937941
}
938942
}
939943
940944
/*
941945
--- src/db.c
+++ src/db.c
@@ -880,15 +880,18 @@
880 db_err("unable to find the name of a repository database");
881 }
882 }
883 if( file_access(zDbName, R_OK) || file_size(zDbName)<1024 ){
884 if( file_access(zDbName, 0) ){
 
885 fossil_panic("repository does not exist or"
886 " is in an unreadable directory: %s", zDbName);
887 }else if( file_access(zDbName, R_OK) ){
 
888 fossil_panic("read permission denied for repository %s", zDbName);
889 }else{
 
890 fossil_panic("not a valid repository: %s", zDbName);
891 }
892 }
893 db_open_or_attach(zDbName, "repository");
894 g.repositoryOpen = 1;
@@ -919,11 +922,11 @@
919 }
920 if( zRep==0 ){
921 if( db_open_local()==0 ){
922 goto rep_not_found;
923 }
924 zRep = db_lget("repository", 0);
925 if( zRep==0 ){
926 goto rep_not_found;
927 }
928 }
929 db_open_repository(zRep);
@@ -931,10 +934,11 @@
931 if( (bFlags & OPEN_ANY_SCHEMA)==0 ) db_verify_schema();
932 return;
933 }
934 rep_not_found:
935 if( (bFlags & OPEN_OK_NOT_FOUND)==0 ){
 
936 fossil_fatal("use --repository or -R to specify the repository database");
937 }
938 }
939
940 /*
941
--- src/db.c
+++ src/db.c
@@ -880,15 +880,18 @@
880 db_err("unable to find the name of a repository database");
881 }
882 }
883 if( file_access(zDbName, R_OK) || file_size(zDbName)<1024 ){
884 if( file_access(zDbName, 0) ){
885 g.json.resultCode = FSL_JSON_E_DB_NOT_FOUND;
886 fossil_panic("repository does not exist or"
887 " is in an unreadable directory: %s", zDbName);
888 }else if( file_access(zDbName, R_OK) ){
889 g.json.resultCode = FSL_JSON_E_DENIED;
890 fossil_panic("read permission denied for repository %s", zDbName);
891 }else{
892 g.json.resultCode = FSL_JSON_E_DB_NOT_VALID;
893 fossil_panic("not a valid repository: %s", zDbName);
894 }
895 }
896 db_open_or_attach(zDbName, "repository");
897 g.repositoryOpen = 1;
@@ -919,11 +922,11 @@
922 }
923 if( zRep==0 ){
924 if( db_open_local()==0 ){
925 goto rep_not_found;
926 }
927 zRep = db_lget("repository", 0)/*leak here*/;
928 if( zRep==0 ){
929 goto rep_not_found;
930 }
931 }
932 db_open_repository(zRep);
@@ -931,10 +934,11 @@
934 if( (bFlags & OPEN_ANY_SCHEMA)==0 ) db_verify_schema();
935 return;
936 }
937 rep_not_found:
938 if( (bFlags & OPEN_OK_NOT_FOUND)==0 ){
939 g.json.resultCode = FSL_JSON_E_DB_NOT_FOUND;
940 fossil_fatal("use --repository or -R to specify the repository database");
941 }
942 }
943
944 /*
945
+16 -4
--- src/json.c
+++ src/json.c
@@ -259,10 +259,12 @@
259259
C(STMT_PREP,"Statement preparation failed");
260260
C(STMT_BIND,"Statement parameter binding failed");
261261
C(STMT_EXEC,"Statement execution/stepping failed");
262262
C(DB_LOCKED,"Database is locked");
263263
C(DB_NEEDS_REBUILD,"Fossil repository needs to be rebuilt");
264
+ C(DB_NOT_FOUND,"Fossil repository db file could not be found.");
265
+ C(DB_NOT_VALID, "Fossil repository db file is not valid.");
264266
#undef C
265267
default:
266268
return "Unknown Error";
267269
}
268270
}
@@ -1602,20 +1604,28 @@
16021604
cson_value * json_page_resultCodes(){
16031605
cson_value * listV = cson_value_new_array();
16041606
cson_array * list = cson_value_get_array(listV);
16051607
cson_value * objV = NULL;
16061608
cson_object * obj = NULL;
1609
+ cson_string * kRC;
1610
+ cson_string * kSymbol;
1611
+ cson_string * kNumber;
1612
+ cson_string * kDesc;
16071613
int rc = cson_array_reserve( list, 35 );
16081614
if(rc){
16091615
assert( 0 && "Allocation error.");
16101616
exit(1);
16111617
}
1618
+ kRC = cson_new_string("resultCode",10);
1619
+ kSymbol = cson_new_string("cSymbol",7);
1620
+ kNumber = cson_new_string("number",6);
1621
+ kDesc = cson_new_string("description",11);
16121622
#define C(K) objV = cson_value_new_object(); obj = cson_value_get_object(objV); \
1613
- cson_object_set(obj, "resultCode", json_new_string(json_rc_cstr(FSL_JSON_E_##K)) ); \
1614
- cson_object_set(obj, "cSymbol", json_new_string("FSL_JSON_E_"#K) ); \
1615
- cson_object_set(obj, "number", cson_value_new_integer(FSL_JSON_E_##K) ); \
1616
- cson_object_set(obj, "description", json_new_string(json_err_cstr(FSL_JSON_E_##K))); \
1623
+ cson_object_set_s(obj, kRC, json_new_string(json_rc_cstr(FSL_JSON_E_##K)) ); \
1624
+ cson_object_set_s(obj, kSymbol, json_new_string("FSL_JSON_E_"#K) ); \
1625
+ cson_object_set_s(obj, kNumber, cson_value_new_integer(FSL_JSON_E_##K) ); \
1626
+ cson_object_set_s(obj, kDesc, json_new_string(json_err_cstr(FSL_JSON_E_##K))); \
16171627
cson_array_append( list, objV ); obj = NULL; objV = NULL
16181628
16191629
C(GENERIC);
16201630
C(INVALID_REQUEST);
16211631
C(UNKNOWN_COMMAND);
@@ -1650,10 +1660,12 @@
16501660
C(STMT_PREP);
16511661
C(STMT_BIND);
16521662
C(STMT_EXEC);
16531663
C(DB_LOCKED);
16541664
C(DB_NEEDS_REBUILD);
1665
+ C(DB_NOT_FOUND);
1666
+ C(DB_NOT_VALID);
16551667
#undef C
16561668
return listV;
16571669
}
16581670
16591671
16601672
--- src/json.c
+++ src/json.c
@@ -259,10 +259,12 @@
259 C(STMT_PREP,"Statement preparation failed");
260 C(STMT_BIND,"Statement parameter binding failed");
261 C(STMT_EXEC,"Statement execution/stepping failed");
262 C(DB_LOCKED,"Database is locked");
263 C(DB_NEEDS_REBUILD,"Fossil repository needs to be rebuilt");
 
 
264 #undef C
265 default:
266 return "Unknown Error";
267 }
268 }
@@ -1602,20 +1604,28 @@
1602 cson_value * json_page_resultCodes(){
1603 cson_value * listV = cson_value_new_array();
1604 cson_array * list = cson_value_get_array(listV);
1605 cson_value * objV = NULL;
1606 cson_object * obj = NULL;
 
 
 
 
1607 int rc = cson_array_reserve( list, 35 );
1608 if(rc){
1609 assert( 0 && "Allocation error.");
1610 exit(1);
1611 }
 
 
 
 
1612 #define C(K) objV = cson_value_new_object(); obj = cson_value_get_object(objV); \
1613 cson_object_set(obj, "resultCode", json_new_string(json_rc_cstr(FSL_JSON_E_##K)) ); \
1614 cson_object_set(obj, "cSymbol", json_new_string("FSL_JSON_E_"#K) ); \
1615 cson_object_set(obj, "number", cson_value_new_integer(FSL_JSON_E_##K) ); \
1616 cson_object_set(obj, "description", json_new_string(json_err_cstr(FSL_JSON_E_##K))); \
1617 cson_array_append( list, objV ); obj = NULL; objV = NULL
1618
1619 C(GENERIC);
1620 C(INVALID_REQUEST);
1621 C(UNKNOWN_COMMAND);
@@ -1650,10 +1660,12 @@
1650 C(STMT_PREP);
1651 C(STMT_BIND);
1652 C(STMT_EXEC);
1653 C(DB_LOCKED);
1654 C(DB_NEEDS_REBUILD);
 
 
1655 #undef C
1656 return listV;
1657 }
1658
1659
1660
--- src/json.c
+++ src/json.c
@@ -259,10 +259,12 @@
259 C(STMT_PREP,"Statement preparation failed");
260 C(STMT_BIND,"Statement parameter binding failed");
261 C(STMT_EXEC,"Statement execution/stepping failed");
262 C(DB_LOCKED,"Database is locked");
263 C(DB_NEEDS_REBUILD,"Fossil repository needs to be rebuilt");
264 C(DB_NOT_FOUND,"Fossil repository db file could not be found.");
265 C(DB_NOT_VALID, "Fossil repository db file is not valid.");
266 #undef C
267 default:
268 return "Unknown Error";
269 }
270 }
@@ -1602,20 +1604,28 @@
1604 cson_value * json_page_resultCodes(){
1605 cson_value * listV = cson_value_new_array();
1606 cson_array * list = cson_value_get_array(listV);
1607 cson_value * objV = NULL;
1608 cson_object * obj = NULL;
1609 cson_string * kRC;
1610 cson_string * kSymbol;
1611 cson_string * kNumber;
1612 cson_string * kDesc;
1613 int rc = cson_array_reserve( list, 35 );
1614 if(rc){
1615 assert( 0 && "Allocation error.");
1616 exit(1);
1617 }
1618 kRC = cson_new_string("resultCode",10);
1619 kSymbol = cson_new_string("cSymbol",7);
1620 kNumber = cson_new_string("number",6);
1621 kDesc = cson_new_string("description",11);
1622 #define C(K) objV = cson_value_new_object(); obj = cson_value_get_object(objV); \
1623 cson_object_set_s(obj, kRC, json_new_string(json_rc_cstr(FSL_JSON_E_##K)) ); \
1624 cson_object_set_s(obj, kSymbol, json_new_string("FSL_JSON_E_"#K) ); \
1625 cson_object_set_s(obj, kNumber, cson_value_new_integer(FSL_JSON_E_##K) ); \
1626 cson_object_set_s(obj, kDesc, json_new_string(json_err_cstr(FSL_JSON_E_##K))); \
1627 cson_array_append( list, objV ); obj = NULL; objV = NULL
1628
1629 C(GENERIC);
1630 C(INVALID_REQUEST);
1631 C(UNKNOWN_COMMAND);
@@ -1650,10 +1660,12 @@
1660 C(STMT_PREP);
1661 C(STMT_BIND);
1662 C(STMT_EXEC);
1663 C(DB_LOCKED);
1664 C(DB_NEEDS_REBUILD);
1665 C(DB_NOT_FOUND);
1666 C(DB_NOT_VALID);
1667 #undef C
1668 return listV;
1669 }
1670
1671
1672
--- src/json_detail.h
+++ src/json_detail.h
@@ -82,11 +82,13 @@
8282
FSL_JSON_E_STMT_PREP /*+1*/,
8383
FSL_JSON_E_STMT_BIND /*+2*/,
8484
FSL_JSON_E_STMT_EXEC /*+3*/,
8585
FSL_JSON_E_DB_LOCKED /*+4*/,
8686
87
-FSL_JSON_E_DB_NEEDS_REBUILD = FSL_JSON_E_DB + 101
87
+FSL_JSON_E_DB_NEEDS_REBUILD = FSL_JSON_E_DB + 101,
88
+FSL_JSON_E_DB_NOT_FOUND = FSL_JSON_E_DB + 102,
89
+FSL_JSON_E_DB_NOT_VALID = FSL_JSON_E_DB + 103
8890
8991
};
9092
9193
9294
/*
9395
--- src/json_detail.h
+++ src/json_detail.h
@@ -82,11 +82,13 @@
82 FSL_JSON_E_STMT_PREP /*+1*/,
83 FSL_JSON_E_STMT_BIND /*+2*/,
84 FSL_JSON_E_STMT_EXEC /*+3*/,
85 FSL_JSON_E_DB_LOCKED /*+4*/,
86
87 FSL_JSON_E_DB_NEEDS_REBUILD = FSL_JSON_E_DB + 101
 
 
88
89 };
90
91
92 /*
93
--- src/json_detail.h
+++ src/json_detail.h
@@ -82,11 +82,13 @@
82 FSL_JSON_E_STMT_PREP /*+1*/,
83 FSL_JSON_E_STMT_BIND /*+2*/,
84 FSL_JSON_E_STMT_EXEC /*+3*/,
85 FSL_JSON_E_DB_LOCKED /*+4*/,
86
87 FSL_JSON_E_DB_NEEDS_REBUILD = FSL_JSON_E_DB + 101,
88 FSL_JSON_E_DB_NOT_FOUND = FSL_JSON_E_DB + 102,
89 FSL_JSON_E_DB_NOT_VALID = FSL_JSON_E_DB + 103
90
91 };
92
93
94 /*
95

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button