Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Changes In Branch sqlite4 Excluding Merge-Ins
This is equivalent to a diff from 01e4de6b to 0328d681
2012-06-29
| ||
19:35 | Remove redundant include argument from the compilation steps of several source files. ... (check-in: 8a18e7fb user: mistachkin tags: trunk) | |
15:59 | Update to the latest SQLite4 that requires converting preprocessor macro prefixes from "SQLITE_" to "SQLITE4_". ... (Closed-Leaf check-in: 0328d681 user: drh tags: sqlite4) | |
15:47 | Merge in the trunk changes. ... (check-in: 0315f3f0 user: drh tags: sqlite4) | |
12:48 | Fix the manifest generator for check-ins so that when a partial commit is done and some of the uncommitted files have been renamed, the rows of the check-in manifest are ordered by the original, unchanged names of the uncommitted renamed files. ... (check-in: 01e4de6b user: drh tags: trunk) | |
11:05 | Update the test-parse-manifest test command so that it reports parse failures on standard output. ... (check-in: 4113f588 user: drh tags: trunk) | |
Changes to src/Makefile.
1 2 | all clean: $(MAKE) -C .. $(MAKECMDGOALS) | < | 1 2 | all clean: $(MAKE) -C .. $(MAKECMDGOALS) |
Changes to src/add.c.
︙ | ︙ | |||
163 164 165 166 167 168 169 | xCmp = fossil_stricmp; db_multi_exec( "CREATE INDEX IF NOT EXISTS vfile_nocase" " ON vfile(pathname COLLATE nocase)" ); } db_prepare(&loop, "SELECT x FROM sfile ORDER BY x"); | | | 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | xCmp = fossil_stricmp; db_multi_exec( "CREATE INDEX IF NOT EXISTS vfile_nocase" " ON vfile(pathname COLLATE nocase)" ); } db_prepare(&loop, "SELECT x FROM sfile ORDER BY x"); while( db_step(&loop)==SQLITE4_ROW ){ const char *zToAdd = db_column_text(&loop, 0); if( fossil_strcmp(zToAdd, zRepo)==0 ) continue; for(i=0; (zReserved = fossil_reserved_name(i))!=0; i++){ if( xCmp(zToAdd, zReserved)==0 ) break; } if( zReserved ) continue; nAdd += add_one_file(zToAdd, vid, caseSensitive); |
︙ | ︙ | |||
313 314 315 316 317 318 319 | " AND NOT deleted", zTreeName, zTreeName, zTreeName ); blob_reset(&treeName); } db_prepare(&loop, "SELECT x FROM sfile"); | | | 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | " AND NOT deleted", zTreeName, zTreeName, zTreeName ); blob_reset(&treeName); } db_prepare(&loop, "SELECT x FROM sfile"); while( db_step(&loop)==SQLITE4_ROW ){ fossil_print("DELETED %s\n", db_column_text(&loop, 0)); } db_finalize(&loop); db_multi_exec( "UPDATE vfile SET deleted=1 WHERE pathname IN sfile;" "DELETE FROM vfile WHERE rid=0 AND deleted;" ); |
︙ | ︙ | |||
475 476 477 478 479 480 481 | /* step 2: search for missing files */ db_prepare(&q, "SELECT pathname, %Q || pathname, deleted FROM vfile" " WHERE NOT deleted" " ORDER BY 1", g.zLocalRoot ); | | | 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 | /* step 2: search for missing files */ db_prepare(&q, "SELECT pathname, %Q || pathname, deleted FROM vfile" " WHERE NOT deleted" " ORDER BY 1", g.zLocalRoot ); while( db_step(&q)==SQLITE4_ROW ){ const char * zFile; const char * zPath; zFile = db_column_text(&q, 0); zPath = db_column_text(&q, 1); if( !file_wd_isfile_or_link(zPath) ){ if( !isTest ){ |
︙ | ︙ | |||
579 580 581 582 583 584 585 | db_prepare(&q, "SELECT pathname FROM vfile" " WHERE vid=%d" " AND (pathname='%q' OR (pathname>'%q/' AND pathname<'%q0'))" " ORDER BY 1", vid, zOrig, zOrig, zOrig ); | | | | 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 | db_prepare(&q, "SELECT pathname FROM vfile" " WHERE vid=%d" " AND (pathname='%q' OR (pathname>'%q/' AND pathname<'%q0'))" " ORDER BY 1", vid, zOrig, zOrig, zOrig ); while( db_step(&q)==SQLITE4_ROW ){ const char *zPath = db_column_text(&q, 0); int nPath = db_column_bytes(&q, 0); const char *zTail; if( nPath==nOrig ){ zTail = file_tail(zPath); }else{ zTail = &zPath[nOrig+1]; } db_multi_exec( "INSERT INTO mv VALUES('%s','%s%s')", zPath, blob_str(&dest), zTail ); } db_finalize(&q); } } db_prepare(&q, "SELECT f, t FROM mv ORDER BY f"); while( db_step(&q)==SQLITE4_ROW ){ const char *zFrom = db_column_text(&q, 0); const char *zTo = db_column_text(&q, 1); mv_one_file(vid, zFrom, zTo); } db_finalize(&q); db_end_transaction(0); } |
Changes to src/allrepo.c.
︙ | ︙ | |||
162 163 164 165 166 167 168 | "SELECT substr(name, 6) COLLATE nocase, max(rowid)" " FROM global_config" " WHERE substr(name, 1, 5)=='repo:'" " GROUP BY 1 ORDER BY 1" ); } bag_init(&outOfDate); | | | 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | "SELECT substr(name, 6) COLLATE nocase, max(rowid)" " FROM global_config" " WHERE substr(name, 1, 5)=='repo:'" " GROUP BY 1 ORDER BY 1" ); } bag_init(&outOfDate); while( db_step(&q)==SQLITE4_ROW ){ const char *zFilename = db_column_text(&q, 0); int rowid = db_column_int(&q, 1); if( file_access(zFilename, 0) || !file_is_canonical(zFilename) ){ bag_insert(&outOfDate, rowid); continue; } if( useCheckouts && file_isdir(zFilename)!=1 ){ |
︙ | ︙ |
Changes to src/attach.c.
︙ | ︙ | |||
57 58 59 60 61 62 63 | blob_appendf(&sql, " WHERE target GLOB '%q*'", zTkt); }else{ if( g.perm.RdTkt==0 && g.perm.RdWiki==0 ) login_needed(); style_header("All Attachments"); } blob_appendf(&sql, " ORDER BY mtime DESC"); db_prepare(&q, "%s", blob_str(&sql)); | | | 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | blob_appendf(&sql, " WHERE target GLOB '%q*'", zTkt); }else{ if( g.perm.RdTkt==0 && g.perm.RdWiki==0 ) login_needed(); style_header("All Attachments"); } blob_appendf(&sql, " ORDER BY mtime DESC"); db_prepare(&q, "%s", blob_str(&sql)); while( db_step(&q)==SQLITE4_ROW ){ const char *zDate = db_column_text(&q, 0); const char *zSrc = db_column_text(&q, 1); const char *zTarget = db_column_text(&q, 2); const char *zFilename = db_column_text(&q, 3); const char *zComment = db_column_text(&q, 4); const char *zUser = db_column_text(&q, 5); int i; |
︙ | ︙ |
Changes to src/bisect.c.
︙ | ︙ | |||
226 227 228 229 230 231 232 | " datetime(event.mtime) FROM blob, event" " WHERE blob.rid=:rid AND event.objid=:rid" " AND event.type='ci'"); nStep = path_length(); for(p=path_last(), n=0; p; p=p->pFrom, n++){ const char *z; db_bind_int(&s, ":rid", p->rid); | | | 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | " datetime(event.mtime) FROM blob, event" " WHERE blob.rid=:rid AND event.objid=:rid" " AND event.type='ci'"); nStep = path_length(); for(p=path_last(), n=0; p; p=p->pFrom, n++){ const char *z; db_bind_int(&s, ":rid", p->rid); if( db_step(&s)==SQLITE4_ROW ){ z = db_column_text(&s, 0); fossil_print("%s", z); if( p->rid==bisect.good ) fossil_print(" GOOD"); if( p->rid==bisect.bad ) fossil_print(" BAD"); if( p->rid==vid ) fossil_print(" CURRENT"); if( nStep>1 && n==nStep/2 ) fossil_print(" NEXT"); fossil_print("\n"); |
︙ | ︙ |
Changes to src/branch.c.
︙ | ︙ | |||
125 126 127 128 129 130 131 | /* Cancel all other symbolic tags */ db_prepare(&q, "SELECT tagname FROM tagxref, tag" " WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid" " AND tagtype>0 AND tagname GLOB 'sym-*'" " ORDER BY tagname", rootid); | | | 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | /* Cancel all other symbolic tags */ db_prepare(&q, "SELECT tagname FROM tagxref, tag" " WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid" " AND tagtype>0 AND tagname GLOB 'sym-*'" " ORDER BY tagname", rootid); while( db_step(&q)==SQLITE4_ROW ){ const char *zTag = db_column_text(&q, 0); blob_appendf(&branch, "T -%F *\n", zTag); } db_finalize(&q); blob_appendf(&branch, "U %F\n", zUserOvrd ? zUserOvrd : g.zLogin); md5sum_blob(&branch, &mcksum); |
︙ | ︙ | |||
267 268 269 270 271 272 273 | if( g.localOpen ){ vid = db_lget_int("checkout", 0); zCurrent = db_text(0, "SELECT value FROM tagxref" " WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH); } branch_prepare_list_query(&q, showAll?1:(showClosed?-1:0)); | | | 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | if( g.localOpen ){ vid = db_lget_int("checkout", 0); zCurrent = db_text(0, "SELECT value FROM tagxref" " WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH); } branch_prepare_list_query(&q, showAll?1:(showClosed?-1:0)); while( db_step(&q)==SQLITE4_ROW ){ const char *zBr = db_column_text(&q, 0); int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0; fossil_print("%s%s\n", (isCur ? "* " : " "), zBr); } db_finalize(&q); }else{ fossil_panic("branch subcommand should be one of: " |
︙ | ︙ | |||
335 336 337 338 339 340 341 | @ Closed branches are fixed and do not change (unless they are first @ reopened)</li> @ </ol> style_sidebox_end(); branch_prepare_list_query(&q, showAll?1:(showClosed?-1:0)); cnt = 0; | | | 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | @ Closed branches are fixed and do not change (unless they are first @ reopened)</li> @ </ol> style_sidebox_end(); branch_prepare_list_query(&q, showAll?1:(showClosed?-1:0)); cnt = 0; while( db_step(&q)==SQLITE4_ROW ){ const char *zBr = db_column_text(&q, 0); if( cnt==0 ){ if( colorTest ){ @ <h2>Default background colors for all branches:</h2> }else if( showAll ){ @ <h2>All Branches:</h2> }else if( showClosed ){ |
︙ | ︙ | |||
387 388 389 390 391 392 393 | "SELECT substr(tagname,5) FROM tagxref, tag" " WHERE tagxref.rid=%d" " AND tagxref.tagid=tag.tagid" " AND tagxref.tagtype>0" " AND tag.tagname GLOB 'sym-*'", rid ); | | | 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | "SELECT substr(tagname,5) FROM tagxref, tag" " WHERE tagxref.rid=%d" " AND tagxref.tagid=tag.tagid" " AND tagxref.tagtype>0" " AND tag.tagname GLOB 'sym-*'", rid ); while( db_step(&q)==SQLITE4_ROW ){ const char *zTagName = db_column_text(&q, 0); @ %z(href("%R/timeline?r=%T",zTagName))[timeline]</a> } db_finalize(&q); } /* |
︙ | ︙ |
Changes to src/browse.c.
︙ | ︙ | |||
33 34 35 36 37 38 39 | ** Examples: ** ** pathelement('abc/pqr/xyz', 4) -> '/pqr' ** pathelement('abc/pqr', 4) -> 'pqr' ** pathelement('abc/pqr/xyz', 0) -> '/abc' */ void pathelementFunc( | | | | | | | | | | 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | ** Examples: ** ** pathelement('abc/pqr/xyz', 4) -> '/pqr' ** pathelement('abc/pqr', 4) -> 'pqr' ** pathelement('abc/pqr/xyz', 0) -> '/abc' */ void pathelementFunc( sqlite4_context *context, int argc, sqlite4_value **argv ){ const unsigned char *z; int len, n, i; char *zOut; assert( argc==2 ); z = sqlite4_value_text(argv[0]); if( z==0 ) return; len = sqlite4_value_bytes(argv[0]); n = sqlite4_value_int(argv[1]); if( len<=n ) return; if( n>0 && z[n-1]!='/' ) return; for(i=n; i<len && z[i]!='/'; i++){} if( i==len ){ sqlite4_result_text(context, (char*)&z[n], len-n, SQLITE4_TRANSIENT); }else{ zOut = sqlite4_mprintf(0, "/%.*s", i-n, &z[n]); sqlite4_result_text(context, zOut, i-n+1, SQLITE4_DYNAMIC); } } /* ** Given a pathname which is a relative path from the root of ** the repository to a file or directory, compute a string which ** is an HTML rendering of that path with hyperlinks on each |
︙ | ︙ | |||
121 122 123 124 125 126 127 | Manifest *pM = 0; const char *zSubdirLink; login_check_credentials(); if( !g.perm.Hyperlink ){ login_needed(); return; } while( nD>1 && zD[nD-2]=='/' ){ zD[(--nD)-1] = 0; } style_header("File List"); | | | 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | Manifest *pM = 0; const char *zSubdirLink; login_check_credentials(); if( !g.perm.Hyperlink ){ login_needed(); return; } while( nD>1 && zD[nD-2]=='/' ){ zD[(--nD)-1] = 0; } style_header("File List"); sqlite4_create_function(g.db, "pathelement", 2, SQLITE4_UTF8, 0, pathelementFunc, 0, 0); /* If the name= parameter is an empty string, make it a NULL pointer */ if( zD && strlen(zD)==0 ){ zD = 0; } /* If a specific check-in is requested, fetch and parse it. If the ** specific check-in does not exist, clear zCI. zCI==0 will cause all |
︙ | ︙ | |||
267 268 269 270 271 272 273 | nCol = 100/mxLen; if( nCol<1 ) nCol = 1; if( nCol>5 ) nCol = 5; nRow = (cnt+nCol-1)/nCol; db_prepare(&q, "SELECT x, u FROM localfiles ORDER BY x /*scan*/"); @ <table class="browser"><tr><td class="browser"><ul class="browser"> i = 0; | | | 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | nCol = 100/mxLen; if( nCol<1 ) nCol = 1; if( nCol>5 ) nCol = 5; nRow = (cnt+nCol-1)/nCol; db_prepare(&q, "SELECT x, u FROM localfiles ORDER BY x /*scan*/"); @ <table class="browser"><tr><td class="browser"><ul class="browser"> i = 0; while( db_step(&q)==SQLITE4_ROW ){ const char *zFN; if( i==nRow ){ @ </ul></td><td class="browser"><ul class="browser"> i = 0; } i++; zFN = db_column_text(&q, 0); |
︙ | ︙ |
Changes to src/captcha.c.
︙ | ︙ | |||
388 389 390 391 392 393 394 | int i; unsigned int v; char *z; for(i=2; i<g.argc; i++){ char zHex[30]; v = (unsigned int)atoi(g.argv[i]); | | | | 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | int i; unsigned int v; char *z; for(i=2; i<g.argc; i++){ char zHex[30]; v = (unsigned int)atoi(g.argv[i]); sqlite4_snprintf(zHex, sizeof(zHex), "%x", v); z = captcha_render(zHex); fossil_print("%s:\n%s", zHex, z); free(z); } } /* ** Compute a seed value for a captcha. The seed is public and is sent ** as a hidden parameter with the page that contains the captcha. Knowledge ** of the seed is insufficient for determining the captcha without additional ** information held only on the server and never revealed. */ unsigned int captcha_seed(void){ unsigned int x; sqlite4_randomness(0, sizeof(x), &x); x &= 0x7fffffff; return x; } /* ** Translate a captcha seed value into the captcha password string. ** The returned string is static and overwritten on each call to |
︙ | ︙ |
Changes to src/cgi.c.
︙ | ︙ | |||
662 663 664 665 666 667 668 | zName = 0; showBytes = 0; }else{ nArg = tokenize_line(zLine, sizeof(azArg)/sizeof(azArg[0]), azArg); for(i=0; i<nArg; i++){ int c = fossil_tolower(azArg[i][0]); int n = strlen(azArg[i]); | | | | | | 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 | zName = 0; showBytes = 0; }else{ nArg = tokenize_line(zLine, sizeof(azArg)/sizeof(azArg[0]), azArg); for(i=0; i<nArg; i++){ int c = fossil_tolower(azArg[i][0]); int n = strlen(azArg[i]); if( c=='c' && sqlite4_strnicmp(azArg[i],"content-disposition:",n)==0 ){ i++; }else if( c=='n' && sqlite4_strnicmp(azArg[i],"name=",n)==0 ){ zName = azArg[++i]; }else if( c=='f' && sqlite4_strnicmp(azArg[i],"filename=",n)==0 ){ char *z = azArg[++i]; if( zName && z && fossil_islower(zName[0]) ){ cgi_set_parameter_nocopy(mprintf("%s:filename",zName), z); } showBytes = 1; }else if( c=='c' && sqlite4_strnicmp(azArg[i],"content-type:",n)==0 ){ char *z = azArg[++i]; if( zName && z && fossil_islower(zName[0]) ){ cgi_set_parameter_nocopy(mprintf("%s:mimetype",zName), z); } } } } |
︙ | ︙ |
Changes to src/checkin.c.
︙ | ︙ | |||
44 45 46 47 48 49 50 | db_prepare(&q, "SELECT pathname, deleted, chnged, rid, coalesce(origname!=pathname,0)" " FROM vfile " " WHERE is_selected(id)" " AND (chnged OR deleted OR rid=0 OR pathname!=origname) ORDER BY 1" ); blob_zero(&rewrittenPathname); | | | 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | db_prepare(&q, "SELECT pathname, deleted, chnged, rid, coalesce(origname!=pathname,0)" " FROM vfile " " WHERE is_selected(id)" " AND (chnged OR deleted OR rid=0 OR pathname!=origname) ORDER BY 1" ); blob_zero(&rewrittenPathname); while( db_step(&q)==SQLITE4_ROW ){ const char *zPathname = db_column_text(&q,0); const char *zDisplayName = zPathname; int isDeleted = db_column_int(&q, 1); int isChnged = db_column_int(&q,2); int isNew = db_column_int(&q,3)==0; int isRenamed = db_column_int(&q,4); char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname); |
︙ | ︙ | |||
95 96 97 98 99 100 101 | } free(zFullName); } blob_reset(&rewrittenPathname); db_finalize(&q); db_prepare(&q, "SELECT uuid, id FROM vmerge JOIN blob ON merge=rid" " WHERE id<=0"); | | | 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | } free(zFullName); } blob_reset(&rewrittenPathname); db_finalize(&q); db_prepare(&q, "SELECT uuid, id FROM vmerge JOIN blob ON merge=rid" " WHERE id<=0"); while( db_step(&q)==SQLITE4_ROW ){ const char *zLabel = "MERGED_WITH"; switch( db_column_int(&q, 1) ){ case -1: zLabel = "CHERRYPICK "; break; case -2: zLabel = "BACKOUT "; break; } blob_append(report, zPrefix, nPrefix); blob_appendf(report, "%s %s\n", zLabel, db_column_text(&q, 0)); |
︙ | ︙ | |||
231 232 233 234 235 236 237 | vid = db_lget_int("checkout", 0); vfile_check_signature(vid, 0, 0); db_prepare(&q, "SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0)" " FROM vfile" " ORDER BY 1" ); | | | 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | vid = db_lget_int("checkout", 0); vfile_check_signature(vid, 0, 0); db_prepare(&q, "SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0)" " FROM vfile" " ORDER BY 1" ); while( db_step(&q)==SQLITE4_ROW ){ const char *zPathname = db_column_text(&q,0); int isDeleted = db_column_int(&q, 1); int isNew = db_column_int(&q,2)==0; int chnged = db_column_int(&q,3); int renamed = db_column_int(&q,4); char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname); if( isBrief ){ |
︙ | ︙ | |||
323 324 325 326 327 328 329 | fossil_all_reserved_names() ); if( file_tree_name(g.zRepositoryName, &repo, 0) ){ db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo); } db_multi_exec("DELETE FROM sfile WHERE x IN (SELECT pathname FROM vfile)"); blob_zero(&rewrittenPathname); | | | 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | fossil_all_reserved_names() ); if( file_tree_name(g.zRepositoryName, &repo, 0) ){ db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo); } db_multi_exec("DELETE FROM sfile WHERE x IN (SELECT pathname FROM vfile)"); blob_zero(&rewrittenPathname); while( db_step(&q)==SQLITE4_ROW ){ zDisplayName = zPathname = db_column_text(&q, 0); if( cwdRelative ) { char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname); file_relative_name(zFullName, &rewrittenPathname, 0); free(zFullName); zDisplayName = blob_str(&rewrittenPathname); if( zDisplayName[0]=='.' && zDisplayName[1]=='/' ){ |
︙ | ︙ | |||
399 400 401 402 403 404 405 | " WHERE x NOT IN (%s)" " ORDER BY 1", g.zLocalRoot, fossil_all_reserved_names() ); if( file_tree_name(g.zRepositoryName, &repo, 0) ){ db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo); } | | | 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 | " WHERE x NOT IN (%s)" " ORDER BY 1", g.zLocalRoot, fossil_all_reserved_names() ); if( file_tree_name(g.zRepositoryName, &repo, 0) ){ db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo); } while( db_step(&q)==SQLITE4_ROW ){ if( allFlag ){ file_delete(db_column_text(&q, 0)); }else{ Blob ans; char *prompt = mprintf("remove unmanaged file \"%s\" (y/N)? ", db_column_text(&q, 0)); blob_zero(&ans); |
︙ | ︙ | |||
689 690 691 692 693 694 695 | " WHERE (NOT deleted OR NOT is_selected(vfile.id))" " AND vfile.vid=%d" " ORDER BY if_selected(vfile.id, pathname, origname)", vid); blob_zero(&filename); blob_appendf(&filename, "%s", g.zLocalRoot); nBasename = blob_size(&filename); | | | 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 | " WHERE (NOT deleted OR NOT is_selected(vfile.id))" " AND vfile.vid=%d" " ORDER BY if_selected(vfile.id, pathname, origname)", vid); blob_zero(&filename); blob_appendf(&filename, "%s", g.zLocalRoot); nBasename = blob_size(&filename); while( db_step(&q)==SQLITE4_ROW ){ const char *zName = db_column_text(&q, 0); const char *zUuid = db_column_text(&q, 1); const char *zOrig = db_column_text(&q, 2); int frid = db_column_int(&q, 3); int isExe = db_column_int(&q, 4); int isLink = db_column_int(&q, 5); int isSelected = db_column_int(&q, 6); |
︙ | ︙ | |||
754 755 756 757 758 759 760 | pFile = manifest_file_next(pBaseline, 0); nFBcard++; } blob_appendf(pOut, "P %s", zParentUuid); if( verifyDate ) checkin_verify_younger(vid, zParentUuid, zDate); free(zParentUuid); db_prepare(&q2, "SELECT merge FROM vmerge WHERE id=0"); | | | 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 | pFile = manifest_file_next(pBaseline, 0); nFBcard++; } blob_appendf(pOut, "P %s", zParentUuid); if( verifyDate ) checkin_verify_younger(vid, zParentUuid, zDate); free(zParentUuid); db_prepare(&q2, "SELECT merge FROM vmerge WHERE id=0"); while( db_step(&q2)==SQLITE4_ROW ){ char *zMergeUuid; int mid = db_column_int(&q2, 0); if( !g.markPrivate && content_is_private(mid) ) continue; zMergeUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", mid); if( zMergeUuid ){ blob_appendf(pOut, " %s", zMergeUuid); if( verifyDate ) checkin_verify_younger(mid, zMergeUuid, zDate); |
︙ | ︙ | |||
804 805 806 807 808 809 810 | db_prepare(&q, "SELECT tagname FROM tagxref, tag" " WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid" " AND tagtype==2 AND tagname GLOB 'sym-*'" " AND tagname!='sym-'||%Q" " ORDER BY tagname", vid, zBranch); | | | 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 | db_prepare(&q, "SELECT tagname FROM tagxref, tag" " WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid" " AND tagtype==2 AND tagname GLOB 'sym-*'" " AND tagname!='sym-'||%Q" " ORDER BY tagname", vid, zBranch); while( db_step(&q)==SQLITE4_ROW ){ const char *zBrTag = db_column_text(&q, 0); blob_appendf(pOut, "T -%F *\n", zBrTag); } db_finalize(&q); } blob_appendf(pOut, "U %F\n", zUserOvrd ? zUserOvrd : g.zLogin); md5sum_blob(pOut, &mcksum); |
︙ | ︙ | |||
1153 1154 1155 1156 1157 1158 1159 | ** the identified fils are inserted (if they have been modified). */ db_prepare(&q, "SELECT id, %Q || pathname, mrid, %s FROM vfile " "WHERE chnged==1 AND NOT deleted AND is_selected(id)", g.zLocalRoot, glob_expr("pathname", db_get("crnl-glob","")) ); | | | 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 | ** the identified fils are inserted (if they have been modified). */ db_prepare(&q, "SELECT id, %Q || pathname, mrid, %s FROM vfile " "WHERE chnged==1 AND NOT deleted AND is_selected(id)", g.zLocalRoot, glob_expr("pathname", db_get("crnl-glob","")) ); while( db_step(&q)==SQLITE4_ROW ){ int id, rid; const char *zFullname; Blob content; int crnlOk; id = db_column_int(&q, 0); zFullname = db_column_text(&q, 1); |
︙ | ︙ |
Changes to src/clone.c.
︙ | ︙ | |||
40 41 42 43 44 45 46 | "SELECT " " rid, (SELECT uuid FROM blob WHERE rid=delta.rid)," " srcid, (SELECT uuid FROM blob WHERE rid=delta.srcid)" " FROM delta" " WHERE srcid in private AND rid NOT IN private" ); bag_init(&toUndelta); | | | 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | "SELECT " " rid, (SELECT uuid FROM blob WHERE rid=delta.rid)," " srcid, (SELECT uuid FROM blob WHERE rid=delta.srcid)" " FROM delta" " WHERE srcid in private AND rid NOT IN private" ); bag_init(&toUndelta); while( db_step(&q)==SQLITE4_ROW ){ int rid = db_column_int(&q, 0); const char *zId = db_column_text(&q, 1); int srcid = db_column_int(&q, 2); const char *zSrc = db_column_text(&q, 3); if( showWarning ){ fossil_warning( "public artifact %S (%d) is a delta from private artifact %S (%d)", |
︙ | ︙ |
Changes to src/config.h.
︙ | ︙ | |||
82 83 84 85 86 87 88 | # else # define COMPILER_NAME "unknown" # endif #endif #ifndef _RC_COMPILE_ | | | | | 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | # else # define COMPILER_NAME "unknown" # endif #endif #ifndef _RC_COMPILE_ #include "sqlite4.h" /* ** On Solaris, getpass() will only return up to 8 characters. getpassphrase() returns up to 257. */ #if HAVE_GETPASSPHRASE #define getpass getpassphrase #endif /* ** Typedef for a 64-bit integer */ typedef sqlite4_int64 i64; typedef sqlite4_uint64 u64; /* ** 8-bit types */ typedef unsigned char u8; typedef signed char i8; |
︙ | ︙ |
Changes to src/configure.c.
︙ | ︙ | |||
194 195 196 197 198 199 200 | ** and "@shun" and "@user". This routine writes SQL text into pOut that when ** evaluated will populate the corresponding table with data. */ void configure_render_special_name(const char *zName, Blob *pOut){ Stmt q; if( fossil_strcmp(zName, "@shun")==0 ){ db_prepare(&q, "SELECT uuid FROM shun"); | | | | | | 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | ** and "@shun" and "@user". This routine writes SQL text into pOut that when ** evaluated will populate the corresponding table with data. */ void configure_render_special_name(const char *zName, Blob *pOut){ Stmt q; if( fossil_strcmp(zName, "@shun")==0 ){ db_prepare(&q, "SELECT uuid FROM shun"); while( db_step(&q)==SQLITE4_ROW ){ blob_appendf(pOut, "INSERT OR IGNORE INTO shun VALUES('%s');\n", db_column_text(&q, 0) ); } db_finalize(&q); }else if( fossil_strcmp(zName, "@reportfmt")==0 ){ db_prepare(&q, "SELECT title, cols, sqlcode FROM reportfmt"); while( db_step(&q)==SQLITE4_ROW ){ blob_appendf(pOut, "INSERT INTO _xfer_reportfmt(title,cols,sqlcode)" " VALUES(%Q,%Q,%Q);\n", db_column_text(&q, 0), db_column_text(&q, 1), db_column_text(&q, 2) ); } db_finalize(&q); }else if( fossil_strcmp(zName, "@user")==0 ){ db_prepare(&q, "SELECT login, CASE WHEN length(pw)==40 THEN pw END," " cap, info, quote(photo) FROM user"); while( db_step(&q)==SQLITE4_ROW ){ blob_appendf(pOut, "INSERT INTO _xfer_user(login,pw,cap,info,photo)" " VALUES(%Q,%Q,%Q,%Q,%s);\n", db_column_text(&q, 0), db_column_text(&q, 1), db_column_text(&q, 2), db_column_text(&q, 3), db_column_text(&q, 4) ); } db_finalize(&q); }else if( fossil_strcmp(zName, "@concealed")==0 ){ db_prepare(&q, "SELECT hash, content FROM concealed"); while( db_step(&q)==SQLITE4_ROW ){ blob_appendf(pOut, "INSERT OR IGNORE INTO concealed(hash,content)" " VALUES(%Q,%Q);\n", db_column_text(&q, 0), db_column_text(&q, 1) ); } db_finalize(&q); |
︙ | ︙ | |||
257 258 259 260 261 262 263 | ** are given in the argument. ** ** These functions are used below in the WHEN clause of a trigger to ** get the trigger to fire exactly once. */ static int configHasBeenReset = 0; static void config_is_reset_function( | | | | | | | | | 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | ** are given in the argument. ** ** These functions are used below in the WHEN clause of a trigger to ** get the trigger to fire exactly once. */ static int configHasBeenReset = 0; static void config_is_reset_function( sqlite4_context *context, int argc, sqlite4_value **argv ){ int m = sqlite4_value_int(argv[0]); sqlite4_result_int(context, (configHasBeenReset&m)!=0 ); } static void config_reset_function( sqlite4_context *context, int argc, sqlite4_value **argv ){ int m = sqlite4_value_int(argv[0]); configHasBeenReset |= m; } /* ** Create the temporary _xfer_reportfmt and _xfer_user tables that are ** necessary in order to evalute the SQL text generated by the ** configure_render_special_name() routine. |
︙ | ︙ | |||
333 334 335 336 337 338 339 | @ END; @ CREATE TEMP TRIGGER _xfer_r3 BEFORE INSERT ON shun @ WHEN NOT config_is_reset(8) BEGIN @ DELETE FROM shun; @ SELECT config_reset(8); @ END; ; | | | | 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | @ END; @ CREATE TEMP TRIGGER _xfer_r3 BEFORE INSERT ON shun @ WHEN NOT config_is_reset(8) BEGIN @ DELETE FROM shun; @ SELECT config_reset(8); @ END; ; sqlite4_create_function(g.db, "config_is_reset", 1, SQLITE4_UTF8, 0, config_is_reset_function, 0, 0); sqlite4_create_function(g.db, "config_reset", 1, SQLITE4_UTF8, 0, config_reset_function, 0, 0); configHasBeenReset = 0; db_multi_exec(zSQL2); } } /* |
︙ | ︙ | |||
593 594 595 596 597 598 599 | ** Send only entries whose timestamp is later than or equal to iStart. ** ** Return the number of cards sent. */ int configure_send_group( Blob *pOut, /* Write output here */ int groupMask, /* Mask of groups to be send */ | | | | | | | | 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 | ** Send only entries whose timestamp is later than or equal to iStart. ** ** Return the number of cards sent. */ int configure_send_group( Blob *pOut, /* Write output here */ int groupMask, /* Mask of groups to be send */ sqlite4_int64 iStart /* Only write values changed since this time */ ){ Stmt q; Blob rec; int ii; int nCard = 0; blob_zero(&rec); if( groupMask & CONFIGSET_SHUN ){ db_prepare(&q, "SELECT mtime, quote(uuid), quote(scom) FROM shun" " WHERE mtime>=%lld", iStart); while( db_step(&q)==SQLITE4_ROW ){ blob_appendf(&rec,"%s %s scom %s", db_column_text(&q, 0), db_column_text(&q, 1), db_column_text(&q, 2) ); blob_appendf(pOut, "config /shun %d\n%s\n", blob_size(&rec), blob_str(&rec)); nCard++; blob_reset(&rec); } db_finalize(&q); } if( groupMask & CONFIGSET_USER ){ db_prepare(&q, "SELECT mtime, quote(login), quote(pw), quote(cap)," " quote(info), quote(photo) FROM user" " WHERE mtime>=%lld", iStart); while( db_step(&q)==SQLITE4_ROW ){ blob_appendf(&rec,"%s %s pw %s cap %s info %s photo %s", db_column_text(&q, 0), db_column_text(&q, 1), db_column_text(&q, 2), db_column_text(&q, 3), db_column_text(&q, 4), db_column_text(&q, 5) ); blob_appendf(pOut, "config /user %d\n%s\n", blob_size(&rec), blob_str(&rec)); nCard++; blob_reset(&rec); } db_finalize(&q); } if( groupMask & CONFIGSET_TKT ){ db_prepare(&q, "SELECT mtime, quote(title), quote(owner), quote(cols)," " quote(sqlcode) FROM reportfmt" " WHERE mtime>=%lld", iStart); while( db_step(&q)==SQLITE4_ROW ){ blob_appendf(&rec,"%s %s owner %s cols %s sqlcode %s", db_column_text(&q, 0), db_column_text(&q, 1), db_column_text(&q, 2), db_column_text(&q, 3), db_column_text(&q, 4) ); blob_appendf(pOut, "config /reportfmt %d\n%s\n", blob_size(&rec), blob_str(&rec)); nCard++; blob_reset(&rec); } db_finalize(&q); } if( groupMask & CONFIGSET_ADDR ){ db_prepare(&q, "SELECT mtime, quote(hash), quote(content) FROM concealed" " WHERE mtime>=%lld", iStart); while( db_step(&q)==SQLITE4_ROW ){ blob_appendf(&rec,"%s %s content %s", db_column_text(&q, 0), db_column_text(&q, 1), db_column_text(&q, 2) ); blob_appendf(pOut, "config /concealed %d\n%s\n", blob_size(&rec), blob_str(&rec)); nCard++; blob_reset(&rec); } db_finalize(&q); } db_prepare(&q, "SELECT mtime, quote(name), quote(value) FROM config" " WHERE name=:name AND mtime>=%lld", iStart); for(ii=0; ii<count(aConfig); ii++){ if( (aConfig[ii].groupMask & groupMask)!=0 && aConfig[ii].zName[0]!='@' ){ db_bind_text(&q, ":name", aConfig[ii].zName); while( db_step(&q)==SQLITE4_ROW ){ blob_appendf(&rec,"%s %s value %s", db_column_text(&q, 0), db_column_text(&q, 1), db_column_text(&q, 2) ); blob_appendf(pOut, "config /config %d\n%s\n", blob_size(&rec), blob_str(&rec)); |
︙ | ︙ | |||
724 725 726 727 728 729 730 | /* ** Write SQL text into file zFilename that will restore the configuration ** area identified by mask to its current state from any other state. */ static void export_config( int groupMask, /* Mask indicating which configuration to export */ const char *zMask, /* Name of the configuration */ | | | 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 | /* ** Write SQL text into file zFilename that will restore the configuration ** area identified by mask to its current state from any other state. */ static void export_config( int groupMask, /* Mask indicating which configuration to export */ const char *zMask, /* Name of the configuration */ sqlite4_int64 iStart, /* Start date */ const char *zFilename /* Write into this file */ ){ Blob out; blob_zero(&out); blob_appendf(&out, "# The \"%s\" configuration exported from\n" "# repository \"%s\"\n" |
︙ | ︙ | |||
810 811 812 813 814 815 816 | db_find_and_open_repository(0, 0); db_open_config(0); zMethod = g.argv[2]; n = strlen(zMethod); if( strncmp(zMethod, "export", n)==0 ){ int mask; const char *zSince = find_option("since",0,1); | | | 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 | db_find_and_open_repository(0, 0); db_open_config(0); zMethod = g.argv[2]; n = strlen(zMethod); if( strncmp(zMethod, "export", n)==0 ){ int mask; const char *zSince = find_option("since",0,1); sqlite4_int64 iStart; if( g.argc!=5 ){ usage("export AREA FILENAME"); } mask = configure_name_to_mask(g.argv[3], 1); if( zSince ){ iStart = db_multi_exec( "SELECT coalesce(strftime('%%s',%Q),strftime('%%s','now',%Q))+0", |
︙ | ︙ |
Changes to src/content.c.
︙ | ︙ | |||
121 122 123 124 125 126 127 | ** original content and not a delta. */ static int findSrcid(int rid){ static Stmt q; int srcid; db_static_prepare(&q, "SELECT srcid FROM delta WHERE rid=:rid"); db_bind_int(&q, ":rid", rid); | | | | 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | ** original content and not a delta. */ static int findSrcid(int rid){ static Stmt q; int srcid; db_static_prepare(&q, "SELECT srcid FROM delta WHERE rid=:rid"); db_bind_int(&q, ":rid", rid); if( db_step(&q)==SQLITE4_ROW ){ srcid = db_column_int(&q, 0); }else{ srcid = 0; } db_reset(&q); return srcid; } /* ** Return the blob.size field given blob.rid */ int content_size(int rid, int dflt){ static Stmt q; int sz = dflt; db_static_prepare(&q, "SELECT size FROM blob WHERE rid=:r"); db_bind_int(&q, ":r", rid); if( db_step(&q)==SQLITE4_ROW ){ sz = db_column_int(&q, 0); } db_reset(&q); return sz; } /* |
︙ | ︙ | |||
192 193 194 195 196 197 198 | bag_insert(&pending, rid); while( (rid = bag_first(&pending))!=0 ){ bag_remove(&pending, rid); bag_remove(&contentCache.missing, rid); bag_insert(&contentCache.available, rid); db_static_prepare(&q, "SELECT rid FROM delta WHERE srcid=:rid"); db_bind_int(&q, ":rid", rid); | | | | 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | bag_insert(&pending, rid); while( (rid = bag_first(&pending))!=0 ){ bag_remove(&pending, rid); bag_remove(&contentCache.missing, rid); bag_insert(&contentCache.available, rid); db_static_prepare(&q, "SELECT rid FROM delta WHERE srcid=:rid"); db_bind_int(&q, ":rid", rid); while( db_step(&q)==SQLITE4_ROW ){ int nx = db_column_int(&q, 0); bag_insert(&pending, nx); } db_reset(&q); } bag_clear(&pending); } /* ** Get the blob.content value for blob.rid=rid. Return 1 on success or ** 0 on failure. */ static int content_of_blob(int rid, Blob *pBlob){ static Stmt q; int rc = 0; db_static_prepare(&q, "SELECT content FROM blob WHERE rid=:rid AND size>=0"); db_bind_int(&q, ":rid", rid); if( db_step(&q)==SQLITE4_ROW ){ db_ephemeral_blob(&q, 0, pBlob); blob_uncompress(pBlob, pBlob); rc = 1; } db_reset(&q); return rc; } |
︙ | ︙ | |||
390 391 392 393 394 395 396 | content_get(rid, &content); manifest_crosslink(rid, &content); assert( blob_is_reset(&content) ); } /* Parse all delta-manifests that depend on baseline-manifest rid */ db_prepare(&q, "SELECT rid FROM orphan WHERE baseline=%d", rid); | | | 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 | content_get(rid, &content); manifest_crosslink(rid, &content); assert( blob_is_reset(&content) ); } /* Parse all delta-manifests that depend on baseline-manifest rid */ db_prepare(&q, "SELECT rid FROM orphan WHERE baseline=%d", rid); while( db_step(&q)==SQLITE4_ROW ){ int child = db_column_int(&q, 0); if( nChildUsed>=nChildAlloc ){ nChildAlloc = nChildAlloc*2 + 10; aChild = fossil_realloc(aChild, nChildAlloc*sizeof(aChild)); } aChild[nChildUsed++] = child; } |
︙ | ︙ | |||
418 419 420 421 422 423 424 | nChildUsed = 0; db_prepare(&q, "SELECT rid FROM delta" " WHERE srcid=%d" " AND NOT EXISTS(SELECT 1 FROM mlink WHERE mid=delta.rid)", rid ); | | | 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 | nChildUsed = 0; db_prepare(&q, "SELECT rid FROM delta" " WHERE srcid=%d" " AND NOT EXISTS(SELECT 1 FROM mlink WHERE mid=delta.rid)", rid ); while( db_step(&q)==SQLITE4_ROW ){ int child = db_column_int(&q, 0); if( nChildUsed>=nChildAlloc ){ nChildAlloc = nChildAlloc*2 + 10; aChild = fossil_realloc(aChild, nChildAlloc*sizeof(aChild)); } aChild[nChildUsed++] = child; } |
︙ | ︙ | |||
507 508 509 510 511 512 513 | } db_begin_transaction(); /* Check to see if the entry already exists and if it does whether ** or not the entry is a phantom */ db_prepare(&s1, "SELECT rid, size FROM blob WHERE uuid=%B", &hash); | | | 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 | } db_begin_transaction(); /* Check to see if the entry already exists and if it does whether ** or not the entry is a phantom */ db_prepare(&s1, "SELECT rid, size FROM blob WHERE uuid=%B", &hash); if( db_step(&s1)==SQLITE4_ROW ){ rid = db_column_int(&s1, 0); if( db_column_int(&s1, 1)>=0 || pBlob==0 ){ /* Either the entry is not a phantom or it is a phantom but we ** have no data with which to dephantomize it. In either case, ** there is nothing for us to do other than return the RID. */ db_finalize(&s1); db_end_transaction(0); |
︙ | ︙ | |||
721 722 723 724 725 726 727 | int rc; db_static_prepare(&s1, "SELECT 1 FROM private WHERE rid=:rid" ); db_bind_int(&s1, ":rid", rid); rc = db_step(&s1); db_reset(&s1); | | | 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 | int rc; db_static_prepare(&s1, "SELECT 1 FROM private WHERE rid=:rid" ); db_bind_int(&s1, ":rid", rid); rc = db_step(&s1); db_reset(&s1); return rc==SQLITE4_ROW; } /* ** Make sure an artifact is public. */ void content_make_public(int rid){ static Stmt s1; |
︙ | ︙ | |||
843 844 845 846 847 848 849 | db_prepare(&q, "SELECT " " rid, (SELECT uuid FROM blob WHERE rid=delta.rid)," " srcid, (SELECT uuid FROM blob WHERE rid=delta.srcid)" " FROM delta" " WHERE srcid in private AND rid NOT IN private" ); | | | | 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 | db_prepare(&q, "SELECT " " rid, (SELECT uuid FROM blob WHERE rid=delta.rid)," " srcid, (SELECT uuid FROM blob WHERE rid=delta.srcid)" " FROM delta" " WHERE srcid in private AND rid NOT IN private" ); while( db_step(&q)==SQLITE4_ROW ){ int rid = db_column_int(&q, 0); const char *zId = db_column_text(&q, 1); int srcid = db_column_int(&q, 2); const char *zSrc = db_column_text(&q, 3); fossil_print( "public artifact %S (%d) is a delta from private artifact %S (%d)\n", zId, rid, zSrc, srcid ); nErr++; } db_finalize(&q); db_prepare(&q, "SELECT rid, uuid, size FROM blob ORDER BY rid"); total = db_int(0, "SELECT max(rid) FROM blob"); while( db_step(&q)==SQLITE4_ROW ){ int rid = db_column_int(&q, 0); const char *zUuid = db_column_text(&q, 1); int size = db_column_int(&q, 2); n1++; fossil_print(" %d/%d\r", n1, total); fflush(stdout); if( size<0 ){ |
︙ | ︙ |
Changes to src/cson_amalgamation.c.
︙ | ︙ | |||
1402 1403 1404 1405 1406 1407 1408 | #ifdef _MSC_VER # if _MSC_VER >= 1400 /* Visual Studio 2005 and up */ # pragma warning( push ) # pragma warning(disable:4996) /* unsecure sscanf (but snscanf() isn't in c89) */ # pragma warning(disable:4244) /* complaining about data loss due to integer precision in the | | | 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 | #ifdef _MSC_VER # if _MSC_VER >= 1400 /* Visual Studio 2005 and up */ # pragma warning( push ) # pragma warning(disable:4996) /* unsecure sscanf (but snscanf() isn't in c89) */ # pragma warning(disable:4244) /* complaining about data loss due to integer precision in the sqlite4 utf decoding routines */ # endif #endif #if 1 #include <stdio.h> #define MARKER if(1) printf("MARKER: %s:%d:%s():\t",__FILE__,__LINE__,__func__); if(1) printf #else |
︙ | ︙ | |||
3680 3681 3682 3683 3684 3685 3686 | rc = cson_rc.UnknownError; } } return rc; } /** | | | | 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 | rc = cson_rc.UnknownError; } } return rc; } /** The UTF code was originally taken from sqlite4's public-domain source code (http://sqlite.org), modified only slightly for use here. This code generates some "possible data loss" warnings on MSVC, but if this code is good enough for sqlite4 then it's damned well good enough for me, so we disable that warning for Windows builds. */ /* ** This lookup table is used to help decode the first byte of ** a multi-byte UTF8 character. |
︙ | ︙ | |||
5272 5273 5274 5275 5276 5277 5278 | if(obj) cleaner(obj); } } cson_kvp_list_reserve(self,0); } /* end file ./cson_lists.h */ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 | if(obj) cleaner(obj); } } cson_kvp_list_reserve(self,0); } /* end file ./cson_lists.h */ /* begin file ./cson_sqlite4.c */ /** @file cson_sqlite4.c This file contains the implementation code for the cson sqlite4-to-JSON API. License: the same as the cson core library. Author: Stephan Beal (http://wanderinghorse.net/home/stephan) */ #if CSON_ENABLE_SQLITE3 /* we do this here for the sake of the amalgamation build */ #include <assert.h> #include <string.h> /* strlen() */ #if 0 #include <stdio.h> #define MARKER if(1) printf("MARKER: %s:%d:%s():\t",__FILE__,__LINE__,__func__); if(1) printf #else #define MARKER if(0) printf #endif #if defined(__cplusplus) extern "C" { #endif cson_value * cson_sqlite4_column_to_value( sqlite4_stmt * st, int col ) { if( ! st ) return NULL; else { #if 0 sqlite4_value * val = sqlite4_column_type(st,col); int const vtype = val ? sqlite4_value_type(val) : -1; if( ! val ) return cson_value_null(); #else int const vtype = sqlite4_column_type(st,col); #endif switch( vtype ) { case SQLITE4_NULL: return cson_value_null(); case SQLITE4_INTEGER: /* FIXME: for large integers fall back to Double instead. */ return cson_value_new_integer( (cson_int_t) sqlite4_column_int64(st, col) ); case SQLITE4_FLOAT: return cson_value_new_double( sqlite4_column_double(st, col) ); case SQLITE4_BLOB: /* arguably fall through... */ case SQLITE4_TEXT: { char const * str = (char const *)sqlite4_column_text(st,col); return cson_value_new_string(str, str ? strlen(str) : 0); } default: return NULL; } } } cson_value * cson_sqlite4_column_names( sqlite4_stmt * st ) { cson_value * aryV = NULL; cson_array * ary = NULL; char const * colName = NULL; int i = 0; int rc = 0; int colCount = 0; assert(st); colCount = sqlite4_column_count(st); if( colCount <= 0 ) return NULL; aryV = cson_value_new_array(); if( ! aryV ) return NULL; ary = cson_value_get_array(aryV); assert(ary); for( i = 0; (0 ==rc) && (i < colCount); ++i ) { colName = sqlite4_column_name( st, i ); if( ! colName ) rc = cson_rc.AllocError; else { rc = cson_array_set( ary, (unsigned int)i, cson_value_new_string(colName, strlen(colName)) ); } } if( 0 == rc ) return aryV; else { cson_value_free(aryV); return NULL; } } cson_value * cson_sqlite4_row_to_object2( sqlite4_stmt * st, cson_array * colNames ) { cson_value * rootV = NULL; cson_object * root = NULL; cson_string * colName = NULL; int i = 0; int rc = 0; cson_value * currentValue = NULL; int const colCount = sqlite4_column_count(st); if( !colCount || (colCount>cson_array_length_get(colNames)) ) { return NULL; } rootV = cson_value_new_object(); if(!rootV) return NULL; root = cson_value_get_object(rootV); for( i = 0; i < colCount; ++i ) { colName = cson_value_get_string( cson_array_get( colNames, i ) ); if( ! colName ) goto error; currentValue = cson_sqlite4_column_to_value(st,i); if( ! currentValue ) currentValue = cson_value_null(); rc = cson_object_set_s( root, colName, currentValue ); if( 0 != rc ) { cson_value_free( currentValue ); goto error; } } goto end; error: cson_value_free( rootV ); rootV = NULL; end: return rootV; } cson_value * cson_sqlite4_row_to_object( sqlite4_stmt * st ) { #if 0 cson_value * arV = cson_sqlite4_column_names(st); cson_array * ar = NULL; cson_value * rc = NULL; if(!arV) return NULL; ar = cson_value_get_array(arV); assert( NULL != ar ); rc = cson_sqlite4_row_to_object2(st, ar); cson_value_free(arV); return rc; #else cson_value * rootV = NULL; cson_object * root = NULL; char const * colName = NULL; int i = 0; int rc = 0; cson_value * currentValue = NULL; int const colCount = sqlite4_column_count(st); if( !colCount ) return NULL; rootV = cson_value_new_object(); if(!rootV) return NULL; root = cson_value_get_object(rootV); for( i = 0; i < colCount; ++i ) { colName = sqlite4_column_name( st, i ); if( ! colName ) goto error; currentValue = cson_sqlite4_column_to_value(st,i); if( ! currentValue ) currentValue = cson_value_null(); rc = cson_object_set( root, colName, currentValue ); if( 0 != rc ) { cson_value_free( currentValue ); goto error; } } goto end; error: cson_value_free( rootV ); rootV = NULL; end: return rootV; #endif } cson_value * cson_sqlite4_row_to_array( sqlite4_stmt * st ) { cson_value * aryV = NULL; cson_array * ary = NULL; int i = 0; int rc = 0; int const colCount = sqlite4_column_count(st); if( ! colCount ) return NULL; aryV = cson_value_new_array(); if( ! aryV ) return NULL; ary = cson_value_get_array(aryV); rc = cson_array_reserve(ary, (unsigned int) colCount ); if( 0 != rc ) goto error; for( i = 0; i < colCount; ++i ){ cson_value * elem = cson_sqlite4_column_to_value(st,i); if( ! elem ) goto error; rc = cson_array_append(ary,elem); if(0!=rc) { cson_value_free( elem ); goto end; } } goto end; error: cson_value_free(aryV); aryV = NULL; end: return aryV; } /** Internal impl of cson_sqlite4_stmt_to_json() when the 'fat' parameter is non-0. */ static int cson_sqlite4_stmt_to_json_fat( sqlite4_stmt * st, cson_value ** tgt ) { #define RETURN(RC) { if(rootV) cson_value_free(rootV); return RC; } if( ! tgt || !st ) return cson_rc.ArgError; else { cson_value * rootV = NULL; cson_object * root = NULL; cson_value * colsV = NULL; cson_array * cols = NULL; cson_value * rowsV = NULL; cson_array * rows = NULL; cson_value * objV = NULL; int rc = 0; int const colCount = sqlite4_column_count(st); if( colCount <= 0 ) return cson_rc.ArgError; rootV = cson_value_new_object(); if( ! rootV ) return cson_rc.AllocError; colsV = cson_sqlite4_column_names(st); if( ! colsV ) { cson_value_free( rootV ); RETURN(cson_rc.AllocError); } cols = cson_value_get_array(colsV); assert(NULL != cols); |
︙ | ︙ | |||
5528 5529 5530 5531 5532 5533 5534 | if( rc ) { cson_value_free( rowsV ); RETURN(rc); } rows = cson_value_get_array(rowsV); assert(rows); | | | | | | | | 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 | if( rc ) { cson_value_free( rowsV ); RETURN(rc); } rows = cson_value_get_array(rowsV); assert(rows); while( SQLITE4_ROW == sqlite4_step(st) ) { objV = cson_sqlite4_row_to_object2(st, cols); if( ! objV ) RETURN(cson_rc.UnknownError); rc = cson_array_append( rows, objV ); if( rc ) { cson_value_free( objV ); RETURN(rc); } } *tgt = rootV; return 0; } #undef RETURN } /** Internal impl of cson_sqlite4_stmt_to_json() when the 'fat' parameter is 0. */ static int cson_sqlite4_stmt_to_json_slim( sqlite4_stmt * st, cson_value ** tgt ) { #define RETURN(RC) { if(rootV) cson_value_free(rootV); return RC; } if( ! tgt || !st ) return cson_rc.ArgError; else { cson_value * rootV = NULL; cson_object * root = NULL; cson_value * aryV = NULL; cson_value * rowsV = NULL; cson_array * rows = NULL; int rc = 0; int const colCount = sqlite4_column_count(st); if( colCount <= 0 ) return cson_rc.ArgError; rootV = cson_value_new_object(); if( ! rootV ) return cson_rc.AllocError; aryV = cson_sqlite4_column_names(st); if( ! aryV ) { cson_value_free( rootV ); RETURN(cson_rc.AllocError); } root = cson_value_get_object(rootV); rc = cson_object_set( root, "columns", aryV ); |
︙ | ︙ | |||
5589 5590 5591 5592 5593 5594 5595 | if( 0 != rc ) { cson_value_free( rowsV ); RETURN(rc); } rows = cson_value_get_array(rowsV); assert(rows); | | | | | | | | | | | | | | | | | | | | | | | | | 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 | if( 0 != rc ) { cson_value_free( rowsV ); RETURN(rc); } rows = cson_value_get_array(rowsV); assert(rows); while( SQLITE4_ROW == sqlite4_step(st) ) { aryV = cson_sqlite4_row_to_array(st); if( ! aryV ) RETURN(cson_rc.UnknownError); rc = cson_array_append( rows, aryV ); if( 0 != rc ) { cson_value_free( aryV ); RETURN(rc); } } *tgt = rootV; return 0; } #undef RETURN } int cson_sqlite4_stmt_to_json( sqlite4_stmt * st, cson_value ** tgt, char fat ) { return fat ? cson_sqlite4_stmt_to_json_fat(st,tgt) : cson_sqlite4_stmt_to_json_slim(st,tgt) ; } int cson_sqlite4_sql_to_json( sqlite4 * db, cson_value ** tgt, char const * sql, char fat ) { if( !db || !tgt || !sql || !*sql ) return cson_rc.ArgError; else { sqlite4_stmt * st = NULL; int rc = sqlite4_prepare( db, sql, -1, &st, NULL ); if( 0 != rc ) return cson_rc.IOError /* FIXME: Better error code? */; rc = cson_sqlite4_stmt_to_json( st, tgt, fat ); sqlite4_finalize( st ); return rc; } } int cson_sqlite4_bind_value( sqlite4_stmt * st, int ndx, cson_value const * v ) { int rc = 0; char convertErr = 0; if(!st) return cson_rc.ArgError; else if( ndx < 1 ) { rc = cson_rc.RangeError; } else if( cson_value_is_array(v) ){ cson_array * ar = cson_value_get_array(v); unsigned int len = cson_array_length_get(ar); unsigned int i; assert(NULL != ar); for( i = 0; !rc && (i < len); ++i ){ rc = cson_sqlite4_bind_value( st, (int)i+ndx, cson_array_get(ar, i)); } } else if(!v || cson_value_is_null(v)){ rc = sqlite4_bind_null(st,ndx); convertErr = 1; } else if( cson_value_is_double(v) ){ rc = sqlite4_bind_double( st, ndx, cson_value_get_double(v) ); convertErr = 1; } else if( cson_value_is_bool(v) ){ rc = sqlite4_bind_int( st, ndx, cson_value_get_bool(v) ? 1 : 0 ); convertErr = 1; } else if( cson_value_is_integer(v) ){ rc = sqlite4_bind_int64( st, ndx, cson_value_get_integer(v) ); convertErr = 1; } else if( cson_value_is_string(v) ){ cson_string const * s = cson_value_get_string(v); rc = sqlite4_bind_text( st, ndx, cson_string_cstr(s), cson_string_length_bytes(s), SQLITE4_TRANSIENT); convertErr = 1; } else { rc = cson_rc.TypeError; } if(convertErr && rc) switch(rc){ case SQLITE4_TOOBIG: case SQLITE4_RANGE: rc = cson_rc.RangeError; break; case SQLITE4_NOMEM: rc = cson_rc.AllocError; break; case SQLITE4_IOERR: rc = cson_rc.IOError; break; default: rc = cson_rc.UnknownError; break; }; return rc; } #if defined(__cplusplus) } /*extern "C"*/ #endif #undef MARKER #endif /* CSON_ENABLE_SQLITE3 */ /* end file ./cson_sqlite4.c */ #endif /* FOSSIL_ENABLE_JSON */ |
Changes to src/cson_amalgamation.h.
︙ | ︙ | |||
2299 2300 2301 2302 2303 2304 2305 | #if defined(__cplusplus) } /*extern "C"*/ #endif #endif /* WANDERINGHORSE_NET_CSON_H_INCLUDED */ /* end file include/wh/cson/cson.h */ | | | | | | | | | | | | | | | | | | | | | | 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 | #if defined(__cplusplus) } /*extern "C"*/ #endif #endif /* WANDERINGHORSE_NET_CSON_H_INCLUDED */ /* end file include/wh/cson/cson.h */ /* begin file include/wh/cson/cson_sqlite4.h */ /** @file cson_sqlite4.h This file contains cson's public sqlite4-to-JSON API declarations and API documentation. If CSON_ENABLE_SQLITE3 is not defined, or is defined to 0, then including this file will have no side-effects other than defining CSON_ENABLE_SQLITE3 (if it was not defined) to 0 and defining a few include guard macros. i.e. if CSON_ENABLE_SQLITE3 is not set to a true value then the API is not visible. This API requires that <sqlite4.h> be in the INCLUDES path and that the client eventually link to (or directly embed) the sqlite4 library. */ #if !defined(WANDERINGHORSE_NET_CSON_SQLITE3_H_INCLUDED) #define WANDERINGHORSE_NET_CSON_SQLITE3_H_INCLUDED 1 #if !defined(CSON_ENABLE_SQLITE3) # if defined(DOXYGEN) #define CSON_ENABLE_SQLITE3 1 # else #define CSON_ENABLE_SQLITE3 1 # endif #endif #if CSON_ENABLE_SQLITE3 /* we do this here for the sake of the amalgamation build */ #include <sqlite4.h> #if defined(__cplusplus) extern "C" { #endif /** Converts a single value from a single 0-based column index to its JSON equivalent. On success it returns a new JSON value, which will have a different concrete type depending on the field type reported by sqlite4_column_type(st,col): Integer, double, null, or string (TEXT and BLOB data, though not all blob data is legal for a JSON string). st must be a sqlite4_step()'d row and col must be a 0-based column index within that result row. */ cson_value * cson_sqlite4_column_to_value( sqlite4_stmt * st, int col ); /** Creates a JSON Array object containing the names of all columns of the given prepared statement handle. Returns a new array value on success, which the caller owns. Its elements are in the same order as in the underlying query. On error NULL is returned. st is not traversed or freed by this function - only the column count and names are read. */ cson_value * cson_sqlite4_column_names( sqlite4_stmt * st ); /** Creates a JSON Object containing key/value pairs corresponding to the result columns in the current row of the given statement handle. st must be a sqlite4_step()'d row result. On success a new Object is returned which is owned by the caller. On error NULL is returned. cson_sqlite4_column_to_value() is used to convert each column to a JSON value, and the column names are taken from sqlite4_column_name(). */ cson_value * cson_sqlite4_row_to_object( sqlite4_stmt * st ); /** Functionally almost identical to cson_sqlite4_row_to_object(), the only difference being how the result objects gets its column names. st must be a freshly-step()'d handle holding a result row. colNames must be an Array with at least the same number of columns as st. If it has fewer, NULL is returned and this function has no side-effects. For each column in the result set, the colNames entry at the same index is used for the column key. If a given entry is-not-a String then conversion will fail and NULL will be returned. The one reason to prefer this over cson_sqlite4_row_to_object() is that this one can share the keys across multiple rows (or even other JSON containers), whereas the former makes fresh copies of the column names for each row. */ cson_value * cson_sqlite4_row_to_object2( sqlite4_stmt * st, cson_array * colNames ); /** Similar to cson_sqlite4_row_to_object(), but creates an Array value which contains the JSON-form values of the given result set row. */ cson_value * cson_sqlite4_row_to_array( sqlite4_stmt * st ); /** Converts the results of an sqlite4 SELECT statement to JSON, in the form of a cson_value object tree. st must be a prepared, but not yet traversed, SELECT query. tgt must be a pointer to NULL (see the example below). If either of those arguments are NULL, cson_rc.ArgError is returned. This walks the query results and returns a JSON object which |
︙ | ︙ | |||
2454 2455 2456 2457 2458 2459 2460 | JSON object tree (using the above structure), which the caller owns. If the query returns no rows, the "rows" value will be an empty array, as opposed to null. On error non-0 is returned and *tgt is not modified. The error code cson_rc.IOError is used to indicate a db-level | | | | | | | | | | | | 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 | JSON object tree (using the above structure), which the caller owns. If the query returns no rows, the "rows" value will be an empty array, as opposed to null. On error non-0 is returned and *tgt is not modified. The error code cson_rc.IOError is used to indicate a db-level error, and cson_rc.TypeError is returned if sqlite4_column_count(st) returns 0 or less (indicating an invalid or non-SELECT statement). The JSON data types are determined by the column type as reported by sqlite4_column_type(): SQLITE_INTEGER: integer SQLITE_FLOAT: double SQLITE_TEXT or SQLITE_BLOB: string, and this will only work if the data is UTF8 compatible. If the db returns a literal or SQL NULL for a value it is converted to a JSON null. If it somehow finds a column type it cannot handle, the value is also converted to a NULL in the output. Example @code cson_value * json = NULL; int rc = cson_sqlite4_stmt_to_json( myStatement, &json, 1 ); if( 0 != rc ) { ... error ... } else { cson_output_FILE( json, stdout, NULL ); cson_value_free( json ); } @endcode */ int cson_sqlite4_stmt_to_json( sqlite4_stmt * st, cson_value ** tgt, char fat ); /** A convenience wrapper around cson_sqlite4_stmt_to_json(), which takes SQL instead of a sqlite4_stmt object. It has the same return value and argument semantics as that function. */ int cson_sqlite4_sql_to_json( sqlite4 * db, cson_value ** tgt, char const * sql, char fat ); /** Binds a JSON value to a 1-based parameter index in a prepared SQL statement. v must be NULL or one of one of the types (null, string, integer, double, boolean, array). Booleans are bound as integer 0 or 1. NULL or null are bound as SQL NULL. Integers are bound as 64-bit ints. Strings are bound using sqlite4_bind_text() (as opposed to text16), but we could/should arguably bind them as blobs. If v is an Array then ndx is is used as a starting position (1-based) and each item in the array is bound to the next parameter position (starting and ndx, though the array uses 0-based offsets). TODO: add Object support for named parameters. Returns 0 on success, non-0 on error. */ int cson_sqlite4_bind_value( sqlite4_stmt * st, int ndx, cson_value const * v ); #if defined(__cplusplus) } /*extern "C"*/ #endif #endif /* CSON_ENABLE_SQLITE3 */ #endif /* WANDERINGHORSE_NET_CSON_SQLITE3_H_INCLUDED */ /* end file include/wh/cson/cson_sqlite4.h */ #endif /* FOSSIL_ENABLE_JSON */ |
Changes to src/db.c.
︙ | ︙ | |||
28 29 30 31 32 33 34 | ** and located at the root of the local copy of the source tree. ** */ #include "config.h" #if ! defined(_WIN32) # include <pwd.h> #endif | | | | | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | ** and located at the root of the local copy of the source tree. ** */ #include "config.h" #if ! defined(_WIN32) # include <pwd.h> #endif #include <sqlite4.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <time.h> #include "db.h" #if INTERFACE /* ** An single SQL statement is represented as an instance of the following ** structure. */ struct Stmt { Blob sql; /* The SQL for this statement */ sqlite4_stmt *pStmt; /* The results of sqlite4_prepare() */ Stmt *pNext, *pPrev; /* List of all unfinalized statements */ int nStep; /* Number of sqlite4_step() calls */ }; /* ** Copy this to initialize a Stmt object to a clean/empty state. This ** is useful to help avoid assertions when performing cleanup in some ** error handling cases. */ |
︙ | ︙ | |||
106 107 108 109 110 111 112 | ** the following structure. */ static struct DbLocalData { int nBegin; /* Nesting depth of BEGIN */ int doRollback; /* True to force a rollback */ int nCommitHook; /* Number of commit hooks */ Stmt *pAllStmt; /* List of all unfinalized statements */ | | | | 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | ** the following structure. */ static struct DbLocalData { int nBegin; /* Nesting depth of BEGIN */ int doRollback; /* True to force a rollback */ int nCommitHook; /* Number of commit hooks */ Stmt *pAllStmt; /* List of all unfinalized statements */ int nPrepare; /* Number of calls to sqlite4_prepare() */ int nDeleteOnFail; /* Number of entries in azDeleteOnFail[] */ struct sCommitHook { int (*xHook)(void); /* Functions to call at db_end_transaction() */ int sequence; /* Call functions in sequence order */ } aHook[5]; char *azDeleteOnFail[3]; /* Files to delete on a failure */ char *azBeforeCommit[5]; /* Commands to run prior to COMMIT */ int nBeforeCommit; /* Number of entries in azBeforeCommit */ int nPriorChanges; /* sqlite4_total_changes() at transaction start */ } db = {0, 0, 0, 0, 0, 0, }; /* ** Arrange for the given file to be deleted on a failure. */ void db_delete_on_failure(const char *zFilename){ assert( db.nDeleteOnFail<count(db.azDeleteOnFail) ); |
︙ | ︙ | |||
149 150 151 152 153 154 155 | /* ** Begin and end a nested transaction */ void db_begin_transaction(void){ if( db.nBegin==0 ){ db_multi_exec("BEGIN"); | | | | | | | | | | | 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | /* ** Begin and end a nested transaction */ void db_begin_transaction(void){ if( db.nBegin==0 ){ db_multi_exec("BEGIN"); /* sqlite3_commit_hook(g.db, db_verify_at_commit, 0); */ db.nPriorChanges = sqlite4_total_changes(g.db); } db.nBegin++; } void db_end_transaction(int rollbackFlag){ if( g.db==0 ) return; if( db.nBegin<=0 ) return; if( rollbackFlag ) db.doRollback = 1; db.nBegin--; if( db.nBegin==0 ){ int i; if( db.doRollback==0 && db.nPriorChanges<sqlite4_total_changes(g.db) ){ while( db.nBeforeCommit ){ db.nBeforeCommit--; sqlite4_exec(g.db, db.azBeforeCommit[db.nBeforeCommit], 0, 0, 0); sqlite4_free(0, db.azBeforeCommit[db.nBeforeCommit]); } leaf_do_pending_checks(); } for(i=0; db.doRollback==0 && i<db.nCommitHook; i++){ db.doRollback |= db.aHook[i].xHook(); } while( db.pAllStmt ){ db_finalize(db.pAllStmt); } db_multi_exec(db.doRollback ? "ROLLBACK" : "COMMIT"); db.doRollback = 0; } } /* ** Force a rollback and shutdown the database */ void db_force_rollback(void){ int i; static int busy = 0; sqlite4_stmt *pStmt = 0; if( busy || g.db==0 ) return; busy = 1; undo_rollback(); while( (pStmt = sqlite4_next_stmt(g.db,pStmt))!=0 ){ sqlite4_reset(pStmt); } while( db.pAllStmt ){ db_finalize(db.pAllStmt); } if( db.nBegin ){ sqlite4_exec(g.db, "ROLLBACK", 0, 0, 0); db.nBegin = 0; } busy = 0; db_close(0); for(i=0; i<db.nDeleteOnFail; i++){ file_delete(db.azDeleteOnFail[i]); } |
︙ | ︙ | |||
249 250 251 252 253 254 255 | int rc; char *zSql; blob_zero(&pStmt->sql); blob_vappendf(&pStmt->sql, zFormat, ap); va_end(ap); zSql = blob_str(&pStmt->sql); db.nPrepare++; | | | | 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | int rc; char *zSql; blob_zero(&pStmt->sql); blob_vappendf(&pStmt->sql, zFormat, ap); va_end(ap); zSql = blob_str(&pStmt->sql); db.nPrepare++; rc = sqlite4_prepare(g.db, zSql, -1, &pStmt->pStmt, 0); if( rc!=0 && !errOk ){ db_err("%s\n%s", sqlite4_errmsg(g.db), zSql); } pStmt->pNext = pStmt->pPrev = 0; pStmt->nStep = 0; return rc; } int db_prepare(Stmt *pStmt, const char *zFormat, ...){ int rc; |
︙ | ︙ | |||
274 275 276 277 278 279 280 | va_list ap; va_start(ap, zFormat); rc = db_vprepare(pStmt, 1, zFormat, ap); va_end(ap); return rc; } int db_static_prepare(Stmt *pStmt, const char *zFormat, ...){ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | | < | | | | | | | | | | | | | | | | < | | < < | | 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 | va_list ap; va_start(ap, zFormat); rc = db_vprepare(pStmt, 1, zFormat, ap); va_end(ap); return rc; } int db_static_prepare(Stmt *pStmt, const char *zFormat, ...){ int rc = SQLITE4_OK; if( blob_size(&pStmt->sql)==0 ){ va_list ap; va_start(ap, zFormat); rc = db_vprepare(pStmt, 0, zFormat, ap); pStmt->pNext = db.pAllStmt; pStmt->pPrev = 0; if( db.pAllStmt ) db.pAllStmt->pPrev = pStmt; db.pAllStmt = pStmt; va_end(ap); } return rc; } /* ** Return the index of a bind parameter */ static int paramIdx(Stmt *pStmt, const char *zParamName){ int i = sqlite4_bind_parameter_index(pStmt->pStmt, zParamName); if( i==0 ){ db_err("no such bind parameter: %s\nSQL: %b", zParamName, &pStmt->sql); } return i; } /* ** Bind an integer, string, or Blob value to a named parameter. */ int db_bind_int(Stmt *pStmt, const char *zParamName, int iValue){ return sqlite4_bind_int(pStmt->pStmt, paramIdx(pStmt, zParamName), iValue); } int db_bind_int64(Stmt *pStmt, const char *zParamName, i64 iValue){ return sqlite4_bind_int64(pStmt->pStmt, paramIdx(pStmt, zParamName), iValue); } int db_bind_double(Stmt *pStmt, const char *zParamName, double rValue){ return sqlite4_bind_double(pStmt->pStmt, paramIdx(pStmt, zParamName), rValue); } int db_bind_text(Stmt *pStmt, const char *zParamName, const char *zValue){ return sqlite4_bind_text(pStmt->pStmt, paramIdx(pStmt, zParamName), zValue, -1, SQLITE4_STATIC); } int db_bind_null(Stmt *pStmt, const char *zParamName){ return sqlite4_bind_null(pStmt->pStmt, paramIdx(pStmt, zParamName)); } int db_bind_blob(Stmt *pStmt, const char *zParamName, Blob *pBlob){ return sqlite4_bind_blob(pStmt->pStmt, paramIdx(pStmt, zParamName), blob_buffer(pBlob), blob_size(pBlob), SQLITE4_STATIC); } /* bind_str() treats a Blob object like a TEXT string and binds it ** to the SQL variable. Constrast this to bind_blob() which treats ** the Blob object like an SQL BLOB. */ int db_bind_str(Stmt *pStmt, const char *zParamName, Blob *pBlob){ return sqlite4_bind_text(pStmt->pStmt, paramIdx(pStmt, zParamName), blob_buffer(pBlob), blob_size(pBlob), SQLITE4_STATIC); } /* ** Step the SQL statement. Return either SQLITE4_ROW or an error code ** or SQLITE4_OK if the statement finishes successfully. */ int db_step(Stmt *pStmt){ int rc; rc = sqlite4_step(pStmt->pStmt); pStmt->nStep++; return rc; } /* ** Print warnings if a query is inefficient. */ static void db_stats(Stmt *pStmt){ #ifdef FOSSIL_DEBUG int c1, c2, c3; const char *zSql = sqlite4_sql(pStmt->pStmt); if( zSql==0 ) return; c1 = sqlite4_stmt_status(pStmt->pStmt, SQLITE4_STMTSTATUS_FULLSCAN_STEP, 1); c2 = sqlite4_stmt_status(pStmt->pStmt, SQLITE4_STMTSTATUS_AUTOINDEX, 1); c3 = sqlite4_stmt_status(pStmt->pStmt, SQLITE4_STMTSTATUS_SORT, 1); if( c1>pStmt->nStep*4 && strstr(zSql,"/*scan*/")==0 ){ fossil_warning("%d scan steps for %d rows in [%s]", c1, pStmt->nStep, zSql); }else if( c2 ){ fossil_warning("%d automatic index rows in [%s]", c2, zSql); }else if( c3 && strstr(zSql,"/*sort*/")==0 && strstr(zSql,"/*scan*/")==0 ){ fossil_warning("sort w/o index in [%s]", zSql); } pStmt->nStep = 0; #endif } /* ** Reset or finalize a statement. */ int db_reset(Stmt *pStmt){ int rc; db_stats(pStmt); rc = sqlite4_reset(pStmt->pStmt); db_check_result(rc); return rc; } int db_finalize(Stmt *pStmt){ int rc; db_stats(pStmt); blob_reset(&pStmt->sql); rc = sqlite4_finalize(pStmt->pStmt); db_check_result(rc); pStmt->pStmt = 0; if( pStmt->pNext ){ pStmt->pNext->pPrev = pStmt->pPrev; } if( pStmt->pPrev ){ pStmt->pPrev->pNext = pStmt->pNext; }else if( db.pAllStmt==pStmt ){ db.pAllStmt = pStmt->pNext; } pStmt->pNext = 0; pStmt->pPrev = 0; return rc; } /* ** Return the rowid of the most recent insert */ i64 db_last_insert_rowid(void){ return sqlite4_last_insert_rowid(g.db); } /* ** Return the number of rows that were changed by the most recent ** INSERT, UPDATE, or DELETE. Auxiliary changes caused by triggers ** or other side effects are not counted. */ int db_changes(void){ return sqlite4_changes(g.db); } /* ** Extract text, integer, or blob values from the N-th column of the ** current row. */ int db_column_bytes(Stmt *pStmt, int N){ return sqlite4_column_bytes(pStmt->pStmt, N); } int db_column_int(Stmt *pStmt, int N){ return sqlite4_column_int(pStmt->pStmt, N); } i64 db_column_int64(Stmt *pStmt, int N){ return sqlite4_column_int64(pStmt->pStmt, N); } double db_column_double(Stmt *pStmt, int N){ return sqlite4_column_double(pStmt->pStmt, N); } const char *db_column_text(Stmt *pStmt, int N){ return (char*)sqlite4_column_text(pStmt->pStmt, N); } const char *db_column_raw(Stmt *pStmt, int N){ return (const char*)sqlite4_column_blob(pStmt->pStmt, N); } const char *db_column_name(Stmt *pStmt, int N){ return (char*)sqlite4_column_name(pStmt->pStmt, N); } int db_column_count(Stmt *pStmt){ return sqlite4_column_count(pStmt->pStmt); } char *db_column_malloc(Stmt *pStmt, int N){ return mprintf("%s", db_column_text(pStmt, N)); } void db_column_blob(Stmt *pStmt, int N, Blob *pBlob){ blob_append(pBlob, sqlite4_column_blob(pStmt->pStmt, N), sqlite4_column_bytes(pStmt->pStmt, N)); } /* ** Initialize a blob to an ephermeral copy of the content of a ** column in the current row. The data in the blob will become ** invalid when the statement is stepped or reset. */ void db_ephemeral_blob(Stmt *pStmt, int N, Blob *pBlob){ blob_init(pBlob, sqlite4_column_blob(pStmt->pStmt, N), sqlite4_column_bytes(pStmt->pStmt, N)); } /* ** Check a result code. If it is not SQLITE4_OK, print the ** corresponding error message and exit. */ void db_check_result(int rc){ if( rc!=SQLITE4_OK ){ db_err("SQL error: %s", sqlite4_errmsg(g.db)); } } /* ** Execute a single prepared statement until it finishes. */ int db_exec(Stmt *pStmt){ int rc; while( (rc = db_step(pStmt))==SQLITE4_ROW ){} rc = db_reset(pStmt); db_check_result(rc); return rc; } /* ** Execute multiple SQL statements. */ int db_multi_exec(const char *zSql, ...){ Blob sql; int rc; va_list ap; char *zErr = 0; blob_init(&sql, 0, 0); va_start(ap, zSql); blob_vappendf(&sql, zSql, ap); va_end(ap); rc = sqlite4_exec(g.db, blob_buffer(&sql), 0, 0, &zErr); if( rc!=SQLITE4_OK ){ db_err("%s\n%s", zErr, blob_buffer(&sql)); } blob_reset(&sql); return rc; } /* ** Optionally make the following changes to the database if feasible and ** convenient. Do not start a transaction for these changes, but only ** make these changes if other changes are also being made. */ void db_optional_sql(const char *zDb, const char *zSql, ...){ if( db_is_writeable(zDb) && db.nBeforeCommit < count(db.azBeforeCommit) ){ va_list ap; va_start(ap, zSql); db.azBeforeCommit[db.nBeforeCommit++] = sqlite4_vmprintf(0, zSql, ap); va_end(ap); } } /* ** Execute a query and return a single integer value. */ i64 db_int64(i64 iDflt, const char *zSql, ...){ va_list ap; Stmt s; i64 rc; va_start(ap, zSql); db_vprepare(&s, 0, zSql, ap); va_end(ap); if( db_step(&s)!=SQLITE4_ROW ){ rc = iDflt; }else{ rc = db_column_int64(&s, 0); } db_finalize(&s); return rc; } int db_int(int iDflt, const char *zSql, ...){ va_list ap; Stmt s; int rc; va_start(ap, zSql); db_vprepare(&s, 0, zSql, ap); va_end(ap); if( db_step(&s)!=SQLITE4_ROW ){ rc = iDflt; }else{ rc = db_column_int(&s, 0); } db_finalize(&s); return rc; } /* ** Return TRUE if the query would return 1 or more rows. Return ** FALSE if the query result would be an empty set. */ int db_exists(const char *zSql, ...){ va_list ap; Stmt s; int rc; va_start(ap, zSql); db_vprepare(&s, 0, zSql, ap); va_end(ap); if( db_step(&s)!=SQLITE4_ROW ){ rc = 0; }else{ rc = 1; } db_finalize(&s); return rc; } /* ** Execute a query and return a floating-point value. */ double db_double(double rDflt, const char *zSql, ...){ va_list ap; Stmt s; double r; va_start(ap, zSql); db_vprepare(&s, 0, zSql, ap); va_end(ap); if( db_step(&s)!=SQLITE4_ROW ){ r = rDflt; }else{ r = db_column_double(&s, 0); } db_finalize(&s); return r; } /* ** Execute a query and append the first column of the first row ** of the result set to blob given in the first argument. */ void db_blob(Blob *pResult, const char *zSql, ...){ va_list ap; Stmt s; va_start(ap, zSql); db_vprepare(&s, 0, zSql, ap); va_end(ap); if( db_step(&s)==SQLITE4_ROW ){ blob_append(pResult, sqlite4_column_blob(s.pStmt, 0), sqlite4_column_bytes(s.pStmt, 0)); } db_finalize(&s); } /* ** Execute a query. Return the first column of the first row ** of the result set as a string. Space to hold the string is ** obtained from malloc(). If the result set is empty, return ** zDefault instead. */ char *db_text(char const *zDefault, const char *zSql, ...){ va_list ap; Stmt s; char *z; va_start(ap, zSql); db_vprepare(&s, 0, zSql, ap); va_end(ap); if( db_step(&s)==SQLITE4_ROW ){ z = mprintf("%s", sqlite4_column_text(s.pStmt, 0)); }else if( zDefault ){ z = mprintf("%s", zDefault); }else{ z = 0; } db_finalize(&s); return z; } /* ** Initialize a new database file with the given schema. If anything ** goes wrong, call db_err() to exit. */ void db_init_database( const char *zFileName, /* Name of database file to create */ const char *zSchema, /* First part of schema */ ... /* Additional SQL to run. Terminate with NULL. */ ){ sqlite4 *db; int rc; const char *zSql; va_list ap; rc = sqlite4_open(0, zFileName, &db, SQLITE4_OPEN_READWRITE|SQLITE4_OPEN_CREATE); if( rc!=SQLITE4_OK ){ db_err(sqlite4_errmsg(db)); } sqlite4_exec(db, "BEGIN EXCLUSIVE", 0, 0, 0); rc = sqlite4_exec(db, zSchema, 0, 0, 0); if( rc!=SQLITE4_OK ){ db_err(sqlite4_errmsg(db)); } va_start(ap, zSchema); while( (zSql = va_arg(ap, const char*))!=0 ){ rc = sqlite4_exec(db, zSql, 0, 0, 0); if( rc!=SQLITE4_OK ){ db_err(sqlite4_errmsg(db)); } } va_end(ap); sqlite4_exec(db, "COMMIT", 0, 0, 0); sqlite4_close(db); } /* ** Function to return the number of seconds since 1970. This is ** the same as strftime('%s','now') but is more compact. */ void db_now_function( sqlite4_context *context, int argc, sqlite4_value **argv ){ sqlite4_result_int64(context, time(0)); } /* ** Open a database file. Return a pointer to the new database ** connection. An error results in process abort. */ static sqlite4 *openDatabase(const char *zDbName){ int rc; const char *zVfs; sqlite4 *db; zVfs = fossil_getenv("FOSSIL_VFS"); rc = sqlite4_open(0, zDbName, &db, SQLITE4_OPEN_READWRITE | SQLITE4_OPEN_CREATE ); if( rc!=SQLITE4_OK ){ db_err(sqlite4_errmsg(db)); } sqlite4_create_function(db, "now", 0, SQLITE4_ANY, 0, db_now_function, 0, 0); return db; } /* ** zDbName is the name of a database file. If no other database ** file is open, then open this one. If another database file is |
︙ | ︙ | |||
764 765 766 767 768 769 770 | if( access(zHome, W_OK) ){ fossil_fatal("home directory %s must be writeable", zHome); } #endif g.zHome = mprintf("%/", zHome); #if defined(_WIN32) /* . filenames give some window systems problems and many apps problems */ | | | | 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 | if( access(zHome, W_OK) ){ fossil_fatal("home directory %s must be writeable", zHome); } #endif g.zHome = mprintf("%/", zHome); #if defined(_WIN32) /* . filenames give some window systems problems and many apps problems */ zDbName = mprintf("%//_fossil4", zHome); #else zDbName = mprintf("%s/.fossil4", zHome); #endif if( file_size(zDbName)<1024*3 ){ db_init_database(zDbName, zConfigSchema, (char*)0); } g.useAttach = useAttach; if( useAttach ){ db_open_or_attach(zDbName, "configdb"); |
︙ | ︙ | |||
875 876 877 878 879 880 881 | if( g.localOpen) return 1; file_getcwd(zPwd, sizeof(zPwd)-20); n = strlen(zPwd); if( n==1 && zPwd[0]=='/' ) zPwd[0] = '.'; while( n>0 ){ if( file_access(zPwd, W_OK) ) break; for(i=0; i<sizeof(aDbName)/sizeof(aDbName[0]); i++){ | | | 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 | if( g.localOpen) return 1; file_getcwd(zPwd, sizeof(zPwd)-20); n = strlen(zPwd); if( n==1 && zPwd[0]=='/' ) zPwd[0] = '.'; while( n>0 ){ if( file_access(zPwd, W_OK) ) break; for(i=0; i<sizeof(aDbName)/sizeof(aDbName[0]); i++){ sqlite4_snprintf(zPwd+n, sizeof(zPwd)-n, "%s", aDbName[i]); if( isValidLocalDb(zPwd) ){ /* Found a valid checkout database file */ zPwd[n] = 0; while( n>1 && zPwd[n-1]=='/' ){ n--; zPwd[n] = 0; } |
︙ | ︙ | |||
1025 1026 1027 1028 1029 1030 1031 | " AND value<>'%s'", AUX_SCHEMA); } /* ** Return true if the database is writeable */ int db_is_writeable(const char *zName){ | | | 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 | " AND value<>'%s'", AUX_SCHEMA); } /* ** Return true if the database is writeable */ int db_is_writeable(const char *zName){ return 1; /* !sqlite4_db_readonly(g.db, db_name(zName)); */ } /* ** Verify that the repository schema is correct. If it is not correct, ** issue a fatal error and die. */ void db_verify_schema(void){ |
︙ | ︙ | |||
1094 1095 1096 1097 1098 1099 1100 | /* ** Close the database connection. ** ** Check for unfinalized statements and report errors if the reportErrors ** argument is true. Ignore unfinalized statements when false. */ void db_close(int reportErrors){ | | | | | | | | | | | | < < | | < | | | 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 | /* ** Close the database connection. ** ** Check for unfinalized statements and report errors if the reportErrors ** argument is true. Ignore unfinalized statements when false. */ void db_close(int reportErrors){ sqlite4_stmt *pStmt; if( g.db==0 ) return; if( g.fSqlStats ){ int cur, hiwtr; sqlite4_db_status(g.db, SQLITE4_DBSTATUS_LOOKASIDE_USED, &cur, &hiwtr, 0); fprintf(stderr, "-- LOOKASIDE_USED %10d %10d\n", cur, hiwtr); sqlite4_db_status(g.db, SQLITE4_DBSTATUS_LOOKASIDE_HIT, &cur, &hiwtr, 0); fprintf(stderr, "-- LOOKASIDE_HIT %10d\n", hiwtr); sqlite4_db_status(g.db, SQLITE4_DBSTATUS_LOOKASIDE_MISS_SIZE, &cur,&hiwtr,0); fprintf(stderr, "-- LOOKASIDE_MISS_SIZE %10d\n", hiwtr); sqlite4_db_status(g.db, SQLITE4_DBSTATUS_LOOKASIDE_MISS_FULL, &cur,&hiwtr,0); fprintf(stderr, "-- LOOKASIDE_MISS_FULL %10d\n", hiwtr); sqlite4_db_status(g.db, SQLITE4_DBSTATUS_CACHE_USED, &cur, &hiwtr, 0); fprintf(stderr, "-- CACHE_USED %10d\n", cur); sqlite4_db_status(g.db, SQLITE4_DBSTATUS_SCHEMA_USED, &cur, &hiwtr, 0); fprintf(stderr, "-- SCHEMA_USED %10d\n", cur); sqlite4_db_status(g.db, SQLITE4_DBSTATUS_STMT_USED, &cur, &hiwtr, 0); fprintf(stderr, "-- STMT_USED %10d\n", cur); sqlite4_env_status(0, SQLITE4_ENVSTATUS_MEMORY_USED, &cur, &hiwtr, 0); fprintf(stderr, "-- MEMORY_USED %10d %10d\n", cur, hiwtr); sqlite4_env_status(0, SQLITE4_ENVSTATUS_MALLOC_SIZE, &cur, &hiwtr, 0); fprintf(stderr, "-- MALLOC_SIZE %10d\n", hiwtr); sqlite4_env_status(0, SQLITE4_ENVSTATUS_MALLOC_COUNT, &cur, &hiwtr, 0); fprintf(stderr, "-- MALLOC_COUNT %10d %10d\n", cur, hiwtr); fprintf(stderr, "-- prepared statements %10d\n", db.nPrepare); } while( db.pAllStmt ){ db_finalize(db.pAllStmt); } db_end_transaction(1); pStmt = 0; if( reportErrors ){ while( (pStmt = sqlite4_next_stmt(g.db, pStmt))!=0 ){ fossil_warning("unfinalized SQL statement: [%s]", sqlite4_sql(pStmt)); } } g.repositoryOpen = 0; g.localOpen = 0; g.configOpen = 0; sqlite4_close(g.db); g.db = 0; if( g.dbConfig ){ sqlite4_close(g.dbConfig); g.dbConfig = 0; } } /* ** Create a new empty repository database with the given name. |
︙ | ︙ | |||
1308 1309 1310 1311 1312 1313 1314 | /* ** SQL functions for debugging. ** ** The print() function writes its arguments on stdout, but only ** if the -sqlprint command-line option is turned on. */ static void db_sql_print( | | | | | | | | | | | | | 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 | /* ** SQL functions for debugging. ** ** The print() function writes its arguments on stdout, but only ** if the -sqlprint command-line option is turned on. */ static void db_sql_print( sqlite4_context *context, int argc, sqlite4_value **argv ){ int i; if( g.fSqlPrint ){ for(i=0; i<argc; i++){ char c = i==argc-1 ? '\n' : ' '; fossil_print("%s%c", sqlite4_value_text(argv[i]), c); } } } static void db_sql_trace(void *notUsed, const char *zSql){ int n = strlen(zSql); char *zMsg = mprintf("%s%s\n", zSql, (n>0 && zSql[n-1]==';') ? "" : ";"); fossil_puts(zMsg, 1); fossil_free(zMsg); } /* ** Implement the user() SQL function. user() takes no arguments and ** returns the user ID of the current user. */ static void db_sql_user( sqlite4_context *context, int argc, sqlite4_value **argv ){ if( g.zLogin!=0 ){ sqlite4_result_text(context, g.zLogin, -1, SQLITE4_STATIC); } } /* ** Implement the cgi() SQL function. cgi() takes a an argument which is ** a name of CGI query parameter. The value of that parameter is returned, ** if available. optional second argument will be returned if the first ** doesn't exist as a CGI parameter. */ static void db_sql_cgi(sqlite4_context *context, int argc, sqlite4_value **argv){ const char* zP; if( argc!=1 && argc!=2 ) return; zP = P((const char*)sqlite4_value_text(argv[0])); if( zP ){ sqlite4_result_text(context, zP, -1, SQLITE4_STATIC); }else if( argc==2 ){ zP = (const char*)sqlite4_value_text(argv[1]); if( zP ) sqlite4_result_text(context, zP, -1, SQLITE4_TRANSIENT); } } /* ** SQL function: ** ** is_selected(id) |
︙ | ︙ | |||
1379 1380 1381 1382 1383 1384 1385 | ** changes are to be committed) or if id is found in g.aCommitFile[] ** (meaning that id was named on the command-line). ** ** In the second form (3 arguments) return argument X if true and Y ** if false. */ static void file_is_selected( | | | | | | | 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 | ** changes are to be committed) or if id is found in g.aCommitFile[] ** (meaning that id was named on the command-line). ** ** In the second form (3 arguments) return argument X if true and Y ** if false. */ static void file_is_selected( sqlite4_context *context, int argc, sqlite4_value **argv ){ int rc = 0; assert(argc==1 || argc==3); if( g.aCommitFile ){ int iId = sqlite4_value_int(argv[0]); int ii; for(ii=0; g.aCommitFile[ii]; ii++){ if( iId==g.aCommitFile[ii] ){ rc = 1; break; } } }else{ rc = 1; } if( argc==1 ){ sqlite4_result_int(context, rc); }else{ assert( argc==3 ); assert( rc==0 || rc==1 ); sqlite4_result_value(context, argv[2-rc]); } } /* ** Convert the input string into an SHA1. Make a notation in the ** CONCEALED table so that the hash can be undo using the db_reveal() ** function at some later time. |
︙ | ︙ | |||
1432 1433 1434 1435 1436 1437 1438 | Blob out; if( n==40 && validate16(zContent, n) ){ memcpy(zHash, zContent, n); zHash[n] = 0; }else{ sha1sum_step_text(zContent, n); sha1sum_finish(&out); | | | 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 | Blob out; if( n==40 && validate16(zContent, n) ){ memcpy(zHash, zContent, n); zHash[n] = 0; }else{ sha1sum_step_text(zContent, n); sha1sum_finish(&out); sqlite4_snprintf(zHash, sizeof(zHash), "%s", blob_str(&out)); blob_reset(&out); db_multi_exec( "INSERT OR IGNORE INTO concealed(hash,content,mtime)" " VALUES(%Q,%#Q,now())", zHash, n, zContent ); } |
︙ | ︙ | |||
1470 1471 1472 1473 1474 1475 1476 | } /* ** This function registers auxiliary functions when the SQLite ** database connection is first established. */ LOCAL void db_connection_init(void){ | | | | | | | | | | | | 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 | } /* ** This function registers auxiliary functions when the SQLite ** database connection is first established. */ LOCAL void db_connection_init(void){ sqlite4_exec(g.db, "PRAGMA foreign_keys=OFF;", 0, 0, 0); sqlite4_create_function(g.db, "user", 0, SQLITE4_ANY, 0, db_sql_user, 0, 0); sqlite4_create_function(g.db, "cgi", 1, SQLITE4_ANY, 0, db_sql_cgi, 0, 0); sqlite4_create_function(g.db, "cgi", 2, SQLITE4_ANY, 0, db_sql_cgi, 0, 0); sqlite4_create_function(g.db, "print", -1, SQLITE4_UTF8, 0,db_sql_print,0,0); sqlite4_create_function( g.db, "is_selected", 1, SQLITE4_UTF8, 0, file_is_selected,0,0 ); sqlite4_create_function( g.db, "if_selected", 3, SQLITE4_UTF8, 0, file_is_selected,0,0 ); if( g.fSqlTrace ){ sqlite4_trace(g.db, db_sql_trace, 0); } } /* ** Return true if the string zVal represents "true" (or "false"). */ int is_truth(const char *zVal){ |
︙ | ︙ | |||
1517 1518 1519 1520 1521 1522 1523 | ** ** If g.useAttach that means the ~/.fossil database was opened with ** the useAttach flag set to 1. In that case no connection swap is required ** so this routine is a no-op. */ void db_swap_connections(void){ if( !g.useAttach ){ | | | 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 | ** ** If g.useAttach that means the ~/.fossil database was opened with ** the useAttach flag set to 1. In that case no connection swap is required ** so this routine is a no-op. */ void db_swap_connections(void){ if( !g.useAttach ){ sqlite4 *dbTemp = g.db; g.db = g.dbConfig; g.dbConfig = dbTemp; } } /* ** Logic for reading potentially versioned settings from |
︙ | ︙ | |||
1678 1679 1680 1681 1682 1683 1684 | int db_get_int(const char *zName, int dflt){ int v = dflt; int rc; if( g.repositoryOpen ){ Stmt q; db_prepare(&q, "SELECT value FROM config WHERE name=%Q", zName); rc = db_step(&q); | | | | | 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 | int db_get_int(const char *zName, int dflt){ int v = dflt; int rc; if( g.repositoryOpen ){ Stmt q; db_prepare(&q, "SELECT value FROM config WHERE name=%Q", zName); rc = db_step(&q); if( rc==SQLITE4_ROW ){ v = db_column_int(&q, 0); } db_finalize(&q); }else{ rc = SQLITE4_DONE; } if( rc==SQLITE4_DONE && g.configOpen ){ db_swap_connections(); v = db_int(dflt, "SELECT value FROM global_config WHERE name=%Q", zName); db_swap_connections(); } return v; } void db_set_int(const char *zName, int value, int globalFlag){ |
︙ | ︙ | |||
1864 1865 1866 1867 1868 1869 1870 | ); }else{ db_prepare(&q, "SELECT '(global)', value FROM global_config WHERE name=%Q", ctrlSetting->name ); } | | | 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 | ); }else{ db_prepare(&q, "SELECT '(global)', value FROM global_config WHERE name=%Q", ctrlSetting->name ); } if( db_step(&q)==SQLITE4_ROW ){ fossil_print("%-20s %-8s %s\n", ctrlSetting->name, db_column_text(&q, 0), db_column_text(&q, 1)); }else{ fossil_print("%-20s\n", ctrlSetting->name); } if( ctrlSetting->versionable && localOpen ){ /* Check to see if this is overridden by a versionable settings file */ |
︙ | ︙ | |||
2172 2173 2174 2175 2176 2177 2178 | ** describes that timespan in units of seconds, minutes, hours, days, ** or years, depending on its duration. */ char *db_timespan_name(double rSpan){ if( rSpan<0 ) rSpan = -rSpan; rSpan *= 24.0*3600.0; /* Convert units to seconds */ if( rSpan<120.0 ){ | | | | | | | | | 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 | ** describes that timespan in units of seconds, minutes, hours, days, ** or years, depending on its duration. */ char *db_timespan_name(double rSpan){ if( rSpan<0 ) rSpan = -rSpan; rSpan *= 24.0*3600.0; /* Convert units to seconds */ if( rSpan<120.0 ){ return sqlite4_mprintf(0, "%.1f seconds", rSpan); } rSpan /= 60.0; /* Convert units to minutes */ if( rSpan<90.0 ){ return sqlite4_mprintf(0, "%.1f minutes", rSpan); } rSpan /= 60.0; /* Convert units to hours */ if( rSpan<=48.0 ){ return sqlite4_mprintf(0, "%.1f hours", rSpan); } rSpan /= 24.0; /* Convert units to days */ if( rSpan<=365.0 ){ return sqlite4_mprintf(0, "%.1f days", rSpan); } rSpan /= 356.24; /* Convert units to years */ return sqlite4_mprintf(0, "%.1f years", rSpan); } /* ** COMMAND: test-timespan ** %fossil test-timespan TIMESTAMP ** ** Print the approximate span of time from now to TIMESTAMP. */ void test_timespan_cmd(void){ double rDiff; if( g.argc!=3 ) usage("TIMESTAMP"); sqlite4_open(0, ":memory:", &g.db, SQLITE4_OPEN_READWRITE); rDiff = db_double(0.0, "SELECT julianday('now') - julianday(%Q)", g.argv[2]); fossil_print("Time differences: %s\n", db_timespan_name(rDiff)); sqlite4_close(g.db); g.db = 0; } |
Changes to src/descendants.c.
︙ | ︙ | |||
102 103 104 105 106 107 108 | db_prepare(&ins, "INSERT OR IGNORE INTO leaves VALUES(:rid)"); while( bag_count(&pending) ){ int rid = bag_first(&pending); int cnt = 0; bag_remove(&pending, rid); db_bind_int(&q1, ":rid", rid); | | | | 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | db_prepare(&ins, "INSERT OR IGNORE INTO leaves VALUES(:rid)"); while( bag_count(&pending) ){ int rid = bag_first(&pending); int cnt = 0; bag_remove(&pending, rid); db_bind_int(&q1, ":rid", rid); while( db_step(&q1)==SQLITE4_ROW ){ int cid = db_column_int(&q1, 0); if( bag_insert(&seen, cid) ){ bag_insert(&pending, cid); } db_bind_int(&isBr, ":rid", cid); if( db_step(&isBr)==SQLITE4_DONE ){ cnt++; } db_reset(&isBr); } db_reset(&q1); if( cnt==0 && !is_a_leaf(rid) ){ cnt++; |
︙ | ︙ | |||
173 174 175 176 177 178 179 | " WHERE a.cid=:rid" ); while( (N--)>0 && (rid = pqueuex_extract(&queue, 0))!=0 ){ db_bind_int(&ins, ":rid", rid); db_step(&ins); db_reset(&ins); db_bind_int(&q, ":rid", rid); | | | 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | " WHERE a.cid=:rid" ); while( (N--)>0 && (rid = pqueuex_extract(&queue, 0))!=0 ){ db_bind_int(&ins, ":rid", rid); db_step(&ins); db_reset(&ins); db_bind_int(&q, ":rid", rid); while( db_step(&q)==SQLITE4_ROW ){ int pid = db_column_int(&q, 0); double mtime = db_column_double(&q, 1); if( bag_insert(&seen, pid) ){ pqueuex_insert(&queue, pid, -mtime, 0); } } db_reset(&q); |
︙ | ︙ | |||
211 212 213 214 215 216 217 | db_prepare(&ins, "INSERT INTO ancestor VALUES(:rid, :gen)"); db_prepare(&q, "SELECT pid FROM plink" " WHERE cid=:rid AND isprim" ); while( (N--)>0 ){ db_bind_int(&q, ":rid", rid); | | | 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | db_prepare(&ins, "INSERT INTO ancestor VALUES(:rid, :gen)"); db_prepare(&q, "SELECT pid FROM plink" " WHERE cid=:rid AND isprim" ); while( (N--)>0 ){ db_bind_int(&q, ":rid", rid); if( db_step(&q)!=SQLITE4_ROW ) break; rid = db_column_int(&q, 0); db_reset(&q); gen++; db_bind_int(&ins, ":rid", rid); db_bind_int(&ins, ":gen", gen); db_step(&ins); db_reset(&ins); |
︙ | ︙ | |||
245 246 247 248 249 250 251 | db_prepare(&ins, "INSERT OR IGNORE INTO ok VALUES(:rid)"); db_prepare(&q, "SELECT cid, mtime FROM plink WHERE pid=:rid"); while( (N--)>0 && (rid = pqueuex_extract(&queue, 0))!=0 ){ db_bind_int(&ins, ":rid", rid); db_step(&ins); db_reset(&ins); db_bind_int(&q, ":rid", rid); | | | 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | db_prepare(&ins, "INSERT OR IGNORE INTO ok VALUES(:rid)"); db_prepare(&q, "SELECT cid, mtime FROM plink WHERE pid=:rid"); while( (N--)>0 && (rid = pqueuex_extract(&queue, 0))!=0 ){ db_bind_int(&ins, ":rid", rid); db_step(&ins); db_reset(&ins); db_bind_int(&q, ":rid", rid); while( db_step(&q)==SQLITE4_ROW ){ int pid = db_column_int(&q, 0); double mtime = db_column_double(&q, 1); if( bag_insert(&seen, pid) ){ pqueuex_insert(&queue, pid, mtime, 0); } } db_reset(&q); |
︙ | ︙ |
Changes to src/diff.c.
︙ | ︙ | |||
471 472 473 474 475 476 477 | } /* ** Write a 6-digit line number followed by a single space onto the line. */ static void sbsWriteLineno(SbsLine *p, int ln){ sbsWriteHtml(p, "<span class=\"diffln\">"); | | | 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 | } /* ** Write a 6-digit line number followed by a single space onto the line. */ static void sbsWriteLineno(SbsLine *p, int ln){ sbsWriteHtml(p, "<span class=\"diffln\">"); sqlite4_snprintf(&p->zLine[p->n], 7, "%5d ", ln+1); p->n += 6; sbsWriteHtml(p, "</span>"); p->zLine[p->n++] = ' '; } /* ** The two text segments zLeft and zRight are known to be different on |
︙ | ︙ | |||
1773 1774 1775 1776 1777 1778 1779 | " AND event.objid=ancestor.rid" " ORDER BY ancestor.generation ASC" " LIMIT %d", (annFlags & ANN_FILE_VERS)!=0 ? "fid" : "mid", fnid, iLimit>0 ? iLimit : 10000000 ); | | | 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 | " AND event.objid=ancestor.rid" " ORDER BY ancestor.generation ASC" " LIMIT %d", (annFlags & ANN_FILE_VERS)!=0 ? "fid" : "mid", fnid, iLimit>0 ? iLimit : 10000000 ); while( db_step(&q)==SQLITE4_ROW ){ int pid = db_column_int(&q, 0); const char *zUuid = db_column_text(&q, 1); const char *zDate = db_column_text(&q, 2); const char *zUser = db_column_text(&q, 3); if( webLabel ){ zLabel = mprintf( "<a href='%R/info/%s' target='infowindow'>%.10s</a> %s %13.13s", |
︙ | ︙ |
Changes to src/diffcmd.c.
︙ | ︙ | |||
278 279 280 281 282 283 284 | " WHERE vid=%d" " AND (deleted OR chnged OR rid==0)" " ORDER BY pathname", vid ); } db_prepare(&q, blob_str(&sql)); | | | 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | " WHERE vid=%d" " AND (deleted OR chnged OR rid==0)" " ORDER BY pathname", vid ); } db_prepare(&q, blob_str(&sql)); while( db_step(&q)==SQLITE4_ROW ){ const char *zPathname = db_column_text(&q,0); int isDeleted = db_column_int(&q, 1); int isChnged = db_column_int(&q,2); int isNew = db_column_int(&q,3); int srcid = db_column_int(&q, 4); int isLink = db_column_int(&q, 5); char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname); |
︙ | ︙ |
Changes to src/doc.c.
︙ | ︙ | |||
300 301 302 303 304 305 306 | z = zName; for(i=0; zName[i]; i++){ if( zName[i]=='.' ) z = &zName[i+1]; } len = strlen(z); if( len<sizeof(zSuffix)-1 ){ | | | 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | z = zName; for(i=0; zName[i]; i++){ if( zName[i]=='.' ) z = &zName[i+1]; } len = strlen(z); if( len<sizeof(zSuffix)-1 ){ sqlite4_snprintf(zSuffix, sizeof(zSuffix), "%s", z); for(i=0; zSuffix[i]; i++) zSuffix[i] = fossil_tolower(zSuffix[i]); first = 0; last = sizeof(aMime)/sizeof(aMime[0]); while( first<=last ){ int c; i = (first+last)/2; c = fossil_strcmp(zSuffix, aMime[i].zSuffix); |
︙ | ︙ | |||
384 385 386 387 388 389 390 | goto doc_not_found; } }else{ goto doc_not_found; } } if( fossil_strcmp(zBaseline,"ckout")==0 && db_open_local()==0 ){ | | | 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | goto doc_not_found; } }else{ goto doc_not_found; } } if( fossil_strcmp(zBaseline,"ckout")==0 && db_open_local()==0 ){ sqlite4_snprintf(zBaseline, sizeof(zBaseline), "tip"); } if( fossil_strcmp(zBaseline,"ckout")==0 ){ /* Read from the local checkout */ char *zFullpath; db_must_be_within_tree(); zFullpath = mprintf("%s/%s", g.zLocalRoot, zName); if( !file_isfile(zFullpath) ){ |
︙ | ︙ |
Changes to src/encode.c.
︙ | ︙ | |||
530 531 532 533 534 535 536 | int n, i; unsigned char salt; char *zOut; if( zIn==0 ) return 0; n = strlen(zIn); zOut = fossil_malloc( n*2+3 ); | | | 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | int n, i; unsigned char salt; char *zOut; if( zIn==0 ) return 0; n = strlen(zIn); zOut = fossil_malloc( n*2+3 ); sqlite4_randomness(0, 1, &salt); zOut[n+1] = (char)salt; for(i=0; i<n; i++) zOut[i+n+2] = zIn[i]^aObscurer[i&0x0f]^salt; encode16((unsigned char*)&zOut[n+1], (unsigned char*)zOut, n+1); return zOut; } /* |
︙ | ︙ |
Changes to src/event.c.
︙ | ︙ | |||
81 82 83 84 85 86 87 | rid = nextRid = prevRid = 0; db_prepare(&q1, "SELECT rid FROM tagxref" " WHERE tagid=(SELECT tagid FROM tag WHERE tagname GLOB 'event-%q*')" " ORDER BY mtime DESC", zEventId ); | | | | 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | rid = nextRid = prevRid = 0; db_prepare(&q1, "SELECT rid FROM tagxref" " WHERE tagid=(SELECT tagid FROM tag WHERE tagname GLOB 'event-%q*')" " ORDER BY mtime DESC", zEventId ); while( db_step(&q1)==SQLITE4_ROW ){ nextRid = rid; rid = db_column_int(&q1, 0); if( specRid==0 || specRid==rid ){ if( db_step(&q1)==SQLITE4_ROW ){ prevRid = db_column_int(&q1, 0); } break; } } db_finalize(&q1); if( rid==0 || (specRid!=0 && specRid!=rid) ){ |
︙ | ︙ | |||
322 323 324 325 326 327 328 | db_multi_exec("INSERT INTO newtags VALUES(%B)", &one); } blob_reset(&tags); /* Extract the tags in sorted order and make an entry in the ** artifact for each. */ db_prepare(&q, "SELECT x FROM newtags ORDER BY x"); | | | 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | db_multi_exec("INSERT INTO newtags VALUES(%B)", &one); } blob_reset(&tags); /* Extract the tags in sorted order and make an entry in the ** artifact for each. */ db_prepare(&q, "SELECT x FROM newtags ORDER BY x"); while( db_step(&q)==SQLITE4_ROW ){ blob_appendf(&event, "T +sym-%F *\n", db_column_text(&q, 0)); } db_finalize(&q); } if( g.zLogin ){ blob_appendf(&event, "U %F\n", g.zLogin); } |
︙ | ︙ |
Changes to src/export.c.
︙ | ︙ | |||
33 34 35 36 37 38 39 | if( zUser==0 ){ printf(" <unknown>"); return; } db_static_prepare(&q, "SELECT info FROM user WHERE login=:user"); db_bind_text(&q, ":user", zUser); | | | 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | if( zUser==0 ){ printf(" <unknown>"); return; } db_static_prepare(&q, "SELECT info FROM user WHERE login=:user"); db_bind_text(&q, ":user", zUser); if( db_step(&q)!=SQLITE4_ROW ){ db_reset(&q); for(i=0; zUser[i] && zUser[i]!='>' && zUser[i]!='<'; i++){} if( zUser[i]==0 ){ printf(" %s <%s>", zUser, zUser); return; } zName = mprintf("%s", zUser); |
︙ | ︙ | |||
180 181 182 183 184 185 186 | " FROM mlink" " WHERE fid>0 AND NOT EXISTS(SELECT 1 FROM oldblob WHERE rid=fid)"); db_prepare(&q, "SELECT DISTINCT fid FROM mlink" " WHERE fid>0 AND NOT EXISTS(SELECT 1 FROM oldblob WHERE rid=fid)"); db_prepare(&q2, "INSERT INTO oldblob VALUES (:rid)"); db_prepare(&q3, "SELECT rid FROM newblob WHERE srcid= (:srcid)"); | | | | 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | " FROM mlink" " WHERE fid>0 AND NOT EXISTS(SELECT 1 FROM oldblob WHERE rid=fid)"); db_prepare(&q, "SELECT DISTINCT fid FROM mlink" " WHERE fid>0 AND NOT EXISTS(SELECT 1 FROM oldblob WHERE rid=fid)"); db_prepare(&q2, "INSERT INTO oldblob VALUES (:rid)"); db_prepare(&q3, "SELECT rid FROM newblob WHERE srcid= (:srcid)"); while( db_step(&q)==SQLITE4_ROW ){ int rid = db_column_int(&q, 0); Blob content; while( !bag_find(&blobs, rid) ){ content_get(rid, &content); db_bind_int(&q2, ":rid", rid); db_step(&q2); db_reset(&q2); printf("blob\nmark :%d\ndata %d\n", BLOBMARK(rid), blob_size(&content)); bag_insert(&blobs, rid); fwrite(blob_buffer(&content), 1, blob_size(&content), stdout); printf("\n"); blob_reset(&content); db_bind_int(&q3, ":srcid", rid); if( db_step(&q3) != SQLITE4_ROW ){ db_reset(&q3); break; } rid = db_column_int(&q3, 0); db_reset(&q3); } } |
︙ | ︙ | |||
220 221 222 223 224 225 226 | " (SELECT value FROM tagxref WHERE rid=objid AND tagid=%d)" " FROM event" " WHERE type='ci' AND NOT EXISTS (SELECT 1 FROM oldcommit WHERE objid=rid)" " ORDER BY mtime ASC", TAG_BRANCH ); db_prepare(&q2, "INSERT INTO oldcommit VALUES (:rid)"); | | | 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | " (SELECT value FROM tagxref WHERE rid=objid AND tagid=%d)" " FROM event" " WHERE type='ci' AND NOT EXISTS (SELECT 1 FROM oldcommit WHERE objid=rid)" " ORDER BY mtime ASC", TAG_BRANCH ); db_prepare(&q2, "INSERT INTO oldcommit VALUES (:rid)"); while( db_step(&q)==SQLITE4_ROW ){ Stmt q4; const char *zSecondsSince1970 = db_column_text(&q, 0); int ckinId = db_column_int(&q, 1); const char *zComment = db_column_text(&q, 2); const char *zUser = db_column_text(&q, 3); const char *zBranch = db_column_text(&q, 4); char *zBr; |
︙ | ︙ | |||
246 247 248 249 250 251 252 | free(zBr); printf("committer"); print_person(zUser); printf(" %s +0000\n", zSecondsSince1970); if( zComment==0 ) zComment = "null comment"; printf("data %d\n%s\n", (int)strlen(zComment), zComment); db_prepare(&q3, "SELECT pid FROM plink WHERE cid=%d AND isprim", ckinId); | | | | | 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | free(zBr); printf("committer"); print_person(zUser); printf(" %s +0000\n", zSecondsSince1970); if( zComment==0 ) zComment = "null comment"; printf("data %d\n%s\n", (int)strlen(zComment), zComment); db_prepare(&q3, "SELECT pid FROM plink WHERE cid=%d AND isprim", ckinId); if( db_step(&q3) == SQLITE4_ROW ){ printf("from :%d\n", COMMITMARK(db_column_int(&q3, 0))); db_prepare(&q4, "SELECT pid FROM plink" " WHERE cid=%d AND NOT isprim" " AND NOT EXISTS(SELECT 1 FROM phantom WHERE rid=pid)" " ORDER BY pid", ckinId); while( db_step(&q4)==SQLITE4_ROW ){ printf("merge :%d\n", COMMITMARK(db_column_int(&q4,0))); } db_finalize(&q4); }else{ printf("deleteall\n"); } db_prepare(&q4, "SELECT filename.name, mlink.fid, mlink.mperm FROM mlink" " JOIN filename ON filename.fnid=mlink.fnid" " WHERE mlink.mid=%d", ckinId ); while( db_step(&q4)==SQLITE4_ROW ){ const char *zName = db_column_text(&q4,0); int zNew = db_column_int(&q4,1); int mPerm = db_column_int(&q4,2); if( zNew==0) printf("D %s\n", zName); else if( bag_find(&blobs, zNew) ) { const char *zPerm; |
︙ | ︙ | |||
300 301 302 303 304 305 306 | /* Output tags */ db_prepare(&q, "SELECT tagname, rid, strftime('%%s',mtime)" " FROM tagxref JOIN tag USING(tagid)" " WHERE tagtype=1 AND tagname GLOB 'sym-*'" ); | | | 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | /* Output tags */ db_prepare(&q, "SELECT tagname, rid, strftime('%%s',mtime)" " FROM tagxref JOIN tag USING(tagid)" " WHERE tagtype=1 AND tagname GLOB 'sym-*'" ); while( db_step(&q)==SQLITE4_ROW ){ const char *zTagname = db_column_text(&q, 0); char *zEncoded = 0; int rid = db_column_int(&q, 1); const char *zSecSince1970 = db_column_text(&q, 2); int i; if( rid==0 || !bag_find(&vers, rid) ) continue; zTagname += 4; |
︙ | ︙ | |||
328 329 330 331 332 333 334 | if( markfile_out!=0 ){ FILE *f; f = fopen(markfile_out, "w"); if( f == 0 ){ fossil_panic("cannot open %s for writing", markfile_out); } db_prepare(&q, "SELECT rid FROM oldblob"); | | | | 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | if( markfile_out!=0 ){ FILE *f; f = fopen(markfile_out, "w"); if( f == 0 ){ fossil_panic("cannot open %s for writing", markfile_out); } db_prepare(&q, "SELECT rid FROM oldblob"); while( db_step(&q)==SQLITE4_ROW ){ fprintf(f, "b%d\n", db_column_int(&q, 0)); } db_finalize(&q); db_prepare(&q, "SELECT rid FROM oldcommit"); while( db_step(&q)==SQLITE4_ROW ){ fprintf(f, "c%d\n", db_column_int(&q, 0)); } db_finalize(&q); if( ferror(f)!=0 || fclose(f)!=0 ) { fossil_panic("error while writing %s", markfile_out); } } } |
Changes to src/file.c.
︙ | ︙ | |||
669 670 671 672 673 674 675 | blob_zero(&x); for(i=2; i<g.argc; i++){ char zBuf[100]; const char *zName = g.argv[i]; file_canonical_name(zName, &x, 0); fossil_print("[%s] -> [%s]\n", zName, blob_buffer(&x)); blob_reset(&x); | | | | 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 | blob_zero(&x); for(i=2; i<g.argc; i++){ char zBuf[100]; const char *zName = g.argv[i]; file_canonical_name(zName, &x, 0); fossil_print("[%s] -> [%s]\n", zName, blob_buffer(&x)); blob_reset(&x); sqlite4_snprintf(zBuf, sizeof(zBuf), "%lld", file_wd_size(zName)); fossil_print(" file_size = %s\n", zBuf); sqlite4_snprintf(zBuf, sizeof(zBuf), "%lld", file_wd_mtime(zName)); fossil_print(" file_mtime = %s\n", zBuf); fossil_print(" file_isfile = %d\n", file_wd_isfile(zName)); fossil_print(" file_isfile_or_link = %d\n",file_wd_isfile_or_link(zName)); fossil_print(" file_islink = %d\n", file_wd_islink(zName)); fossil_print(" file_isexe = %d\n", file_wd_isexe(zName)); fossil_print(" file_isdir = %d\n", file_wd_isdir(zName)); } |
︙ | ︙ | |||
944 945 946 947 948 949 950 | if( azDirs[i]==0 ) continue; if( !file_isdir(azDirs[i]) ) continue; zDir = azDirs[i]; break; } /* Check that the output buffer is large enough for the temporary file | | | | | 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 | if( azDirs[i]==0 ) continue; if( !file_isdir(azDirs[i]) ) continue; zDir = azDirs[i]; break; } /* Check that the output buffer is large enough for the temporary file ** name. If it is not, return SQLITE4_ERROR. */ if( (strlen(zDir) + 17) >= (size_t)nBuf ){ fossil_fatal("insufficient space for temporary filename"); } do{ if( cnt++>20 ) fossil_panic("cannot generate a temporary filename"); sqlite4_snprintf(zBuf, nBuf-17, "%s/", zDir); j = (int)strlen(zBuf); sqlite4_randomness(0, 15, &zBuf[j]); for(i=0; i<15; i++, j++){ zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ]; } zBuf[j] = 0; }while( file_size(zBuf)>=0 ); #if defined(_WIN32) |
︙ | ︙ | |||
1005 1006 1007 1008 1009 1010 1011 | /* ** Translate MBCS to UTF8. Return a pointer to the translated text. ** Call fossil_mbcs_free() to deallocate any memory used to store the ** returned pointer when done. */ char *fossil_mbcs_to_utf8(const char *zMbcs){ #ifdef _WIN32 | | | | | | 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 | /* ** Translate MBCS to UTF8. Return a pointer to the translated text. ** Call fossil_mbcs_free() to deallocate any memory used to store the ** returned pointer when done. */ char *fossil_mbcs_to_utf8(const char *zMbcs){ #ifdef _WIN32 extern char *sqlite4_win32_mbcs_to_utf8(const char*); return sqlite4_win32_mbcs_to_utf8(zMbcs); #else return (char*)zMbcs; /* No-op on unix */ #endif } /* ** Translate UTF8 to MBCS for use in system calls. Return a pointer to the ** translated text.. Call fossil_mbcs_free() to deallocate any memory ** used to store the returned pointer when done. */ char *fossil_utf8_to_mbcs(const char *zUtf8){ #ifdef _WIN32 extern char *sqlite4_win32_utf8_to_mbcs(const char*); return sqlite4_win32_utf8_to_mbcs(zUtf8); #else return (char*)zUtf8; /* No-op on unix */ #endif } /* ** Return the value of an environment variable as UTF8. |
︙ | ︙ | |||
1084 1085 1086 1087 1088 1089 1090 | /* ** Translate MBCS to UTF8. Return a pointer. Call fossil_mbcs_free() ** to deallocate any memory used to store the returned pointer when done. */ void fossil_mbcs_free(char *zOld){ #ifdef _WIN32 | | | | 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 | /* ** Translate MBCS to UTF8. Return a pointer. Call fossil_mbcs_free() ** to deallocate any memory used to store the returned pointer when done. */ void fossil_mbcs_free(char *zOld){ #ifdef _WIN32 extern void sqlite4_free(void*); sqlite4_free(0, zOld); #else /* No-op on unix */ #endif } /* ** Like fopen() but always takes a UTF8 argument. |
︙ | ︙ |
Changes to src/finfo.c.
︙ | ︙ | |||
71 72 73 74 75 76 77 | vfile_check_signature(vid, 1, 0); file_tree_name(g.argv[2], &fname, 1); db_prepare(&q, "SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0)" " FROM vfile WHERE vfile.pathname=%B %s", &fname, filename_collation()); blob_zero(&line); | | | 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | vfile_check_signature(vid, 1, 0); file_tree_name(g.argv[2], &fname, 1); db_prepare(&q, "SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0)" " FROM vfile WHERE vfile.pathname=%B %s", &fname, filename_collation()); blob_zero(&line); if ( db_step(&q)==SQLITE4_ROW ) { Blob uuid; int isDeleted = db_column_int(&q, 1); int isNew = db_column_int(&q,2) == 0; int chnged = db_column_int(&q,3); int renamed = db_column_int(&q,4); blob_zero(&uuid); |
︙ | ︙ | |||
170 171 172 173 174 175 176 | " ORDER BY event.mtime DESC LIMIT %d OFFSET %d", zFilename, filename_collation(), iLimit, iOffset ); blob_zero(&line); if( iBrief ){ fossil_print("History of %s\n", blob_str(&fname)); } | | | | | 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | " ORDER BY event.mtime DESC LIMIT %d OFFSET %d", zFilename, filename_collation(), iLimit, iOffset ); blob_zero(&line); if( iBrief ){ fossil_print("History of %s\n", blob_str(&fname)); } while( db_step(&q)==SQLITE4_ROW ){ const char *zFileUuid = db_column_text(&q, 0); const char *zCiUuid = db_column_text(&q,1); const char *zDate = db_column_text(&q, 2); const char *zCom = db_column_text(&q, 3); const char *zUser = db_column_text(&q, 4); char *zOut; if( iBrief ){ fossil_print("%s ", zDate); zOut = sqlite4_mprintf(0, "[%.10s] %s (user: %s, artifact: [%.10s])", zCiUuid, zCom, zUser, zFileUuid); comment_print(zOut, 11, 79); sqlite4_free(0, zOut); }else{ blob_reset(&line); blob_appendf(&line, "%.10s ", zCiUuid); blob_appendf(&line, "%.10s ", zDate); blob_appendf(&line, "%8.8s ", zUser); blob_appendf(&line,"%-40.40s\n", zCom ); comment_print(blob_str(&line), 0, 79); |
︙ | ︙ | |||
272 273 274 275 276 277 278 | blob_appendf(&title, "History of "); hyperlinked_path(zFilename, &title, 0); @ <h2>%b(&title)</h2> blob_reset(&title); pGraph = graph_init(); @ <div id="canvas" style="position:relative;width:1px;height:1px;"></div> @ <table id="timelineTable" class="timelineTable"> | | | 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | blob_appendf(&title, "History of "); hyperlinked_path(zFilename, &title, 0); @ <h2>%b(&title)</h2> blob_reset(&title); pGraph = graph_init(); @ <div id="canvas" style="position:relative;width:1px;height:1px;"></div> @ <table id="timelineTable" class="timelineTable"> while( db_step(&q)==SQLITE4_ROW ){ const char *zDate = db_column_text(&q, 0); const char *zCom = db_column_text(&q, 1); const char *zUser = db_column_text(&q, 2); int fpid = db_column_int(&q, 3); int frid = db_column_int(&q, 4); const char *zPUuid = db_column_text(&q, 5); const char *zUuid = db_column_text(&q, 6); |
︙ | ︙ | |||
295 296 297 298 299 300 301 | if( uBg ){ zBgClr = hash_color(zUser); }else if( brBg || zBgClr==0 || zBgClr[0]==0 ){ zBgClr = strcmp(zBr,"trunk")==0 ? "" : hash_color(zBr); } gidx = graph_add_row(pGraph, frid, fpid>0 ? 1 : 0, &fpid, zBr, zBgClr, 0); if( memcmp(zDate, zPrevDate, 10) ){ | | | | | 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | if( uBg ){ zBgClr = hash_color(zUser); }else if( brBg || zBgClr==0 || zBgClr[0]==0 ){ zBgClr = strcmp(zBr,"trunk")==0 ? "" : hash_color(zBr); } gidx = graph_add_row(pGraph, frid, fpid>0 ? 1 : 0, &fpid, zBr, zBgClr, 0); if( memcmp(zDate, zPrevDate, 10) ){ sqlite4_snprintf(zPrevDate, sizeof(zPrevDate), "%.10s", zDate); @ <tr><td> @ <div class="divider">%s(zPrevDate)</div> @ </td></tr> } memcpy(zTime, &zDate[11], 5); zTime[5] = 0; @ <tr><td class="timelineTime"> @ %z(href("%R/timeline?c=%t",zDate))%s(zTime)</a></td> @ <td class="timelineGraph"><div id="m%d(gidx)"></div></td> if( zBgClr && zBgClr[0] ){ @ <td class="timelineTableCell" style="background-color: %h(zBgClr);"> }else{ @ <td class="timelineTableCell"> } sqlite4_snprintf(zShort, sizeof(zShort), "%.10s", zUuid); sqlite4_snprintf(zShortCkin, sizeof(zShortCkin), "%.10s", zCkin); if( zUuid ){ @ %z(href("%R/artifact/%s",zUuid))[%S(zUuid)]</a> part of check-in }else{ @ <b>Deleted</b> by check-in } hyperlink_to_uuid(zShortCkin); @ %h(zCom) (user: |
︙ | ︙ |
Changes to src/gzip.c.
︙ | ︙ | |||
45 46 47 48 49 50 51 | z[2] = (v>>16) & 0xff; z[3] = (v>>24) & 0xff; } /* ** Begin constructing a gzip file. */ | | | 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | z[2] = (v>>16) & 0xff; z[3] = (v>>24) & 0xff; } /* ** Begin constructing a gzip file. */ void gzip_begin(sqlite4_int64 now){ char aHdr[10]; assert( gzip.eState==0 ); blob_zero(&gzip.out); aHdr[0] = 0x1f; aHdr[1] = 0x8b; aHdr[2] = 8; aHdr[3] = 0; |
︙ | ︙ | |||
123 124 125 126 127 128 129 | ** ** Compress a file using gzip. */ void test_gzip_cmd(void){ Blob b; char *zOut; if( g.argc!=3 ) usage("FILENAME"); | | | 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | ** ** Compress a file using gzip. */ void test_gzip_cmd(void){ Blob b; char *zOut; if( g.argc!=3 ) usage("FILENAME"); sqlite4_open(0, ":memory:", &g.db, SQLITE4_OPEN_READWRITE); gzip_begin(0); blob_read_from_file(&b, g.argv[2]); zOut = mprintf("%s.gz", g.argv[2]); gzip_step(blob_buffer(&b), blob_size(&b)); blob_reset(&b); gzip_finish(&b); blob_write_to_file(&b, zOut); blob_reset(&b); fossil_free(zOut); } |
Changes to src/http_transport.c.
︙ | ︙ | |||
200 201 202 203 204 205 206 | rc = ssl_open(); if( rc==0 ) transport.isOpen = 1; #else socket_set_errmsg("HTTPS: Fossil has been compiled without SSL support"); rc = 1; #endif }else if( g.urlIsFile ){ | | | | 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | rc = ssl_open(); if( rc==0 ) transport.isOpen = 1; #else socket_set_errmsg("HTTPS: Fossil has been compiled without SSL support"); rc = 1; #endif }else if( g.urlIsFile ){ sqlite4_uint64 iRandId; sqlite4_randomness(0, sizeof(iRandId), &iRandId); transport.zOutFile = mprintf("%s-%llu-out.http", g.zRepositoryName, iRandId); transport.zInFile = mprintf("%s-%llu-in.http", g.zRepositoryName, iRandId); transport.pFile = fopen(transport.zOutFile, "wb"); if( transport.pFile==0 ){ fossil_fatal("cannot output temporary file: %s", transport.zOutFile); |
︙ | ︙ |
Changes to src/import.c.
︙ | ︙ | |||
555 556 557 558 559 560 561 | }else if( memcmp(zLine, "mark ", 5)==0 ){ trim_newline(&zLine[5]); fossil_free(gg.zMark); gg.zMark = fossil_strdup(&zLine[5]); }else if( memcmp(zLine, "tagger ", 7)==0 || memcmp(zLine, "committer ",10)==0 ){ | | | 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 | }else if( memcmp(zLine, "mark ", 5)==0 ){ trim_newline(&zLine[5]); fossil_free(gg.zMark); gg.zMark = fossil_strdup(&zLine[5]); }else if( memcmp(zLine, "tagger ", 7)==0 || memcmp(zLine, "committer ",10)==0 ){ sqlite4_int64 secSince1970; for(i=0; zLine[i] && zLine[i]!='<'; i++){} if( zLine[i]==0 ) goto malformed_line; z = &zLine[i+1]; for(i=i+1; zLine[i] && zLine[i]!='>'; i++){} if( zLine[i]==0 ) goto malformed_line; zLine[i] = 0; fossil_free(gg.zUser); |
︙ | ︙ | |||
772 773 774 775 776 777 778 | ); db_begin_transaction(); if( !incrFlag ) db_initial_setup(0, 0, 1); git_fast_import(pIn); db_prepare(&q, "SELECT tcontent FROM xtag"); | | | 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 | ); db_begin_transaction(); if( !incrFlag ) db_initial_setup(0, 0, 1); git_fast_import(pIn); db_prepare(&q, "SELECT tcontent FROM xtag"); while( db_step(&q)==SQLITE4_ROW ){ Blob record; db_ephemeral_blob(&q, 0, &record); fast_insert_content(&record, 0, 0); import_reset(0); } db_finalize(&q); db_end_transaction(0); |
︙ | ︙ |
Changes to src/info.c.
︙ | ︙ | |||
81 82 83 84 85 86 87 | rid ); } if( showFamily ){ db_prepare(&q, "SELECT uuid, pid, isprim FROM plink JOIN blob ON pid=rid " " WHERE cid=%d" " ORDER BY isprim DESC, mtime DESC /*sort*/", rid); | | | | 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | rid ); } if( showFamily ){ db_prepare(&q, "SELECT uuid, pid, isprim FROM plink JOIN blob ON pid=rid " " WHERE cid=%d" " ORDER BY isprim DESC, mtime DESC /*sort*/", rid); while( db_step(&q)==SQLITE4_ROW ){ const char *zUuid = db_column_text(&q, 0); const char *zType = db_column_int(&q, 2) ? "parent:" : "merged-from:"; zDate = db_text("", "SELECT datetime(mtime) || ' UTC' FROM event WHERE objid=%d", db_column_int(&q, 1) ); fossil_print("%-13s %s %s\n", zType, zUuid, zDate); free(zDate); } db_finalize(&q); db_prepare(&q, "SELECT uuid, cid, isprim FROM plink JOIN blob ON cid=rid " " WHERE pid=%d" " ORDER BY isprim DESC, mtime DESC /*sort*/", rid); while( db_step(&q)==SQLITE4_ROW ){ const char *zUuid = db_column_text(&q, 0); const char *zType = db_column_int(&q, 2) ? "child:" : "merged-into:"; zDate = db_text("", "SELECT datetime(mtime) || ' UTC' FROM event WHERE objid=%d", db_column_int(&q, 1) ); fossil_print("%-13s %s %s\n", zType, zUuid, zDate); |
︙ | ︙ | |||
128 129 130 131 132 133 134 | ** checkouts in a repository. */ static void extraRepoInfo(void){ Stmt s; db_prepare(&s, "SELECT substr(name,7), date(mtime,'unixepoch')" " FROM config" " WHERE name GLOB 'ckout:*' ORDER BY name"); | | | | 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | ** checkouts in a repository. */ static void extraRepoInfo(void){ Stmt s; db_prepare(&s, "SELECT substr(name,7), date(mtime,'unixepoch')" " FROM config" " WHERE name GLOB 'ckout:*' ORDER BY name"); while( db_step(&s)==SQLITE4_ROW ){ const char *zName; const char *zCkout = db_column_text(&s, 0); if( g.localOpen ){ if( fossil_strcmp(zCkout, g.zLocalRoot)==0 ) continue; zName = "alt-root:"; }else{ zName = "check-out:"; } fossil_print("%-11s %-54s %s\n", zName, zCkout, db_column_text(&s, 1)); } db_finalize(&s); db_prepare(&s, "SELECT substr(name,9), date(mtime,'unixepoch')" " FROM config" " WHERE name GLOB 'baseurl:*' ORDER BY name"); while( db_step(&s)==SQLITE4_ROW ){ fossil_print("access-url: %-54s %s\n", db_column_text(&s, 0), db_column_text(&s, 1)); } db_finalize(&s); } |
︙ | ︙ | |||
231 232 233 234 235 236 237 | " (SELECT uuid FROM blob WHERE rid=tagxref.srcid AND rid!=%d)," " value, datetime(tagxref.mtime,'localtime'), tagtype," " (SELECT uuid FROM blob WHERE rid=tagxref.origid AND rid!=%d)" " FROM tagxref JOIN tag ON tagxref.tagid=tag.tagid" " WHERE tagxref.rid=%d AND tagname NOT GLOB '%s'" " ORDER BY tagname /*sort*/", rid, rid, rid, zNotGlob ); | | | 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | " (SELECT uuid FROM blob WHERE rid=tagxref.srcid AND rid!=%d)," " value, datetime(tagxref.mtime,'localtime'), tagtype," " (SELECT uuid FROM blob WHERE rid=tagxref.origid AND rid!=%d)" " FROM tagxref JOIN tag ON tagxref.tagid=tag.tagid" " WHERE tagxref.rid=%d AND tagname NOT GLOB '%s'" " ORDER BY tagname /*sort*/", rid, rid, rid, zNotGlob ); while( db_step(&q)==SQLITE4_ROW ){ const char *zTagname = db_column_text(&q, 1); const char *zSrcUuid = db_column_text(&q, 2); const char *zValue = db_column_text(&q, 3); const char *zDate = db_column_text(&q, 4); int tagtype = db_column_int(&q, 5); const char *zOrigUuid = db_column_text(&q, 6); cnt++; |
︙ | ︙ | |||
469 470 471 472 473 474 475 | " datetime(omtime, 'localtime')" " FROM blob, event" " WHERE blob.rid=%d" " AND event.objid=%d", rid, rid ); sideBySide = atoi(PD("sbs","1")); | | | 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 | " datetime(omtime, 'localtime')" " FROM blob, event" " WHERE blob.rid=%d" " AND event.objid=%d", rid, rid ); sideBySide = atoi(PD("sbs","1")); if( db_step(&q)==SQLITE4_ROW ){ const char *zUuid = db_column_text(&q, 0); char *zTitle = mprintf("Check-in [%.10s]", zUuid); char *zEUser, *zEComment; const char *zUser; const char *zComment; const char *zDate; const char *zOrigDate; |
︙ | ︙ | |||
525 526 527 528 529 530 531 | if( g.perm.Admin ){ db_prepare(&q, "SELECT rcvfrom.ipaddr, user.login, datetime(rcvfrom.mtime)" " FROM blob JOIN rcvfrom USING(rcvid) LEFT JOIN user USING(uid)" " WHERE blob.rid=%d", rid ); | | | 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 | if( g.perm.Admin ){ db_prepare(&q, "SELECT rcvfrom.ipaddr, user.login, datetime(rcvfrom.mtime)" " FROM blob JOIN rcvfrom USING(rcvid) LEFT JOIN user USING(uid)" " WHERE blob.rid=%d", rid ); if( db_step(&q)==SQLITE4_ROW ){ const char *zIpAddr = db_column_text(&q, 0); const char *zUser = db_column_text(&q, 1); const char *zDate = db_column_text(&q, 2); if( zUser==0 || zUser[0]==0 ) zUser = "unknown"; @ <tr><th>Received From:</th> @ <td>%h(zUser) @ %h(zIpAddr) on %s(zDate)</td></tr> } |
︙ | ︙ | |||
552 553 554 555 556 557 558 | if( zParent && !isLeaf ){ @ | %z(href("%R/timeline?dp=%S",zUuid))both</a> } db_prepare(&q, "SELECT substr(tag.tagname,5) FROM tagxref, tag " " WHERE rid=%d AND tagtype>0 " " AND tag.tagid=tagxref.tagid " " AND +tag.tagname GLOB 'sym-*'", rid); | | | 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | if( zParent && !isLeaf ){ @ | %z(href("%R/timeline?dp=%S",zUuid))both</a> } db_prepare(&q, "SELECT substr(tag.tagname,5) FROM tagxref, tag " " WHERE rid=%d AND tagtype>0 " " AND tag.tagid=tagxref.tagid " " AND +tag.tagname GLOB 'sym-*'", rid); while( db_step(&q)==SQLITE4_ROW ){ const char *zTagName = db_column_text(&q, 0); @ | %z(href("%R/timeline?r=%T",zTagName))%h(zTagName)</a> } db_finalize(&q); @ </td></tr> @ <tr><th>Other Links:</th> @ <td> |
︙ | ︙ | |||
636 637 638 639 640 641 642 | " (SELECT name FROM filename WHERE filename.fnid=mlink.pfnid)" " FROM mlink JOIN filename ON filename.fnid=mlink.fnid" " WHERE mlink.mid=%d" " ORDER BY name /*sort*/", rid ); diffFlags = construct_diff_flags(showDiff, sideBySide); | | | 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 | " (SELECT name FROM filename WHERE filename.fnid=mlink.pfnid)" " FROM mlink JOIN filename ON filename.fnid=mlink.fnid" " WHERE mlink.mid=%d" " ORDER BY name /*sort*/", rid ); diffFlags = construct_diff_flags(showDiff, sideBySide); while( db_step(&q)==SQLITE4_ROW ){ const char *zName = db_column_text(&q,0); int mperm = db_column_int(&q, 1); const char *zOld = db_column_text(&q,2); const char *zNew = db_column_text(&q,3); const char *zOldName = db_column_text(&q, 4); append_file_change_line(zName, zOld, zNew, zOldName, diffFlags, mperm); } |
︙ | ︙ | |||
679 680 681 682 683 684 685 | " WHERE tagxref.rid=%d" " AND tag.tagid=tagxref.tagid" " AND tag.tagname LIKE 'wiki-%%'" " AND blob.rid=%d" " AND event.objid=%d", rid, rid, rid ); | | | 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 | " WHERE tagxref.rid=%d" " AND tag.tagid=tagxref.tagid" " AND tag.tagname LIKE 'wiki-%%'" " AND blob.rid=%d" " AND event.objid=%d", rid, rid, rid ); if( db_step(&q)==SQLITE4_ROW ){ const char *zName = db_column_text(&q, 0); const char *zUuid = db_column_text(&q, 1); char *zTitle = mprintf("Wiki Page %s", zName); const char *zDate = db_column_text(&q,2); const char *zUser = db_column_text(&q,3); style_header(zTitle); free(zTitle); |
︙ | ︙ | |||
775 776 777 778 779 780 781 | "SELECT datetime(mtime), coalesce(euser,user)," " coalesce(ecomment,comment), uuid" " FROM event, blob" " WHERE event.objid=%d AND type='ci'" " AND blob.rid=%d", rid, rid ); | | | 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 | "SELECT datetime(mtime), coalesce(euser,user)," " coalesce(ecomment,comment), uuid" " FROM event, blob" " WHERE event.objid=%d AND type='ci'" " AND blob.rid=%d", rid, rid ); while( db_step(&q)==SQLITE4_ROW ){ const char *zDate = db_column_text(&q, 0); const char *zUser = db_column_text(&q, 1); const char *zCom = db_column_text(&q, 2); const char *zUuid = db_column_text(&q, 3); @ Check-in hyperlink_to_uuid(zUuid); @ - %w(zCom) by |
︙ | ︙ | |||
917 918 919 920 921 922 923 | " AND a.rid=mlink.fid" " AND b.rid=mlink.mid" " AND mlink.fid=%d" " ORDER BY filename.name, event.mtime /*sort*/", TAG_BRANCH, rid ); @ <ul> | | | 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 | " AND a.rid=mlink.fid" " AND b.rid=mlink.mid" " AND mlink.fid=%d" " ORDER BY filename.name, event.mtime /*sort*/", TAG_BRANCH, rid ); @ <ul> while( db_step(&q)==SQLITE4_ROW ){ const char *zName = db_column_text(&q, 0); const char *zDate = db_column_text(&q, 1); const char *zCom = db_column_text(&q, 2); const char *zUser = db_column_text(&q, 3); const char *zVers = db_column_text(&q, 4); int mPerm = db_column_int(&q, 5); const char *zBr = db_column_text(&q, 6); |
︙ | ︙ | |||
971 972 973 974 975 976 977 | " FROM tagxref, tag, event" " WHERE tagxref.rid=%d" " AND tag.tagid=tagxref.tagid" " AND tag.tagname LIKE 'wiki-%%'" " AND event.objid=tagxref.rid", rid ); | | | 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 | " FROM tagxref, tag, event" " WHERE tagxref.rid=%d" " AND tag.tagid=tagxref.tagid" " AND tag.tagname LIKE 'wiki-%%'" " AND event.objid=tagxref.rid", rid ); while( db_step(&q)==SQLITE4_ROW ){ const char *zPagename = db_column_text(&q, 0); const char *zDate = db_column_text(&q, 1); const char *zUser = db_column_text(&q, 2); if( cnt>0 ){ @ Also wiki page }else{ @ Wiki page |
︙ | ︙ | |||
998 999 1000 1001 1002 1003 1004 | db_prepare(&q, "SELECT datetime(mtime), user, comment, type, uuid, tagid" " FROM event, blob" " WHERE event.objid=%d" " AND blob.rid=%d", rid, rid ); | | | 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 | db_prepare(&q, "SELECT datetime(mtime), user, comment, type, uuid, tagid" " FROM event, blob" " WHERE event.objid=%d" " AND blob.rid=%d", rid, rid ); while( db_step(&q)==SQLITE4_ROW ){ const char *zDate = db_column_text(&q, 0); const char *zUser = db_column_text(&q, 1); const char *zCom = db_column_text(&q, 2); const char *zType = db_column_text(&q, 3); const char *zUuid = db_column_text(&q, 4); if( cnt>0 ){ @ Also |
︙ | ︙ | |||
1039 1040 1041 1042 1043 1044 1045 | db_prepare(&q, "SELECT target, filename, datetime(mtime), user, src" " FROM attachment" " WHERE src=(SELECT uuid FROM blob WHERE rid=%d)" " ORDER BY mtime DESC /*sort*/", rid ); | | | 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 | db_prepare(&q, "SELECT target, filename, datetime(mtime), user, src" " FROM attachment" " WHERE src=(SELECT uuid FROM blob WHERE rid=%d)" " ORDER BY mtime DESC /*sort*/", rid ); while( db_step(&q)==SQLITE4_ROW ){ const char *zTarget = db_column_text(&q, 0); const char *zFilename = db_column_text(&q, 1); const char *zDate = db_column_text(&q, 2); const char *zUser = db_column_text(&q, 3); /* const char *zSrc = db_column_text(&q, 4); */ if( cnt>0 ){ @ Also attachment "%h(zFilename)" to |
︙ | ︙ | |||
1204 1205 1206 1207 1208 1209 1210 | for(i=0; i<n; i+=16){ j = 0; zLine[0] = zHex[(i>>24)&0xf]; zLine[1] = zHex[(i>>16)&0xf]; zLine[2] = zHex[(i>>8)&0xf]; zLine[3] = zHex[i&0xf]; zLine[4] = ':'; | | | 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 | for(i=0; i<n; i+=16){ j = 0; zLine[0] = zHex[(i>>24)&0xf]; zLine[1] = zHex[(i>>16)&0xf]; zLine[2] = zHex[(i>>8)&0xf]; zLine[3] = zHex[i&0xf]; zLine[4] = ':'; sqlite4_snprintf(zLine, sizeof(zLine), "%04x: ", i); for(j=0; j<16; j++){ k = 5+j*3; zLine[k] = ' '; if( i+j<n ){ unsigned char c = x[i+j]; zLine[k+1] = zHex[c>>4]; zLine[k+2] = zHex[c&0xf]; |
︙ | ︙ | |||
1851 1852 1853 1854 1855 1856 1857 | db_multi_exec("REPLACE INTO newtags VALUES('user','+',%Q)", zNewUser); } db_prepare(&q, "SELECT tag.tagid, tagname FROM tagxref, tag" " WHERE tagxref.rid=%d AND tagtype>0 AND tagxref.tagid=tag.tagid", rid ); | | | | 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 | db_multi_exec("REPLACE INTO newtags VALUES('user','+',%Q)", zNewUser); } db_prepare(&q, "SELECT tag.tagid, tagname FROM tagxref, tag" " WHERE tagxref.rid=%d AND tagtype>0 AND tagxref.tagid=tag.tagid", rid ); while( db_step(&q)==SQLITE4_ROW ){ int tagid = db_column_int(&q, 0); const char *zTag = db_column_text(&q, 1); char zLabel[30]; sqlite4_snprintf(zLabel, sizeof(zLabel), "c%d", tagid); if( P(zLabel) ){ db_multi_exec("REPLACE INTO newtags VALUES(%Q,'-',NULL)", zTag); } } db_finalize(&q); if( zCloseFlag[0] ){ db_multi_exec("REPLACE INTO newtags VALUES('closed','+',NULL)"); |
︙ | ︙ | |||
1882 1883 1884 1885 1886 1887 1888 | ); db_multi_exec("REPLACE INTO newtags VALUES('branch','*',%Q)", zNewBranch); db_multi_exec("REPLACE INTO newtags VALUES('sym-%q','*',NULL)", zNewBranch); } db_prepare(&q, "SELECT tag, prefix, value FROM newtags" " ORDER BY prefix || tag"); | | | 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 | ); db_multi_exec("REPLACE INTO newtags VALUES('branch','*',%Q)", zNewBranch); db_multi_exec("REPLACE INTO newtags VALUES('sym-%q','*',NULL)", zNewBranch); } db_prepare(&q, "SELECT tag, prefix, value FROM newtags" " ORDER BY prefix || tag"); while( db_step(&q)==SQLITE4_ROW ){ const char *zTag = db_column_text(&q, 0); const char *zPrefix = db_column_text(&q, 1); const char *zValue = db_column_text(&q, 2); nChng++; if( zValue ){ blob_appendf(&ctrl, "T %s%F %s %F\n", zPrefix, zTag, zUuid, zValue); }else{ |
︙ | ︙ | |||
1931 1932 1933 1934 1935 1936 1937 | wiki_convert(&comment, 0, WIKI_INLINE); blob_zero(&suffix); blob_appendf(&suffix, "(user: %h", zNewUser); db_prepare(&q, "SELECT substr(tagname,5) FROM tagxref, tag" " WHERE tagname GLOB 'sym-*' AND tagxref.rid=%d" " AND tagtype>1 AND tag.tagid=tagxref.tagid", rid); | | | 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 | wiki_convert(&comment, 0, WIKI_INLINE); blob_zero(&suffix); blob_appendf(&suffix, "(user: %h", zNewUser); db_prepare(&q, "SELECT substr(tagname,5) FROM tagxref, tag" " WHERE tagname GLOB 'sym-*' AND tagxref.rid=%d" " AND tagtype>1 AND tag.tagid=tagxref.tagid", rid); while( db_step(&q)==SQLITE4_ROW ){ const char *zTag = db_column_text(&q, 0); if( nTag==0 ){ blob_appendf(&suffix, ", tags: %h", zTag); }else{ blob_appendf(&suffix, ", %h", zTag); } nTag++; |
︙ | ︙ | |||
1987 1988 1989 1990 1991 1992 1993 | db_prepare(&q, "SELECT tag.tagid, tagname FROM tagxref, tag" " WHERE tagxref.rid=%d AND tagtype>0 AND tagxref.tagid=tag.tagid" " ORDER BY CASE WHEN tagname GLOB 'sym-*' THEN substr(tagname,5)" " ELSE tagname END /*sort*/", rid ); | | | | 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 | db_prepare(&q, "SELECT tag.tagid, tagname FROM tagxref, tag" " WHERE tagxref.rid=%d AND tagtype>0 AND tagxref.tagid=tag.tagid" " ORDER BY CASE WHEN tagname GLOB 'sym-*' THEN substr(tagname,5)" " ELSE tagname END /*sort*/", rid ); while( db_step(&q)==SQLITE4_ROW ){ int tagid = db_column_int(&q, 0); const char *zTagName = db_column_text(&q, 1); char zLabel[30]; sqlite4_snprintf(zLabel, sizeof(zLabel), "c%d", tagid); if( P(zLabel) ){ @ <br /><input type="checkbox" name="c%d(tagid)" checked="checked" /> }else{ @ <br /><input type="checkbox" name="c%d(tagid)" /> } if( strncmp(zTagName, "sym-", 4)==0 ){ @ Cancel tag <b>%h(&zTagName[4])</b> |
︙ | ︙ |
Changes to src/json.c.
︙ | ︙ | |||
51 52 53 54 55 56 57 | "requestId" /*requestId*/, "resultCode" /*resultCode*/, "resultText" /*resultText*/, "timestamp" /*timestamp*/ }; | | | 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | "requestId" /*requestId*/, "resultCode" /*resultCode*/, "resultText" /*resultText*/, "timestamp" /*timestamp*/ }; /* Timer code taken from sqlite4's shell.c, modified slightly. FIXME: move the timer into the fossil core API so that we can start the timer early on in the app init phase. Right now we're just timing the json ops themselves. */ #if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__) && !defined(__RTP__) && !defined(_WRS_KERNEL) #include <sys/time.h> #include <sys/resource.h> |
︙ | ︙ | |||
1043 1044 1045 1046 1047 1048 1049 | } if(g.isHTTP){ cgi_set_content_type(json_guess_content_type()) /* reminder: must be done after g.json.jsonp is initialized */ ; #if 0 | | | | 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 | } if(g.isHTTP){ cgi_set_content_type(json_guess_content_type()) /* reminder: must be done after g.json.jsonp is initialized */ ; #if 0 /* Calling this seems to trigger an SQLITE4_MISUSE warning??? Maybe it's not legal to set the logger more than once? */ sqlite4_env_config(0, SQLITE4_CONFIG_LOG, NULL, 0) /* avoids debug messages on stderr in JSON mode */ ; #endif } g.json.cmd.v = cson_value_new_array(); g.json.cmd.a = cson_value_get_array(g.json.cmd.v); |
︙ | ︙ | |||
1687 1688 1689 1690 1691 1692 1693 | */ cson_value * json_stmt_to_array_of_obj(Stmt *pStmt, cson_array * pTgt){ cson_array * a = pTgt; char const * warnMsg = NULL; cson_value * colNamesV = NULL; cson_array * colNames = NULL; | | | | | 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 | */ cson_value * json_stmt_to_array_of_obj(Stmt *pStmt, cson_array * pTgt){ cson_array * a = pTgt; char const * warnMsg = NULL; cson_value * colNamesV = NULL; cson_array * colNames = NULL; while( (SQLITE4_ROW==db_step(pStmt)) ){ cson_value * row = NULL; if(!a){ a = cson_new_array(); assert(NULL!=a); } if(!colNames){ colNamesV = cson_sqlite4_column_names(pStmt->pStmt); assert(NULL != colNamesV); cson_value_add_reference(colNamesV)/*avoids an ownership problem*/; colNames = cson_value_get_array(colNamesV); assert(NULL != colNames); } row = cson_sqlite4_row_to_object2(pStmt->pStmt, colNames); if(!row && !warnMsg){ warnMsg = "Could not convert at least one result row to JSON."; continue; } if( 0 != cson_array_append(a, row) ){ cson_value_free(row); assert( 0 && "Alloc error."); |
︙ | ︙ | |||
1730 1731 1732 1733 1734 1735 1736 | ** result set is represented as an Array of values instead of an ** Object (key/value pairs). If pTgt is NULL and the statement ** has no results then NULL is returned, not an empty array. */ cson_value * json_stmt_to_array_of_array(Stmt *pStmt, cson_array * pTgt){ cson_array * a = pTgt; | | | | | | 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 | ** result set is represented as an Array of values instead of an ** Object (key/value pairs). If pTgt is NULL and the statement ** has no results then NULL is returned, not an empty array. */ cson_value * json_stmt_to_array_of_array(Stmt *pStmt, cson_array * pTgt){ cson_array * a = pTgt; while( (SQLITE4_ROW==db_step(pStmt)) ){ cson_value * row = NULL; if(!a){ a = cson_new_array(); assert(NULL!=a); } row = cson_sqlite4_row_to_array(pStmt->pStmt); cson_array_append(a, row); } return cson_array_value(a); } cson_value * json_stmt_to_array_of_values(Stmt *pStmt, int resultColumn, cson_array * pTgt){ cson_array * a = pTgt; while( (SQLITE4_ROW==db_step(pStmt)) ){ cson_value * row = cson_sqlite4_column_to_value(pStmt->pStmt, resultColumn); if(row){ if(!a){ a = cson_new_array(); assert(NULL!=a); } cson_array_append(a, row); |
︙ | ︙ | |||
1930 1931 1932 1933 1934 1935 1936 | cson_value * json_cap_value(){ if(g.userUid<=0){ return NULL; }else{ Stmt q = empty_Stmt; cson_value * val = NULL; db_prepare(&q, "SELECT cap FROM user WHERE uid=%d", g.userUid); | | | | 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 | cson_value * json_cap_value(){ if(g.userUid<=0){ return NULL; }else{ Stmt q = empty_Stmt; cson_value * val = NULL; db_prepare(&q, "SELECT cap FROM user WHERE uid=%d", g.userUid); if( db_step(&q)==SQLITE4_ROW ){ char const * str = (char const *)sqlite4_column_text(q.pStmt,0); if( str ){ val = json_new_string(str); } } db_finalize(&q); return val; } |
︙ | ︙ | |||
1956 1957 1958 1959 1960 1961 1962 | */ cson_value * json_page_cap(){ cson_value * payload = cson_value_new_object(); cson_value * sub = cson_value_new_object(); Stmt q; cson_object * obj = cson_value_get_object(payload); db_prepare(&q, "SELECT login, cap FROM user WHERE uid=%d", g.userUid); | | | | | 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 | */ cson_value * json_page_cap(){ cson_value * payload = cson_value_new_object(); cson_value * sub = cson_value_new_object(); Stmt q; cson_object * obj = cson_value_get_object(payload); db_prepare(&q, "SELECT login, cap FROM user WHERE uid=%d", g.userUid); if( db_step(&q)==SQLITE4_ROW ){ /* reminder: we don't use g.zLogin because it's 0 for the guest user and the HTML UI appears to currently allow the name to be changed (but doing so would break other code). */ char const * str = (char const *)sqlite4_column_text(q.pStmt,0); if( str ){ cson_object_set( obj, "name", cson_value_new_string(str,strlen(str)) ); } str = (char const *)sqlite4_column_text(q.pStmt,1); if( str ){ cson_object_set( obj, "capabilities", cson_value_new_string(str,strlen(str)) ); } } db_finalize(&q); cson_object_set( obj, "permissionFlags", sub ); |
︙ | ︙ | |||
2065 2066 2067 2068 2069 2070 2071 | if( t/fsize < 5 ){ b = 10; fsize /= 10; }else{ b = 1; } a = t/fsize; | | | | | | | | | 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 | if( t/fsize < 5 ){ b = 10; fsize /= 10; }else{ b = 1; } a = t/fsize; sqlite4_snprintf(zBuf,BufLen, "%d:%d", a, b); SETBUF(jo, "compressionRatio"); } n = db_int(0, "SELECT count(distinct mid) FROM mlink /*scan*/"); cson_object_set(jo, "checkinCount", cson_value_new_integer((cson_int_t)n)); n = db_int(0, "SELECT count(*) FROM filename /*scan*/"); cson_object_set(jo, "fileCount", cson_value_new_integer((cson_int_t)n)); n = db_int(0, "SELECT count(*) FROM tag /*scan*/" " WHERE +tagname GLOB 'wiki-*'"); cson_object_set(jo, "wikiPageCount", cson_value_new_integer((cson_int_t)n)); n = db_int(0, "SELECT count(*) FROM tag /*scan*/" " WHERE +tagname GLOB 'tkt-*'"); cson_object_set(jo, "ticketCount", cson_value_new_integer((cson_int_t)n)); }/*full*/ n = db_int(0, "SELECT julianday('now') - (SELECT min(mtime) FROM event)" " + 0.99"); cson_object_set(jo, "ageDays", cson_value_new_integer((cson_int_t)n)); cson_object_set(jo, "ageYears", cson_value_new_double(n/365.24)); sqlite4_snprintf(zBuf,BufLen, db_get("project-code","")); SETBUF(jo, "projectCode"); sqlite4_snprintf(zBuf,BufLen, db_get("server-code","")); SETBUF(jo, "serverCode"); cson_object_set(jo, "compiler", cson_value_new_string(COMPILER_NAME, strlen(COMPILER_NAME))); jv2 = cson_value_new_object(); jo2 = cson_value_get_object(jv2); cson_object_set(jo, "sqlite", jv2); sqlite4_snprintf(zBuf, BufLen, "%.19s [%.10s] (%s)", SQLITE4_SOURCE_ID, &SQLITE4_SOURCE_ID[20], SQLITE4_VERSION); SETBUF(jo2, "version"); zDb = db_name("repository"); cson_object_set(jo2, "pageCount", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA %s.page_count", zDb))); cson_object_set(jo2, "pageSize", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA %s.page_size", zDb))); cson_object_set(jo2, "freeList", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA %s.freelist_count", zDb))); sqlite4_snprintf(zBuf, BufLen, "%s", db_text(0, "PRAGMA %s.encoding", zDb)); SETBUF(jo2, "encoding"); sqlite4_snprintf(zBuf, BufLen, "%s", db_text(0, "PRAGMA %s.journal_mode", zDb)); cson_object_set(jo2, "journalMode", *zBuf ? cson_value_new_string(zBuf, strlen(zBuf)) : cson_value_null()); return jv; #undef SETBUF } |
︙ | ︙ | |||
2196 2197 2198 2199 2200 2201 2202 | /* Reminder: the db_xxx() ops "should" fail via the fossil core error handlers, which will cause a JSON error and exit(). i.e. we don't handle the errors here. TODO: confirm that all these db routine fail gracefully in JSON mode. On large repos (e.g. fossil's) this operation is likely to take longer than the client timeout, which will cause it to fail (but | | | 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 | /* Reminder: the db_xxx() ops "should" fail via the fossil core error handlers, which will cause a JSON error and exit(). i.e. we don't handle the errors here. TODO: confirm that all these db routine fail gracefully in JSON mode. On large repos (e.g. fossil's) this operation is likely to take longer than the client timeout, which will cause it to fail (but it's sqlite4, so it'll fail gracefully). */ db_close(1); db_open_repository(g.zRepositoryName); db_begin_transaction(); rebuild_db(0, 0, 0); db_end_transaction(0); return NULL; |
︙ | ︙ |
Changes to src/json_artifact.c.
︙ | ︙ | |||
61 62 63 64 65 66 67 | Stmt q = empty_Stmt; cson_array * pParents = NULL; db_prepare( &q, "SELECT uuid FROM plink, blob" " WHERE plink.cid=%d AND blob.rid=plink.pid" " ORDER BY plink.isprim DESC", rid ); | | | | 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | Stmt q = empty_Stmt; cson_array * pParents = NULL; db_prepare( &q, "SELECT uuid FROM plink, blob" " WHERE plink.cid=%d AND blob.rid=plink.pid" " ORDER BY plink.isprim DESC", rid ); while( SQLITE4_ROW==db_step(&q) ){ if(!pParents) { pParents = cson_new_array(); } cson_array_append( pParents, cson_sqlite4_column_to_value( q.pStmt, 0 ) ); } db_finalize(&q); return cson_array_value(pParents); } /* ** Generates an artifact Object for the given rid, |
︙ | ︙ | |||
97 98 99 100 101 102 103 | " e.user, " " e.comment" " FROM blob b, event e" " WHERE b.rid=%d" " AND e.objid=%d", rid, rid ); | | | 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | " e.user, " " e.comment" " FROM blob b, event e" " WHERE b.rid=%d" " AND e.objid=%d", rid, rid ); if( db_step(&q)==SQLITE4_ROW ){ cson_object * o; cson_value * tmpV = NULL; const char *zUuid = db_column_text(&q, 0); const char *zUser; const char *zComment; char * zEUser, * zEComment; int mtime, omtime; |
︙ | ︙ | |||
322 323 324 325 326 327 328 | TAG_BRANCH, rid ); /* TODO: add a "state" flag for the file in each checkin, e.g. "modified", "new", "deleted". */ checkin_arr = cson_new_array(); cson_object_set(pay, "checkins", cson_array_value(checkin_arr)); | | | | 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | TAG_BRANCH, rid ); /* TODO: add a "state" flag for the file in each checkin, e.g. "modified", "new", "deleted". */ checkin_arr = cson_new_array(); cson_object_set(pay, "checkins", cson_array_value(checkin_arr)); while( (SQLITE4_ROW==db_step(&q) ) ){ cson_object * row = cson_value_get_object(cson_sqlite4_row_to_object(q.pStmt)); char const isNew = cson_value_get_bool(cson_object_get(row,"isNew")); char const isDel = cson_value_get_bool(cson_object_get(row,"isDel")); cson_object_set(row, "isNew", NULL); cson_object_set(row, "isDel", NULL); cson_object_set(row, "state", json_new_string(json_artifact_status_to_string(isNew, isDel))); cson_array_append( checkin_arr, cson_object_value(row) ); |
︙ | ︙ |
Changes to src/json_branch.c.
︙ | ︙ | |||
128 129 130 131 132 133 134 | cson_object_set(pay,"current",json_new_string(zCurrent)); } } branch_prepare_list_query(&q, which); cson_object_set(pay,"branches",listV); | | | | 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | cson_object_set(pay,"current",json_new_string(zCurrent)); } } branch_prepare_list_query(&q, which); cson_object_set(pay,"branches",listV); while((SQLITE4_ROW==db_step(&q))){ cson_value * v = cson_sqlite4_column_to_value(q.pStmt,0); if(v){ cson_array_append(list,v); }else if(!sawConversionError){ sawConversionError = mprintf("Column-to-json failed @ %s:%d", __FILE__,__LINE__); } } |
︙ | ︙ | |||
274 275 276 277 278 279 280 | /* Cancel all other symbolic tags */ db_prepare(&q, "SELECT tagname FROM tagxref, tag" " WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid" " AND tagtype>0 AND tagname GLOB 'sym-*'" " ORDER BY tagname", rootid); | | | 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | /* Cancel all other symbolic tags */ db_prepare(&q, "SELECT tagname FROM tagxref, tag" " WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid" " AND tagtype>0 AND tagname GLOB 'sym-*'" " ORDER BY tagname", rootid); while( db_step(&q)==SQLITE4_ROW ){ const char *zTag = db_column_text(&q, 0); blob_appendf(&branch, "T -%F *\n", zTag); } db_finalize(&q); blob_appendf(&branch, "U %F\n", g.zLogin); md5sum_blob(&branch, &mcksum); |
︙ | ︙ |
Changes to src/json_config.c.
︙ | ︙ | |||
148 149 150 151 152 153 154 | if( optSkinBackups ){ blob_append(&sql, " OR name GLOB 'skin:*'", -1); } blob_append(&sql," ORDER BY name", -1); db_prepare(&q, blob_str(&sql)); blob_reset(&sql); pay = cson_new_object(); | | | 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | if( optSkinBackups ){ blob_append(&sql, " OR name GLOB 'skin:*'", -1); } blob_append(&sql," ORDER BY name", -1); db_prepare(&q, blob_str(&sql)); blob_reset(&sql); pay = cson_new_object(); while( (SQLITE4_ROW==db_step(&q)) ){ cson_object_set(pay, db_column_text(&q,0), json_new_string(db_column_text(&q,1))); } db_finalize(&q); return cson_object_value(pay); } |
︙ | ︙ |
Changes to src/json_dir.c.
︙ | ︙ | |||
98 99 100 101 102 103 104 | if(zDX && (!*zDX || (0==strcmp(zDX,"/")))){ zDX = NULL; } zD = zDX ? fossil_strdup(zDX) : NULL; nD = zD ? strlen(zD)+1 : 0; while( nD>1 && zD[nD-2]=='/' ){ zD[(--nD)-1] = 0; } | | | 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | if(zDX && (!*zDX || (0==strcmp(zDX,"/")))){ zDX = NULL; } zD = zDX ? fossil_strdup(zDX) : NULL; nD = zD ? strlen(zD)+1 : 0; while( nD>1 && zD[nD-2]=='/' ){ zD[(--nD)-1] = 0; } sqlite4_create_function(g.db, "pathelement", 2, SQLITE4_UTF8, 0, pathelementFunc, 0, 0); /* Compute the temporary table "localfiles" containing the names ** of all files and subdirectories in the zD[] directory. ** ** Subdirectory names begin with "/". This causes them to sort ** first and it also gives us an easy way to distinguish files |
︙ | ︙ | |||
238 239 240 241 242 243 244 | zPayload = cson_new_object(); cson_object_set_s( zPayload, zKeyName, json_new_string((zD&&*zD) ? zD : "/") ); if( zUuid ){ cson_object_set( zPayload, "checkin", json_new_string(zUuid) ); } | | | 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | zPayload = cson_new_object(); cson_object_set_s( zPayload, zKeyName, json_new_string((zD&&*zD) ? zD : "/") ); if( zUuid ){ cson_object_set( zPayload, "checkin", json_new_string(zUuid) ); } while( (SQLITE4_ROW==db_step(&q)) ){ cson_value * name = NULL; char const * n = db_column_text(&q,0); char const isDir = ('/'==*n); zEntry = cson_new_object(); if(!zEntries){ zEntries = cson_new_array(); cson_object_set( zPayload, "entries", cson_array_value(zEntries) ); |
︙ | ︙ |
Changes to src/json_finfo.c.
︙ | ︙ | |||
115 116 117 118 119 120 121 | pay = cson_new_object(); cson_object_set(pay, "name", json_new_string(zFilename)); if( limit > 0 ){ cson_object_set(pay, "limit", json_new_int(limit)); } checkins = cson_new_array(); cson_object_set(pay, "checkins", cson_array_value(checkins)); | | | 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | pay = cson_new_object(); cson_object_set(pay, "name", json_new_string(zFilename)); if( limit > 0 ){ cson_object_set(pay, "limit", json_new_int(limit)); } checkins = cson_new_array(); cson_object_set(pay, "checkins", cson_array_value(checkins)); while( db_step(&q)==SQLITE4_ROW ){ cson_object * row = cson_new_object(); int const isNew = db_column_int(&q,9); int const isDel = db_column_int(&q,10); cson_array_append( checkins, cson_object_value(row) ); cson_object_set(row, "checkin", json_new_string( db_column_text(&q,1) )); cson_object_set(row, "uuid", json_new_string( db_column_text(&q,2) )); /*cson_object_set(row, "parentArtifact", json_new_string( db_column_text(&q,6) ));*/ |
︙ | ︙ |
Changes to src/json_login.c.
︙ | ︙ | |||
237 238 239 240 241 242 243 | /* assume we just logged out. */ db_prepare(&q, "SELECT login, cap FROM user WHERE login='nobody'"); } else{ db_prepare(&q, "SELECT login, cap FROM user WHERE uid=%d", g.userUid); } | | | | | 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | /* assume we just logged out. */ db_prepare(&q, "SELECT login, cap FROM user WHERE login='nobody'"); } else{ db_prepare(&q, "SELECT login, cap FROM user WHERE uid=%d", g.userUid); } if( db_step(&q)==SQLITE4_ROW ){ /* reminder: we don't use g.zLogin because it's 0 for the guest user and the HTML UI appears to currently allow the name to be changed (but doing so would break other code). */ char const * str; payload = cson_value_new_object(); obj = cson_value_get_object(payload); str = (char const *)sqlite4_column_text(q.pStmt,0); if( str ){ cson_object_set( obj, "name", cson_value_new_string(str,strlen(str)) ); } str = (char const *)sqlite4_column_text(q.pStmt,1); if( str ){ cson_object_set( obj, "capabilities", cson_value_new_string(str,strlen(str)) ); } if( g.json.authToken ){ cson_object_set( obj, "authToken", g.json.authToken ); } |
︙ | ︙ |
Changes to src/json_query.c.
︙ | ︙ | |||
65 66 67 68 69 70 71 | } zFmt = json_find_option_cstr2("format",NULL,"f",3); if(!zFmt) zFmt = "o"; db_prepare(&q,"%s", zSql); switch(*zFmt){ case 'a': | | | | 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | } zFmt = json_find_option_cstr2("format",NULL,"f",3); if(!zFmt) zFmt = "o"; db_prepare(&q,"%s", zSql); switch(*zFmt){ case 'a': check = cson_sqlite4_stmt_to_json(q.pStmt, &payV, 0); break; case 'o': default: check = cson_sqlite4_stmt_to_json(q.pStmt, &payV, 1); }; db_finalize(&q); if(0 != check){ json_set_err(FSL_JSON_E_UNKNOWN, "Conversion to JSON failed with cson code #%d (%s).", check, cson_rc_string(check)); assert(NULL==payV); |
︙ | ︙ |
Changes to src/json_report.c.
︙ | ︙ | |||
106 107 108 109 110 111 112 | " title AS title," " cast(strftime('%%s',mtime) as int) as timestamp," " cols as columns," " sqlcode as sqlCode" " FROM reportfmt" " WHERE rn=%d", nReport); | | | | 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | " title AS title," " cast(strftime('%%s',mtime) as int) as timestamp," " cols as columns," " sqlcode as sqlCode" " FROM reportfmt" " WHERE rn=%d", nReport); if( SQLITE4_ROW != db_step(&q) ){ db_finalize(&q); json_set_err(FSL_JSON_E_RESOURCE_NOT_FOUND, "Report #%d not found.", nReport); return NULL; } pay = cson_sqlite4_row_to_object(q.pStmt); db_finalize(&q); return pay; } /* ** Impl of /json/report/list. */ |
︙ | ︙ | |||
187 188 189 190 191 192 193 | if(!zFmt) zFmt = "o"; db_prepare(&q, "SELECT sqlcode, " " title" " FROM reportfmt" " WHERE rn=%d", nReport); | | | 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | if(!zFmt) zFmt = "o"; db_prepare(&q, "SELECT sqlcode, " " title" " FROM reportfmt" " WHERE rn=%d", nReport); if(SQLITE4_ROW != db_step(&q)){ json_set_err(FSL_JSON_E_INVALID_ARGS, "Report number %d not found.", nReport); db_finalize(&q); goto error; } |
︙ | ︙ | |||
222 223 224 225 226 227 228 | if(g.perm.TktFmt){ cson_object_set(pay, "sqlcode", cson_value_new_string(blob_str(&sql), (unsigned int)blob_size(&sql))); } blob_reset(&sql); | | | | | | 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | if(g.perm.TktFmt){ cson_object_set(pay, "sqlcode", cson_value_new_string(blob_str(&sql), (unsigned int)blob_size(&sql))); } blob_reset(&sql); colNames = cson_sqlite4_column_names(q.pStmt); cson_object_set( pay, "columnNames", colNames); for( i = 0 ; ((limit>0) ?(i < limit) : 1) && (SQLITE4_ROW == db_step(&q)); ++i){ cson_value * row = ('a'==*zFmt) ? cson_sqlite4_row_to_array(q.pStmt) : cson_sqlite4_row_to_object2(q.pStmt, cson_value_get_array(colNames)); ; if(row && !tktList){ tktList = cson_new_array(); } cson_array_append(tktList, row); } |
︙ | ︙ |
Changes to src/json_tag.c.
︙ | ︙ | |||
260 261 262 263 264 265 266 | " WHERE tagid=(SELECT tagid FROM tag WHERE tagname=%Q)" " AND tagxref.tagtype>0" " AND blob.rid=tagxref.rid" "%s LIMIT %d", zName, (limit>0)?"":"--", limit ); | | | | 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | " WHERE tagid=(SELECT tagid FROM tag WHERE tagname=%Q)" " AND tagxref.tagtype>0" " AND blob.rid=tagxref.rid" "%s LIMIT %d", zName, (limit>0)?"":"--", limit ); while( db_step(&q)==SQLITE4_ROW ){ if(!listV){ listV = cson_value_new_array(); list = cson_value_get_array(listV); } cson_array_append(list, cson_sqlite4_column_to_value(q.pStmt,0)); } db_finalize(&q); }else{ char const * zSqlBase = /*modified from timeline_query_for_tty()*/ " SELECT" #if 0 " blob.rid AS rid," |
︙ | ︙ | |||
385 386 387 388 389 390 391 | "SELECT tagname, value FROM tagxref, tag" " WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid" " AND tagtype>%d" " ORDER BY tagname", rid, fRaw ? -1 : 0 ); | | | 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | "SELECT tagname, value FROM tagxref, tag" " WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid" " AND tagtype>%d" " ORDER BY tagname", rid, fRaw ? -1 : 0 ); while( SQLITE4_ROW == db_step(&q) ){ const char *zName = db_column_text(&q, 0); const char *zValue = db_column_text(&q, 1); if( fRaw==0 ){ if( 0!=strncmp(zName, "sym-", 4) ) continue; zName += 4; assert( *zName ); } |
︙ | ︙ | |||
443 444 445 446 447 448 449 | blob_append(&sql, " AND tagname NOT GLOB('tkt-*') ", -1); } blob_append(&sql, " ORDER BY tagname", -1); db_prepare(&q, blob_buffer(&sql)); blob_reset(&sql); cson_object_set(pay, "includeTickets", cson_value_new_bool(fTicket) ); | | | 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 | blob_append(&sql, " AND tagname NOT GLOB('tkt-*') ", -1); } blob_append(&sql, " ORDER BY tagname", -1); db_prepare(&q, blob_buffer(&sql)); blob_reset(&sql); cson_object_set(pay, "includeTickets", cson_value_new_bool(fTicket) ); while( SQLITE4_ROW == db_step(&q) ){ const char *zName = db_column_text(&q, 0); if(NULL==arV){ arV = cson_value_new_array(); ar = cson_value_get_array(arV); cson_object_set(pay, "tags", arV); tagsVal = arV; } |
︙ | ︙ |
Changes to src/json_timeline.c.
︙ | ︙ | |||
301 302 303 304 305 306 307 | " blob.size as size" " FROM mlink, blob" " WHERE mid=%d AND pid!=fid" " AND blob.rid=fid " " ORDER BY name /*sort*/", rid ); | | | 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | " blob.size as size" " FROM mlink, blob" " WHERE mid=%d AND pid!=fid" " AND blob.rid=fid " " ORDER BY name /*sort*/", rid ); while( (SQLITE4_ROW == db_step(&q)) ){ cson_value * rowV = cson_value_new_object(); cson_object * row = cson_value_get_object(rowV); int const isNew = db_column_int(&q,0); int const isDel = db_column_int(&q,1); char * zDownload = NULL; if(!rowsV){ rowsV = cson_value_new_array(); |
︙ | ︙ | |||
461 462 463 464 465 466 467 | " rid AS rid" " FROM json_timeline" " ORDER BY rowid"); listV = cson_value_new_array(); list = cson_value_get_array(listV); tmp = listV; SET("timeline"); | | | 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 | " rid AS rid" " FROM json_timeline" " ORDER BY rowid"); listV = cson_value_new_array(); list = cson_value_get_array(listV); tmp = listV; SET("timeline"); while( (SQLITE4_ROW == db_step(&q) )){ /* convert each row into a JSON object...*/ int const rid = db_column_int(&q,0); cson_value * rowV = json_artifact_for_ci(rid, showFiles); cson_object * row = cson_value_get_object(rowV); if(!row){ if( !warnRowToJsonFailed ){ warnRowToJsonFailed = 1; |
︙ | ︙ | |||
613 614 615 616 617 618 619 | " FROM json_timeline" " ORDER BY rowid", -1); listV = cson_value_new_array(); list = cson_value_get_array(listV); tmp = listV; SET("timeline"); | | | | 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 | " FROM json_timeline" " ORDER BY rowid", -1); listV = cson_value_new_array(); list = cson_value_get_array(listV); tmp = listV; SET("timeline"); while( (SQLITE4_ROW == db_step(&q) )){ /* convert each row into a JSON object...*/ int rc; int const rid = db_column_int(&q,0); Manifest * pMan = NULL; cson_value * rowV; cson_object * row; /*printf("rid=%d\n",rid);*/ pMan = manifest_get(rid, CFTYPE_TICKET); if(!pMan){ /* this might be an attachment? i'm seeing this with rid 15380, uuid [1292fef05f2472108]. /json/artifact/1292fef05f2472108 returns not-found, probably because we haven't added artifact/ticket yet(?). */ continue; } rowV = cson_sqlite4_row_to_object(q.pStmt); row = cson_value_get_object(rowV); if(!row){ manifest_destroy(pMan); json_warn( FSL_JSON_W_ROW_TO_JSON_FAILED, "Could not convert at least one timeline result row to JSON." ); continue; } |
︙ | ︙ |
Changes to src/json_user.c.
︙ | ︙ | |||
87 88 89 90 91 92 93 | " login AS name," " cap AS capabilities," " info AS info," " mtime AS timestamp" " FROM user" " WHERE login=%Q", zName); | | | | | | 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | " login AS name," " cap AS capabilities," " info AS info," " mtime AS timestamp" " FROM user" " WHERE login=%Q", zName); if( (SQLITE4_ROW == db_step(&q)) ){ u = cson_sqlite4_row_to_object(q.pStmt); } db_finalize(&q); return u; } /* ** Identical to json_load_user_by_name(), but expects a user ID. Returns ** NULL if no user found with that ID. */ static cson_value * json_load_user_by_id(int uid){ cson_value * u = NULL; Stmt q; db_prepare(&q,"SELECT uid AS uid," " login AS name," " cap AS capabilities," " info AS info," " mtime AS timestamp" " FROM user" " WHERE uid=%d", uid); if( (SQLITE4_ROW == db_step(&q)) ){ u = cson_sqlite4_row_to_object(q.pStmt); } db_finalize(&q); return u; } /* |
︙ | ︙ |
Changes to src/json_wiki.c.
︙ | ︙ | |||
449 450 451 452 453 454 455 | } } blob_append(&sql," ORDER BY lower(name)", -1); db_prepare(&q,"%s", blob_str(&sql)); blob_reset(&sql); listV = cson_value_new_array(); list = cson_value_get_array(listV); | | | | 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 | } } blob_append(&sql," ORDER BY lower(name)", -1); db_prepare(&q,"%s", blob_str(&sql)); blob_reset(&sql); listV = cson_value_new_array(); list = cson_value_get_array(listV); while( SQLITE4_ROW == db_step(&q) ){ cson_value * v; if( verbose ){ char const * name = db_column_text(&q,0); v = json_get_wiki_page_by_name(name,0); }else{ v = cson_sqlite4_column_to_value(q.pStmt,0); } if(!v){ json_set_err(FSL_JSON_E_UNKNOWN, "Could not convert wiki name column to JSON."); goto error; }else if( 0 != cson_array_append( list, v ) ){ cson_value_free(v); |
︙ | ︙ |
Changes to src/leaf.c.
︙ | ︙ | |||
63 64 65 66 67 68 69 | @ AND coalesce((SELECT value FROM tagxref @ WHERE tagid=%d AND rid=plink.pid), 'trunk') @ =coalesce((SELECT value FROM tagxref @ WHERE tagid=%d AND rid=plink.cid), 'trunk') ; db_static_prepare(&q, zSql, TAG_BRANCH, TAG_BRANCH); db_bind_int(&q, ":pid", pid); | | | 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | @ AND coalesce((SELECT value FROM tagxref @ WHERE tagid=%d AND rid=plink.pid), 'trunk') @ =coalesce((SELECT value FROM tagxref @ WHERE tagid=%d AND rid=plink.cid), 'trunk') ; db_static_prepare(&q, zSql, TAG_BRANCH, TAG_BRANCH); db_bind_int(&q, ":pid", pid); if( db_step(&q)==SQLITE4_ROW ){ nNonBranch = db_column_int(&q, 0); } db_reset(&q); return nNonBranch; } |
︙ | ︙ | |||
119 120 121 122 123 124 125 | " == coalesce((SELECT value FROM tagxref" " WHERE tagid=%d AND rid=plink.cid),'trunk');", TAG_BRANCH, TAG_BRANCH ); db_bind_int(&checkIfLeaf, ":rid", rid); rc = db_step(&checkIfLeaf); db_reset(&checkIfLeaf); | | | 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | " == coalesce((SELECT value FROM tagxref" " WHERE tagid=%d AND rid=plink.cid),'trunk');", TAG_BRANCH, TAG_BRANCH ); db_bind_int(&checkIfLeaf, ":rid", rid); rc = db_step(&checkIfLeaf); db_reset(&checkIfLeaf); if( rc==SQLITE4_ROW ){ db_static_prepare(&removeLeaf, "DELETE FROM leaf WHERE rid=:rid"); db_bind_int(&removeLeaf, ":rid", rid); db_step(&removeLeaf); db_reset(&removeLeaf); }else{ db_static_prepare(&addLeaf, "INSERT OR IGNORE INTO leaf VALUES(:rid)"); db_bind_int(&addLeaf, ":rid", rid); |
︙ | ︙ | |||
161 162 163 164 165 166 167 | static Stmt parentsOf; db_static_prepare(&parentsOf, "SELECT pid FROM plink WHERE cid=:rid AND pid>0" ); db_bind_int(&parentsOf, ":rid", rid); bag_insert(&needToCheck, rid); | | | 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | static Stmt parentsOf; db_static_prepare(&parentsOf, "SELECT pid FROM plink WHERE cid=:rid AND pid>0" ); db_bind_int(&parentsOf, ":rid", rid); bag_insert(&needToCheck, rid); while( db_step(&parentsOf)==SQLITE4_ROW ){ bag_insert(&needToCheck, db_column_int(&parentsOf, 0)); } db_reset(&parentsOf); } /* ** Do all pending leaf checks. |
︙ | ︙ |
Changes to src/login.c.
︙ | ︙ | |||
424 425 426 427 428 429 430 | } /* ** SQL function for constant time comparison of two values. ** Sets result to 0 if two values are equal. */ static void constant_time_cmp_function( | | | | | | | | | 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 | } /* ** SQL function for constant time comparison of two values. ** Sets result to 0 if two values are equal. */ static void constant_time_cmp_function( sqlite4_context *context, int argc, sqlite4_value **argv ){ const unsigned char *buf1, *buf2; int len, i; unsigned char rc = 0; assert( argc==2 ); len = sqlite4_value_bytes(argv[0]); if( len==0 || len!=sqlite4_value_bytes(argv[1]) ){ rc = 1; }else{ buf1 = sqlite4_value_text(argv[0]); buf2 = sqlite4_value_text(argv[1]); for( i=0; i<len; i++ ){ rc = rc | (buf1[i] ^ buf2[i]); } } sqlite4_result_int(context, rc); } /* ** WEBPAGE: login ** WEBPAGE: logout ** WEBPAGE: my ** |
︙ | ︙ | |||
470 471 472 473 474 475 476 | int anonFlag; char *zErrMsg = ""; int uid; /* User id loged in user */ char *zSha1Pw; const char *zIpAddr; /* IP address of requestor */ login_check_credentials(); | | | 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 | int anonFlag; char *zErrMsg = ""; int uid; /* User id loged in user */ char *zSha1Pw; const char *zIpAddr; /* IP address of requestor */ login_check_credentials(); sqlite4_create_function(g.db, "constant_time_cmp", 2, SQLITE4_UTF8, 0, constant_time_cmp_function, 0, 0); zUsername = P("u"); zPasswd = P("p"); anonFlag = P("anon")!=0; if( P("out")!=0 ){ login_clear_login_data(); redirect_to_g(); |
︙ | ︙ | |||
680 681 682 683 684 685 686 | */ static int login_transfer_credentials( const char *zLogin, /* Login we are looking for */ const char *zCode, /* Project code of peer repository */ const char *zHash, /* HASH from login cookie HASH/CODE/LOGIN */ const char *zRemoteAddr /* Request comes from here */ ){ | | | | | | | < | | | | | | 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 | */ static int login_transfer_credentials( const char *zLogin, /* Login we are looking for */ const char *zCode, /* Project code of peer repository */ const char *zHash, /* HASH from login cookie HASH/CODE/LOGIN */ const char *zRemoteAddr /* Request comes from here */ ){ sqlite4 *pOther = 0; /* The other repository */ sqlite4_stmt *pStmt; /* Query against the other repository */ char *zSQL; /* SQL of the query against other repo */ char *zOtherRepo; /* Filename of the other repository */ int rc; /* Result code from SQLite library functions */ int nXfer = 0; /* Number of credentials transferred */ zOtherRepo = db_text(0, "SELECT value FROM config WHERE name='peer-repo-%q'", zCode ); if( zOtherRepo==0 ) return 0; /* No such peer repository */ rc = sqlite4_open(0, zOtherRepo, &pOther, SQLITE4_OPEN_READWRITE); if( rc==SQLITE4_OK ){ sqlite4_create_function(pOther,"now",0,SQLITE4_ANY,0,db_now_function,0,0); sqlite4_create_function(pOther, "constant_time_cmp", 2, SQLITE4_UTF8, 0, constant_time_cmp_function, 0, 0); zSQL = mprintf( "SELECT cexpire FROM user" " WHERE login=%Q" " AND ipaddr=%Q" " AND length(cap)>0" " AND length(pw)>0" " AND cexpire>julianday('now')" " AND constant_time_cmp(cookie,%Q)=0", zLogin, zRemoteAddr, zHash ); pStmt = 0; rc = sqlite4_prepare(pOther, zSQL, -1, &pStmt, 0); if( rc==SQLITE4_OK && sqlite4_step(pStmt)==SQLITE4_ROW ){ db_multi_exec( "UPDATE user SET cookie=%Q, ipaddr=%Q, cexpire=%.17g" " WHERE login=%Q", zHash, zRemoteAddr, sqlite4_column_double(pStmt, 0), zLogin ); nXfer++; } sqlite4_finalize(pStmt); } sqlite4_close(pOther); fossil_free(zOtherRepo); return nXfer; } /* ** Lookup the uid for a non-built-in user with zLogin and zCookie and ** zRemoteAddr. Return 0 if not found. |
︙ | ︙ | |||
777 778 779 780 781 782 783 | char *zRemoteAddr; /* Abbreviated IP address of the requestor */ const char *zCap = 0; /* Capability string */ const char *zPublicPages = 0; /* GLOB patterns of public pages */ /* Only run this check once. */ if( g.userUid!=0 ) return; | | | | 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 | char *zRemoteAddr; /* Abbreviated IP address of the requestor */ const char *zCap = 0; /* Capability string */ const char *zPublicPages = 0; /* GLOB patterns of public pages */ /* Only run this check once. */ if( g.userUid!=0 ) return; sqlite4_create_function(g.db, "constant_time_cmp", 2, SQLITE4_UTF8, 0, constant_time_cmp_function, 0, 0); /* If the HTTP connection is coming over 127.0.0.1 and if ** local login is disabled and if we are using HTTP and not HTTPS, ** then there is no need to check user credentials. ** ** This feature allows the "fossil ui" command to give the user ** full access rights without having to log in. */ zRemoteAddr = ipPrefix(zIpAddr = PD("REMOTE_ADDR","nil")); if( fossil_strcmp(zIpAddr, "127.0.0.1")==0 && g.useLocalauth && db_get_int("localauth",0)==0 && P("HTTPS")==0 ){ uid = db_int(0, "SELECT uid FROM user WHERE cap LIKE '%%s%%'"); g.zLogin = db_text("?", "SELECT login FROM user WHERE uid=%d", uid); zCap = "sx"; g.noPswd = 1; sqlite4_snprintf(g.zCsrfToken, sizeof(g.zCsrfToken), "localhost"); } /* Check the login cookie to see if it matches a known valid user. */ if( uid==0 && (zCookie = P(login_cookie_name()))!=0 ){ /* Parse the cookie value up into HASH/ARG/USER */ char *zHash = fossil_strdup(zCookie); |
︙ | ︙ | |||
853 854 855 856 857 858 859 | */ uid = login_find_user(zUser, zHash, zRemoteAddr); if( uid==0 && login_transfer_credentials(zUser,zArg,zHash,zRemoteAddr) ){ uid = login_find_user(zUser, zHash, zRemoteAddr); if( uid ) record_login_attempt(zUser, zIpAddr, 1); } } | | | 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 | */ uid = login_find_user(zUser, zHash, zRemoteAddr); if( uid==0 && login_transfer_credentials(zUser,zArg,zHash,zRemoteAddr) ){ uid = login_find_user(zUser, zHash, zRemoteAddr); if( uid ) record_login_attempt(zUser, zIpAddr, 1); } } sqlite4_snprintf(g.zCsrfToken, sizeof(g.zCsrfToken), "%.10s", zHash); } /* If no user found and the REMOTE_USER environment variable is set, ** then accept the value of REMOTE_USER as the user. */ if( uid==0 ){ const char *zRemoteUser = P("REMOTE_USER"); |
︙ | ︙ | |||
875 876 877 878 879 880 881 | if( uid==0 ){ uid = db_int(0, "SELECT uid FROM user WHERE login='nobody'"); if( uid==0 ){ /* If there is no user "nobody", then make one up - with no privileges */ uid = -1; zCap = ""; } | | | | 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 | if( uid==0 ){ uid = db_int(0, "SELECT uid FROM user WHERE login='nobody'"); if( uid==0 ){ /* If there is no user "nobody", then make one up - with no privileges */ uid = -1; zCap = ""; } sqlite4_snprintf(g.zCsrfToken, sizeof(g.zCsrfToken), "none"); } /* At this point, we know that uid!=0. Find the privileges associated ** with user uid. */ assert( uid!=0 ); if( zCap==0 ){ Stmt s; db_prepare(&s, "SELECT login, cap FROM user WHERE uid=%d", uid); if( db_step(&s)==SQLITE4_ROW ){ g.zLogin = db_column_malloc(&s, 0); zCap = db_column_malloc(&s, 1); } db_finalize(&s); if( zCap==0 ){ zCap = ""; } |
︙ | ︙ | |||
1313 1314 1315 1316 1317 1318 1319 | */ int login_group_sql( const char *zSql, /* The SQL to run */ const char *zPrefix, /* Prefix to each error message */ const char *zSuffix, /* Suffix to each error message */ char **pzErrorMsg /* Write error message here, if not NULL */ ){ | | | | | | | | | < | | | | | | 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 | */ int login_group_sql( const char *zSql, /* The SQL to run */ const char *zPrefix, /* Prefix to each error message */ const char *zSuffix, /* Suffix to each error message */ char **pzErrorMsg /* Write error message here, if not NULL */ ){ sqlite4 *pPeer; /* Connection to another database */ int nErr = 0; /* Number of errors seen so far */ int rc; /* Result code from subroutine calls */ char *zErr; /* SQLite error text */ char *zSelfCode; /* Project code for ourself */ Blob err; /* Accumulate errors here */ Stmt q; /* Query of all peer-* entries in CONFIG */ if( zPrefix==0 ) zPrefix = ""; if( zSuffix==0 ) zSuffix = ""; if( pzErrorMsg ) *pzErrorMsg = 0; zSelfCode = abbreviated_project_code(db_get("project-code", "x")); blob_zero(&err); db_prepare(&q, "SELECT name, value FROM config" " WHERE name GLOB 'peer-repo-*'" " AND name <> 'peer-repo-%q'" " ORDER BY +value", zSelfCode ); while( db_step(&q)==SQLITE4_ROW ){ const char *zRepoName = db_column_text(&q, 1); if( file_size(zRepoName)<0 ){ /* Silently remove non-existant repositories from the login group. */ const char *zLabel = db_column_text(&q, 0); db_multi_exec( "DELETE FROM config WHERE name GLOB 'peer-*-%q'", &zLabel[10] ); continue; } rc = sqlite4_open(0, zRepoName, &pPeer, SQLITE4_OPEN_READWRITE); if( rc!=SQLITE4_OK ){ blob_appendf(&err, "%s%s: %s%s", zPrefix, zRepoName, sqlite4_errmsg(pPeer), zSuffix); nErr++; sqlite4_close(pPeer); continue; } sqlite4_create_function(pPeer, "shared_secret", 3, SQLITE4_UTF8, 0, sha1_shared_secret_sql_function, 0, 0); sqlite4_create_function(pPeer, "now", 0,SQLITE4_ANY,0,db_now_function,0,0); zErr = 0; rc = sqlite4_exec(pPeer, zSql, 0, 0, &zErr); if( zErr ){ blob_appendf(&err, "%s%s: %s%s", zPrefix, zRepoName, zErr, zSuffix); sqlite4_free(0, zErr); nErr++; }else if( rc!=SQLITE4_OK ){ blob_appendf(&err, "%s%s: %s%s", zPrefix, zRepoName, sqlite4_errmsg(pPeer), zSuffix); nErr++; } sqlite4_close(pPeer); } db_finalize(&q); if( pzErrorMsg && blob_size(&err)>0 ){ *pzErrorMsg = fossil_strdup(blob_str(&err)); } blob_reset(&err); fossil_free(zSelfCode); |
︙ | ︙ | |||
1391 1392 1393 1394 1395 1396 1397 | const char *zRepo, /* Repository file in the login group */ const char *zLogin, /* Login name for the other repo */ const char *zPassword, /* Password to prove we are authorized to join */ const char *zNewName, /* Name of new login group if making a new one */ char **pzErrMsg /* Leave an error message here */ ){ Blob fullName; /* Blob for finding full pathnames */ | | | | 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 | const char *zRepo, /* Repository file in the login group */ const char *zLogin, /* Login name for the other repo */ const char *zPassword, /* Password to prove we are authorized to join */ const char *zNewName, /* Name of new login group if making a new one */ char **pzErrMsg /* Leave an error message here */ ){ Blob fullName; /* Blob for finding full pathnames */ sqlite4 *pOther; /* The other repository */ int rc; /* Return code from sqlite4 functions */ char *zOtherProjCode; /* Project code for pOther */ char *zPwHash; /* Password hash on pOther */ char *zSelfRepo; /* Name of our repository */ char *zSelfLabel; /* Project-name for our repository */ char *zSelfProjCode; /* Our project-code */ char *zSql; /* SQL to run on all peers */ const char *zSelf; /* The ATTACH name of our repository */ |
︙ | ︙ | |||
1431 1432 1433 1434 1435 1436 1437 | } /* Make sure the other repository is a valid Fossil database */ if( file_size(zRepo)<0 ){ *pzErrMsg = mprintf("repository file \"%s\" does not exist", zRepo); return; } | | | | | | | 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 | } /* Make sure the other repository is a valid Fossil database */ if( file_size(zRepo)<0 ){ *pzErrMsg = mprintf("repository file \"%s\" does not exist", zRepo); return; } rc = sqlite4_open(0, zRepo, &pOther, SQLITE4_OPEN_READWRITE); if( rc!=SQLITE4_OK ){ *pzErrMsg = mprintf(sqlite4_errmsg(pOther)); }else{ rc = sqlite4_exec(pOther, "SELECT count(*) FROM user", 0, 0, pzErrMsg); } sqlite4_close(pOther); if( rc ) return; /* Attach the other respository. Make sure the username/password is ** valid and has Setup permission. */ db_multi_exec("ATTACH %Q AS other", zRepo); zOtherProjCode = db_text("x", "SELECT value FROM other.config" |
︙ | ︙ |
Changes to src/main.c.
︙ | ︙ | |||
94 95 96 97 98 99 100 | /* ** All global variables are in this structure. */ struct Global { int argc; char **argv; /* Command-line arguments to the program */ int isConst; /* True if the output is unchanging */ | | | | | 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | /* ** All global variables are in this structure. */ struct Global { int argc; char **argv; /* Command-line arguments to the program */ int isConst; /* True if the output is unchanging */ sqlite4 *db; /* The connection to the databases */ sqlite4 *dbConfig; /* Separate connection for global_config table */ int useAttach; /* True if global_config is attached to repository */ int configOpen; /* True if the config database is open */ sqlite4_int64 now; /* Seconds since 1970 */ int repositoryOpen; /* True if the main repository database is open */ char *zRepositoryName; /* Name of the repository database */ const char *zMainDbType;/* "configdb", "localdb", or "repository" */ const char *zHome; /* Name of user home directory */ int localOpen; /* True if the local database is open */ char *zLocalRoot; /* The directory holding the local database */ int minPrefix; /* Number of digits needed for a distinct UUID */ |
︙ | ︙ | |||
416 417 418 419 420 421 422 | #ifdef FOSSIL_ENABLE_TCL g.tcl.argc = argc; g.tcl.argv = argv; g.tcl.interp = 0; #endif | | | 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | #ifdef FOSSIL_ENABLE_TCL g.tcl.argc = argc; g.tcl.argv = argv; g.tcl.interp = 0; #endif sqlite4_env_config(0, SQLITE4_ENVCONFIG_LOG, fossil_sqlite_log, 0); memset(&g, 0, sizeof(g)); g.now = time(0); g.argc = argc; g.argv = argv; #ifdef FOSSIL_ENABLE_JSON #if defined(NDEBUG) g.json.errorDetailParanoia = 2 /* FIXME: make configurable |
︙ | ︙ | |||
728 729 730 731 732 733 734 | /* ** Return a name for an SQLite error code */ static const char *sqlite_error_code_name(int iCode){ static char zCode[30]; switch( iCode & 0xff ){ | | | | | | | | | | | | | | | | | | | | | | | | | 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 | /* ** Return a name for an SQLite error code */ static const char *sqlite_error_code_name(int iCode){ static char zCode[30]; switch( iCode & 0xff ){ case SQLITE4_OK: return "SQLITE4_OK"; case SQLITE4_ERROR: return "SQLITE4_ERROR"; case SQLITE4_PERM: return "SQLITE4_PERM"; case SQLITE4_ABORT: return "SQLITE4_ABORT"; case SQLITE4_BUSY: return "SQLITE4_BUSY"; case SQLITE4_NOMEM: return "SQLITE4_NOMEM"; case SQLITE4_READONLY: return "SQLITE4_READONLY"; case SQLITE4_INTERRUPT: return "SQLITE4_INTERRUPT"; case SQLITE4_IOERR: return "SQLITE4_IOERR"; case SQLITE4_CORRUPT: return "SQLITE4_CORRUPT"; case SQLITE4_FULL: return "SQLITE4_FULL"; case SQLITE4_CANTOPEN: return "SQLITE4_CANTOPEN"; case SQLITE4_PROTOCOL: return "SQLITE4_PROTOCOL"; case SQLITE4_EMPTY: return "SQLITE4_EMPTY"; case SQLITE4_SCHEMA: return "SQLITE4_SCHEMA"; case SQLITE4_CONSTRAINT: return "SQLITE4_CONSTRAINT"; case SQLITE4_MISMATCH: return "SQLITE4_MISMATCH"; case SQLITE4_MISUSE: return "SQLITE4_MISUSE"; case SQLITE4_NOLFS: return "SQLITE4_NOLFS"; case SQLITE4_FORMAT: return "SQLITE4_FORMAT"; case SQLITE4_RANGE: return "SQLITE4_RANGE"; case SQLITE4_NOTADB: return "SQLITE4_NOTADB"; default: { sqlite4_snprintf(zCode, sizeof(zCode), "error code %d",iCode); } } return zCode; } /* Error logs from SQLite */ void fossil_sqlite_log(void *notUsed, int iCode, const char *zErrmsg){ |
︙ | ︙ |
Changes to src/main.mk.
︙ | ︙ | |||
306 307 308 309 310 311 312 | $(OBJDIR)/wiki.o \ $(OBJDIR)/wikiformat.o \ $(OBJDIR)/winhttp.o \ $(OBJDIR)/xfer.o \ $(OBJDIR)/xfersetup.o \ $(OBJDIR)/zip.o | | | 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | $(OBJDIR)/wiki.o \ $(OBJDIR)/wikiformat.o \ $(OBJDIR)/winhttp.o \ $(OBJDIR)/xfer.o \ $(OBJDIR)/xfersetup.o \ $(OBJDIR)/zip.o APPNAME = fossil4$(E) all: $(OBJDIR) $(APPNAME) install: $(APPNAME) mv $(APPNAME) $(INSTALLDIR) |
︙ | ︙ | |||
341 342 343 344 345 346 347 | $(TCLSH) $(SRCDIR)/../test/tester.tcl $(APPNAME) $(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION $(OBJDIR)/mkversion $(OBJDIR)/mkversion $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set # to 1. If it is set to 1, then there is no need to build or link | | | | | 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | $(TCLSH) $(SRCDIR)/../test/tester.tcl $(APPNAME) $(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION $(OBJDIR)/mkversion $(OBJDIR)/mkversion $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set # to 1. If it is set to 1, then there is no need to build or link # the sqlite4.o object. Instead, the system sqlite will be linked # using -lsqlite4. SQLITE3_OBJ.1 = SQLITE3_OBJ.0 = $(OBJDIR)/sqlite4.o SQLITE3_OBJ. = $(SQLITE3_OBJ.0) # The FOSSIL_ENABLE_TCL variable may be undefined, set to 0, or set to 1. # If it is set to 1, then we need to build the Tcl integration code and # link to the Tcl library. TCL_OBJ.0 = TCL_OBJ.1 = $(OBJDIR)/th_tcl.o |
︙ | ︙ | |||
372 373 374 375 376 377 378 | clean: rm -rf $(OBJDIR)/* $(APPNAME) $(OBJDIR)/page_index.h: $(TRANS_SRC) $(OBJDIR)/mkindex $(OBJDIR)/mkindex $(TRANS_SRC) >$@ $(OBJDIR)/headers: $(OBJDIR)/page_index.h $(OBJDIR)/makeheaders $(OBJDIR)/VERSION.h | | | 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | clean: rm -rf $(OBJDIR)/* $(APPNAME) $(OBJDIR)/page_index.h: $(TRANS_SRC) $(OBJDIR)/mkindex $(OBJDIR)/mkindex $(TRANS_SRC) >$@ $(OBJDIR)/headers: $(OBJDIR)/page_index.h $(OBJDIR)/makeheaders $(OBJDIR)/VERSION.h $(OBJDIR)/makeheaders $(OBJDIR)/add_.c:$(OBJDIR)/add.h $(OBJDIR)/allrepo_.c:$(OBJDIR)/allrepo.h $(OBJDIR)/attach_.c:$(OBJDIR)/attach.h $(OBJDIR)/bag_.c:$(OBJDIR)/bag.h $(OBJDIR)/bisect_.c:$(OBJDIR)/bisect.h $(OBJDIR)/blob_.c:$(OBJDIR)/blob.h $(OBJDIR)/branch_.c:$(OBJDIR)/branch.h $(OBJDIR)/browse_.c:$(OBJDIR)/browse.h $(OBJDIR)/captcha_.c:$(OBJDIR)/captcha.h $(OBJDIR)/cgi_.c:$(OBJDIR)/cgi.h $(OBJDIR)/checkin_.c:$(OBJDIR)/checkin.h $(OBJDIR)/checkout_.c:$(OBJDIR)/checkout.h $(OBJDIR)/clearsign_.c:$(OBJDIR)/clearsign.h $(OBJDIR)/clone_.c:$(OBJDIR)/clone.h $(OBJDIR)/comformat_.c:$(OBJDIR)/comformat.h $(OBJDIR)/configure_.c:$(OBJDIR)/configure.h $(OBJDIR)/content_.c:$(OBJDIR)/content.h $(OBJDIR)/db_.c:$(OBJDIR)/db.h $(OBJDIR)/delta_.c:$(OBJDIR)/delta.h $(OBJDIR)/deltacmd_.c:$(OBJDIR)/deltacmd.h $(OBJDIR)/descendants_.c:$(OBJDIR)/descendants.h $(OBJDIR)/diff_.c:$(OBJDIR)/diff.h $(OBJDIR)/diffcmd_.c:$(OBJDIR)/diffcmd.h $(OBJDIR)/doc_.c:$(OBJDIR)/doc.h $(OBJDIR)/encode_.c:$(OBJDIR)/encode.h $(OBJDIR)/event_.c:$(OBJDIR)/event.h $(OBJDIR)/export_.c:$(OBJDIR)/export.h $(OBJDIR)/file_.c:$(OBJDIR)/file.h $(OBJDIR)/finfo_.c:$(OBJDIR)/finfo.h $(OBJDIR)/glob_.c:$(OBJDIR)/glob.h $(OBJDIR)/graph_.c:$(OBJDIR)/graph.h $(OBJDIR)/gzip_.c:$(OBJDIR)/gzip.h $(OBJDIR)/http_.c:$(OBJDIR)/http.h $(OBJDIR)/http_socket_.c:$(OBJDIR)/http_socket.h $(OBJDIR)/http_ssl_.c:$(OBJDIR)/http_ssl.h $(OBJDIR)/http_transport_.c:$(OBJDIR)/http_transport.h $(OBJDIR)/import_.c:$(OBJDIR)/import.h $(OBJDIR)/info_.c:$(OBJDIR)/info.h $(OBJDIR)/json_.c:$(OBJDIR)/json.h $(OBJDIR)/json_artifact_.c:$(OBJDIR)/json_artifact.h $(OBJDIR)/json_branch_.c:$(OBJDIR)/json_branch.h $(OBJDIR)/json_config_.c:$(OBJDIR)/json_config.h $(OBJDIR)/json_diff_.c:$(OBJDIR)/json_diff.h $(OBJDIR)/json_dir_.c:$(OBJDIR)/json_dir.h $(OBJDIR)/json_finfo_.c:$(OBJDIR)/json_finfo.h $(OBJDIR)/json_login_.c:$(OBJDIR)/json_login.h $(OBJDIR)/json_query_.c:$(OBJDIR)/json_query.h $(OBJDIR)/json_report_.c:$(OBJDIR)/json_report.h $(OBJDIR)/json_tag_.c:$(OBJDIR)/json_tag.h $(OBJDIR)/json_timeline_.c:$(OBJDIR)/json_timeline.h $(OBJDIR)/json_user_.c:$(OBJDIR)/json_user.h $(OBJDIR)/json_wiki_.c:$(OBJDIR)/json_wiki.h $(OBJDIR)/leaf_.c:$(OBJDIR)/leaf.h $(OBJDIR)/login_.c:$(OBJDIR)/login.h $(OBJDIR)/main_.c:$(OBJDIR)/main.h $(OBJDIR)/manifest_.c:$(OBJDIR)/manifest.h $(OBJDIR)/md5_.c:$(OBJDIR)/md5.h $(OBJDIR)/merge_.c:$(OBJDIR)/merge.h $(OBJDIR)/merge3_.c:$(OBJDIR)/merge3.h $(OBJDIR)/name_.c:$(OBJDIR)/name.h $(OBJDIR)/path_.c:$(OBJDIR)/path.h $(OBJDIR)/pivot_.c:$(OBJDIR)/pivot.h $(OBJDIR)/popen_.c:$(OBJDIR)/popen.h $(OBJDIR)/pqueue_.c:$(OBJDIR)/pqueue.h $(OBJDIR)/printf_.c:$(OBJDIR)/printf.h $(OBJDIR)/rebuild_.c:$(OBJDIR)/rebuild.h $(OBJDIR)/report_.c:$(OBJDIR)/report.h $(OBJDIR)/rss_.c:$(OBJDIR)/rss.h $(OBJDIR)/schema_.c:$(OBJDIR)/schema.h $(OBJDIR)/search_.c:$(OBJDIR)/search.h $(OBJDIR)/setup_.c:$(OBJDIR)/setup.h $(OBJDIR)/sha1_.c:$(OBJDIR)/sha1.h $(OBJDIR)/shun_.c:$(OBJDIR)/shun.h $(OBJDIR)/skins_.c:$(OBJDIR)/skins.h $(OBJDIR)/sqlcmd_.c:$(OBJDIR)/sqlcmd.h $(OBJDIR)/stash_.c:$(OBJDIR)/stash.h $(OBJDIR)/stat_.c:$(OBJDIR)/stat.h $(OBJDIR)/style_.c:$(OBJDIR)/style.h $(OBJDIR)/sync_.c:$(OBJDIR)/sync.h $(OBJDIR)/tag_.c:$(OBJDIR)/tag.h $(OBJDIR)/tar_.c:$(OBJDIR)/tar.h $(OBJDIR)/th_main_.c:$(OBJDIR)/th_main.h $(OBJDIR)/timeline_.c:$(OBJDIR)/timeline.h $(OBJDIR)/tkt_.c:$(OBJDIR)/tkt.h $(OBJDIR)/tktsetup_.c:$(OBJDIR)/tktsetup.h $(OBJDIR)/undo_.c:$(OBJDIR)/undo.h $(OBJDIR)/update_.c:$(OBJDIR)/update.h $(OBJDIR)/url_.c:$(OBJDIR)/url.h $(OBJDIR)/user_.c:$(OBJDIR)/user.h $(OBJDIR)/verify_.c:$(OBJDIR)/verify.h $(OBJDIR)/vfile_.c:$(OBJDIR)/vfile.h $(OBJDIR)/wiki_.c:$(OBJDIR)/wiki.h $(OBJDIR)/wikiformat_.c:$(OBJDIR)/wikiformat.h $(OBJDIR)/winhttp_.c:$(OBJDIR)/winhttp.h $(OBJDIR)/xfer_.c:$(OBJDIR)/xfer.h $(OBJDIR)/xfersetup_.c:$(OBJDIR)/xfersetup.h $(OBJDIR)/zip_.c:$(OBJDIR)/zip.h $(SRCDIR)/sqlite4.h $(SRCDIR)/th.h $(OBJDIR)/VERSION.h touch $(OBJDIR)/headers $(OBJDIR)/headers: Makefile $(OBJDIR)/json.o $(OBJDIR)/json_artifact.o $(OBJDIR)/json_branch.o $(OBJDIR)/json_config.o $(OBJDIR)/json_diff.o $(OBJDIR)/json_dir.o $(OBJDIR)/json_finfo.o $(OBJDIR)/json_login.o $(OBJDIR)/json_query.o $(OBJDIR)/json_report.o $(OBJDIR)/json_tag.o $(OBJDIR)/json_timeline.o $(OBJDIR)/json_user.o $(OBJDIR)/json_wiki.o : $(SRCDIR)/json_detail.h Makefile: $(OBJDIR)/add_.c: $(SRCDIR)/add.c $(OBJDIR)/translate $(OBJDIR)/translate $(SRCDIR)/add.c >$(OBJDIR)/add_.c |
︙ | ︙ | |||
1056 1057 1058 1059 1060 1061 1062 | $(OBJDIR)/zip_.c: $(SRCDIR)/zip.c $(OBJDIR)/translate $(OBJDIR)/translate $(SRCDIR)/zip.c >$(OBJDIR)/zip_.c $(OBJDIR)/zip.o: $(OBJDIR)/zip_.c $(OBJDIR)/zip.h $(SRCDIR)/config.h $(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c $(OBJDIR)/zip.h: $(OBJDIR)/headers | | | | | | 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 | $(OBJDIR)/zip_.c: $(SRCDIR)/zip.c $(OBJDIR)/translate $(OBJDIR)/translate $(SRCDIR)/zip.c >$(OBJDIR)/zip_.c $(OBJDIR)/zip.o: $(OBJDIR)/zip_.c $(OBJDIR)/zip.h $(SRCDIR)/config.h $(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c $(OBJDIR)/zip.h: $(OBJDIR)/headers $(OBJDIR)/sqlite4.o: $(SRCDIR)/sqlite4.c $(XTCC) -DSQLITE4_OMIT_LOAD_EXTENSION=1 -DSQLITE4_THREADSAFE=0 -DSQLITE4_DEFAULT_FILE_FORMAT=4 -DSQLITE4_ENABLE_STAT3 -Dlocaltime=fossil_localtime -DSQLITE4_ENABLE_LOCKING_STYLE=0 -c $(SRCDIR)/sqlite4.c -o $(OBJDIR)/sqlite4.o $(OBJDIR)/shell.o: $(SRCDIR)/shell.c $(SRCDIR)/sqlite4.h $(XTCC) -Dmain=sqlite4_shell -DSQLITE4_OMIT_LOAD_EXTENSION=1 -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o $(OBJDIR)/th.o: $(SRCDIR)/th.c $(XTCC) -I$(SRCDIR) -c $(SRCDIR)/th.c -o $(OBJDIR)/th.o $(OBJDIR)/th_lang.o: $(SRCDIR)/th_lang.c $(XTCC) -I$(SRCDIR) -c $(SRCDIR)/th_lang.c -o $(OBJDIR)/th_lang.o |
︙ | ︙ |
Changes to src/makemake.tcl.
︙ | ︙ | |||
115 116 117 118 119 120 121 | xfersetup zip http_ssl } # Name of the final application # | | | 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | xfersetup zip http_ssl } # Name of the final application # set name fossil4 # The "writeln" command sends output to the target makefile. # proc writeln {args} { global output_file if {[lindex $args 0]=="-nonewline"} { puts -nonewline $output_file [lindex $args 1] |
︙ | ︙ | |||
208 209 210 211 212 213 214 | $(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION $(OBJDIR)/mkversion $(OBJDIR)/mkversion $(SRCDIR)/../manifest.uuid \ $(SRCDIR)/../manifest \ $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set # to 1. If it is set to 1, then there is no need to build or link | | | | | 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | $(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION $(OBJDIR)/mkversion $(OBJDIR)/mkversion $(SRCDIR)/../manifest.uuid \ $(SRCDIR)/../manifest \ $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set # to 1. If it is set to 1, then there is no need to build or link # the sqlite4.o object. Instead, the system sqlite will be linked # using -lsqlite4. SQLITE3_OBJ.1 = SQLITE3_OBJ.0 = $(OBJDIR)/sqlite4.o SQLITE3_OBJ. = $(SQLITE3_OBJ.0) # The FOSSIL_ENABLE_TCL variable may be undefined, set to 0, or set to 1. # If it is set to 1, then we need to build the Tcl integration code and # link to the Tcl library. TCL_OBJ.0 = TCL_OBJ.1 = $(OBJDIR)/th_tcl.o |
︙ | ︙ | |||
248 249 250 251 252 253 254 | } set mhargs {} foreach s [lsort $src] { append mhargs " \$(OBJDIR)/${s}_.c:\$(OBJDIR)/$s.h" set extra_h($s) {} } | | | 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | } set mhargs {} foreach s [lsort $src] { append mhargs " \$(OBJDIR)/${s}_.c:\$(OBJDIR)/$s.h" set extra_h($s) {} } append mhargs " \$(SRCDIR)/sqlite4.h" append mhargs " \$(SRCDIR)/th.h" #append mhargs " \$(SRCDIR)/cson_amalgamation.h" append mhargs " \$(OBJDIR)/VERSION.h" writeln "\$(OBJDIR)/page_index.h: \$(TRANS_SRC) \$(OBJDIR)/mkindex" writeln "\t\$(OBJDIR)/mkindex \$(TRANS_SRC) >$@" writeln "\$(OBJDIR)/headers:\t\$(OBJDIR)/page_index.h \$(OBJDIR)/makeheaders \$(OBJDIR)/VERSION.h" writeln "\t\$(OBJDIR)/makeheaders $mhargs" |
︙ | ︙ | |||
271 272 273 274 275 276 277 | writeln "\t\$(OBJDIR)/translate \$(SRCDIR)/$s.c >\$(OBJDIR)/${s}_.c\n" writeln "\$(OBJDIR)/$s.o:\t\$(OBJDIR)/${s}_.c \$(OBJDIR)/$s.h $extra_h($s) \$(SRCDIR)/config.h" writeln "\t\$(XTCC) -o \$(OBJDIR)/$s.o -c \$(OBJDIR)/${s}_.c\n" writeln "\$(OBJDIR)/$s.h:\t\$(OBJDIR)/headers" } | | | | | | | | | | | | | 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | writeln "\t\$(OBJDIR)/translate \$(SRCDIR)/$s.c >\$(OBJDIR)/${s}_.c\n" writeln "\$(OBJDIR)/$s.o:\t\$(OBJDIR)/${s}_.c \$(OBJDIR)/$s.h $extra_h($s) \$(SRCDIR)/config.h" writeln "\t\$(XTCC) -o \$(OBJDIR)/$s.o -c \$(OBJDIR)/${s}_.c\n" writeln "\$(OBJDIR)/$s.h:\t\$(OBJDIR)/headers" } writeln "\$(OBJDIR)/sqlite4.o:\t\$(SRCDIR)/sqlite4.c" set opt {-DSQLITE4_OMIT_LOAD_EXTENSION=1} append opt " -DSQLITE4_THREADSAFE=0 -DSQLITE4_DEFAULT_FILE_FORMAT=4" #append opt " -DSQLITE4_ENABLE_FTS3=1" append opt " -DSQLITE4_ENABLE_STAT3" append opt " -Dlocaltime=fossil_localtime" append opt " -DSQLITE4_ENABLE_LOCKING_STYLE=0" set SQLITE4_OPTIONS $opt writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/sqlite4.c -o \$(OBJDIR)/sqlite4.o\n" writeln "\$(OBJDIR)/shell.o:\t\$(SRCDIR)/shell.c \$(SRCDIR)/sqlite4.h" set opt {-Dmain=sqlite4_shell} append opt " -DSQLITE4_OMIT_LOAD_EXTENSION=1" writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/shell.c -o \$(OBJDIR)/shell.o\n" writeln "\$(OBJDIR)/th.o:\t\$(SRCDIR)/th.c" writeln "\t\$(XTCC) -I\$(SRCDIR) -c \$(SRCDIR)/th.c -o \$(OBJDIR)/th.o\n" writeln "\$(OBJDIR)/th_lang.o:\t\$(SRCDIR)/th_lang.c" writeln "\t\$(XTCC) -I\$(SRCDIR) -c \$(SRCDIR)/th_lang.c -o \$(OBJDIR)/th_lang.o\n" |
︙ | ︙ | |||
544 545 546 547 548 549 550 | test: $(OBJDIR) $(APPNAME) $(TCLSH) $(SRCDIR)/../test/tester.tcl $(APPNAME) $(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(VERSION) $(VERSION) $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h EXTRAOBJ = \ | | | 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 | test: $(OBJDIR) $(APPNAME) $(TCLSH) $(SRCDIR)/../test/tester.tcl $(APPNAME) $(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(VERSION) $(VERSION) $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h EXTRAOBJ = \ $(OBJDIR)/sqlite4.o \ $(OBJDIR)/shell.o \ $(OBJDIR)/th.o \ $(OBJDIR)/th_lang.o \ $(OBJDIR)/cson_amalgamation.o ifdef FOSSIL_ENABLE_TCL EXTRAOBJ += $(OBJDIR)/th_tcl.o |
︙ | ︙ | |||
580 581 582 583 584 585 586 | } set mhargs {} foreach s [lsort $src] { append mhargs " \$(OBJDIR)/${s}_.c:\$(OBJDIR)/$s.h" set extra_h($s) {} } | | | 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 | } set mhargs {} foreach s [lsort $src] { append mhargs " \$(OBJDIR)/${s}_.c:\$(OBJDIR)/$s.h" set extra_h($s) {} } append mhargs " \$(SRCDIR)/sqlite4.h" append mhargs " \$(SRCDIR)/th.h" append mhargs " \$(OBJDIR)/VERSION.h" writeln "\$(OBJDIR)/page_index.h: \$(TRANS_SRC) \$(OBJDIR)/mkindex" writeln "\t\$(MKINDEX) \$(TRANS_SRC) >$@" writeln "\$(OBJDIR)/headers:\t\$(OBJDIR)/page_index.h \$(OBJDIR)/makeheaders \$(OBJDIR)/VERSION.h" writeln "\t\$(MAKEHEADERS) $mhargs" writeln "\techo Done >\$(OBJDIR)/headers" |
︙ | ︙ | |||
602 603 604 605 606 607 608 | writeln "\t\$(TRANSLATE) \$(SRCDIR)/$s.c >\$(OBJDIR)/${s}_.c\n" writeln "\$(OBJDIR)/$s.o:\t\$(OBJDIR)/${s}_.c \$(OBJDIR)/$s.h $extra_h($s) \$(SRCDIR)/config.h" writeln "\t\$(XTCC) -o \$(OBJDIR)/$s.o -c \$(OBJDIR)/${s}_.c\n" writeln "$s.h:\t\$(OBJDIR)/headers" } | | | | | | | | 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 | writeln "\t\$(TRANSLATE) \$(SRCDIR)/$s.c >\$(OBJDIR)/${s}_.c\n" writeln "\$(OBJDIR)/$s.o:\t\$(OBJDIR)/${s}_.c \$(OBJDIR)/$s.h $extra_h($s) \$(SRCDIR)/config.h" writeln "\t\$(XTCC) -o \$(OBJDIR)/$s.o -c \$(OBJDIR)/${s}_.c\n" writeln "$s.h:\t\$(OBJDIR)/headers" } writeln "\$(OBJDIR)/sqlite4.o:\t\$(SRCDIR)/sqlite4.c" set opt $SQLITE4_OPTIONS writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/sqlite4.c -o \$(OBJDIR)/sqlite4.o\n" set opt {} writeln "\$(OBJDIR)/cson_amalgamation.o:\t\$(SRCDIR)/cson_amalgamation.c" writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/cson_amalgamation.c -o \$(OBJDIR)/cson_amalgamation.o -DCSON_FOSSIL_MODE\n" writeln "\$(OBJDIR)/json.o \$(OBJDIR)/json_artifact.o \$(OBJDIR)/json_branch.o \$(OBJDIR)/json_config.o \$(OBJDIR)/json_diff.o \$(OBJDIR)/json_dir.o \$(OBJDIR)/jsos_finfo.o \$(OBJDIR)/json_login.o \$(OBJDIR)/json_query.o \$(OBJDIR)/json_report.o \$(OBJDIR)/json_tag.o \$(OBJDIR)/json_timeline.o \$(OBJDIR)/json_user.o \$(OBJDIR)/json_wiki.o : \$(SRCDIR)/json_detail.h\n" writeln "\$(OBJDIR)/shell.o:\t\$(SRCDIR)/shell.c \$(SRCDIR)/sqlite4.h" set opt {-Dmain=sqlite4_shell} append opt " -DSQLITE4_OMIT_LOAD_EXTENSION=1" writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/shell.c -o \$(OBJDIR)/shell.o\n" writeln "\$(OBJDIR)/th.o:\t\$(SRCDIR)/th.c" writeln "\t\$(XTCC) -I\$(SRCDIR) -c \$(SRCDIR)/th.c -o \$(OBJDIR)/th.o\n" writeln "\$(OBJDIR)/th_lang.o:\t\$(SRCDIR)/th_lang.c" writeln "\t\$(XTCC) -I\$(SRCDIR) -c \$(SRCDIR)/th_lang.c -o \$(OBJDIR)/th_lang.o\n" |
︙ | ︙ | |||
668 669 670 671 672 673 674 | SSL = CFLAGS = -o BCC = $(DMDIR)\bin\dmc $(CFLAGS) TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL) LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32 } | | | | 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 | SSL = CFLAGS = -o BCC = $(DMDIR)\bin\dmc $(CFLAGS) TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL) LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32 } writeln "SQLITE4_OPTIONS = $SQLITE4_OPTIONS\n" writeln -nonewline "SRC = " foreach s [lsort $src] { writeln -nonewline "${s}_.c " } writeln "\n" writeln -nonewline "OBJ = " foreach s [lsort $src] { writeln -nonewline "\$(OBJDIR)\\$s\$O " } writeln "\$(OBJDIR)\\shell\$O \$(OBJDIR)\\sqlite4\$O \$(OBJDIR)\\th\$O \$(OBJDIR)\\th_lang\$O " writeln { RC=$(DMDIR)\bin\rcc RCFLAGS=-32 -w1 -I$(SRCDIR) /D__DMC__ APPNAME = $(OBJDIR)\fossil$(E) |
︙ | ︙ | |||
700 701 702 703 704 705 706 | $(RC) $(RCFLAGS) -o$@ $** $(OBJDIR)\link: $B\win\Makefile.dmc $(OBJDIR)\fossil.res} writeln -nonewline "\t+echo " foreach s [lsort $src] { writeln -nonewline "$s " } | | | | | | 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 | $(RC) $(RCFLAGS) -o$@ $** $(OBJDIR)\link: $B\win\Makefile.dmc $(OBJDIR)\fossil.res} writeln -nonewline "\t+echo " foreach s [lsort $src] { writeln -nonewline "$s " } writeln "shell sqlite4 th th_lang > \$@" writeln "\t+echo fossil >> \$@" writeln "\t+echo fossil >> \$@" writeln "\t+echo \$(LIBS) >> \$@" writeln "\t+echo. >> \$@" writeln "\t+echo fossil >> \$@" writeln { translate$E: $(SRCDIR)\translate.c $(BCC) -o$@ $** makeheaders$E: $(SRCDIR)\makeheaders.c $(BCC) -o$@ $** mkindex$E: $(SRCDIR)\mkindex.c $(BCC) -o$@ $** version$E: $B\src\mkversion.c $(BCC) -o$@ $** $(OBJDIR)\shell$O : $(SRCDIR)\shell.c $(TCC) -o$@ -c -Dmain=sqlite4_shell $(SQLITE4_OPTIONS) $** $(OBJDIR)\sqlite4$O : $(SRCDIR)\sqlite4.c $(TCC) -o$@ -c $(SQLITE4_OPTIONS) $** $(OBJDIR)\th$O : $(SRCDIR)\th.c $(TCC) -o$@ -c $** $(OBJDIR)\th_lang$O : $(SRCDIR)\th_lang.c $(TCC) -o$@ -c $** |
︙ | ︙ | |||
776 777 778 779 780 781 782 | writeln "\t+translate\$E \$** > \$@\n" } writeln -nonewline "headers: makeheaders\$E page_index.h VERSION.h\n\t +makeheaders\$E " foreach s [lsort $src] { writeln -nonewline "${s}_.c:$s.h " } | | | 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 | writeln "\t+translate\$E \$** > \$@\n" } writeln -nonewline "headers: makeheaders\$E page_index.h VERSION.h\n\t +makeheaders\$E " foreach s [lsort $src] { writeln -nonewline "${s}_.c:$s.h " } writeln "\$(SRCDIR)\\sqlite4.h \$(SRCDIR)\\th.h VERSION.h \$(SRCDIR)\\cson_amalgamation.h" writeln "\t@copy /Y nul: headers" close $output_file # # End of the win/Makefile.dmc output ############################################################################## ############################################################################## |
︙ | ︙ | |||
833 834 835 836 837 838 839 | CFLAGS = -nologo -MT -O2 BCC = $(CC) $(CFLAGS) TCC = $(CC) -c $(CFLAGS) $(MSCDEF) $(SSL) $(INCL) LIBS = $(ZLIB) ws2_32.lib advapi32.lib $(SSLLIB) LIBDIR = -LIBPATH:$(MSCDIR)\extra\lib -LIBPATH:$(ZLIBDIR) } | | | | | | 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 | CFLAGS = -nologo -MT -O2 BCC = $(CC) $(CFLAGS) TCC = $(CC) -c $(CFLAGS) $(MSCDEF) $(SSL) $(INCL) LIBS = $(ZLIB) ws2_32.lib advapi32.lib $(SSLLIB) LIBDIR = -LIBPATH:$(MSCDIR)\extra\lib -LIBPATH:$(ZLIBDIR) } regsub -all {[-]D} $SQLITE4_OPTIONS {/D} MSC_SQLITE4_OPTIONS writeln "SQLITE4_OPTIONS = $MSC_SQLITE4_OPTIONS\n" writeln -nonewline "SRC = " foreach s [lsort $src] { writeln -nonewline "${s}_.c " } writeln "\n" writeln -nonewline "OBJ = " foreach s [lsort $src] { writeln -nonewline "\$(OX)\\$s\$O " } writeln "\$(OX)\\shell\$O \$(OX)\\sqlite4\$O \$(OX)\\th\$O \$(OX)\\th_lang\$O " writeln { APPNAME = $(OX)\fossil$(E) all: $(OX) $(APPNAME) $(APPNAME) : translate$E mkindex$E headers $(OBJ) $(OX)\linkopts cd $(OX) link /NODEFAULTLIB:msvcrt -OUT:$@ $(LIBDIR) @linkopts $(OX)\linkopts: $B\win\Makefile.msc} set redir {>} foreach s [lsort [concat $src {shell sqlite4 th th_lang}]] { writeln "\techo \$(OX)\\$s.obj $redir \$@" set redir {>>} } writeln "\techo \$(LIBS) >> \$@\n\n" writeln { |
︙ | ︙ | |||
881 882 883 884 885 886 887 | mkindex$E: $(SRCDIR)\mkindex.c $(BCC) $** mkversion$E: $B\src\mkversion.c $(BCC) $** $(OX)\shell$O : $(SRCDIR)\shell.c | | | | | 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 | mkindex$E: $(SRCDIR)\mkindex.c $(BCC) $** mkversion$E: $B\src\mkversion.c $(BCC) $** $(OX)\shell$O : $(SRCDIR)\shell.c $(TCC) /Fo$@ /Dmain=sqlite4_shell $(SQLITE4_OPTIONS) -c $(SRCDIR)\shell.c $(OX)\sqlite4$O : $(SRCDIR)\sqlite4.c $(TCC) /Fo$@ -c $(SQLITE4_OPTIONS) $** $(OX)\th$O : $(SRCDIR)\th.c $(TCC) /Fo$@ -c $** $(OX)\th_lang$O : $(SRCDIR)\th_lang.c $(TCC) /Fo$@ -c $** |
︙ | ︙ | |||
935 936 937 938 939 940 941 | writeln "\ttranslate\$E \$** > \$@\n" } writeln -nonewline "headers: makeheaders\$E page_index.h VERSION.h\n\tmakeheaders\$E " foreach s [lsort $src] { writeln -nonewline "${s}_.c:$s.h " } | | | 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 | writeln "\ttranslate\$E \$** > \$@\n" } writeln -nonewline "headers: makeheaders\$E page_index.h VERSION.h\n\tmakeheaders\$E " foreach s [lsort $src] { writeln -nonewline "${s}_.c:$s.h " } writeln "\$(SRCDIR)\\sqlite4.h \$(SRCDIR)\\th.h VERSION.h \$(SRCDIR)\\cson_amalgamation.h" writeln "\t@copy /Y nul: headers" close $output_file # # End of the win/Makefile.msc output ############################################################################## |
︙ | ︙ | |||
1035 1036 1037 1038 1039 1040 1041 | # define the special utilities files, needed to generate # the automatically generated source files UTILS=translate.exe mkindex.exe makeheaders.exe UTILS_OBJ=$(UTILS:.exe=.obj) UTILS_SRC=$(foreach uf,$(UTILS),$(SRCDIR)$(uf:.exe=.c)) # define the sqlite files, which need special flags on compile | | | | | 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 | # define the special utilities files, needed to generate # the automatically generated source files UTILS=translate.exe mkindex.exe makeheaders.exe UTILS_OBJ=$(UTILS:.exe=.obj) UTILS_SRC=$(foreach uf,$(UTILS),$(SRCDIR)$(uf:.exe=.c)) # define the sqlite files, which need special flags on compile SQLITESRC=sqlite4.c ORIGSQLITESRC=$(foreach sf,$(SQLITESRC),$(SRCDIR)$(sf)) SQLITEOBJ=$(foreach sf,$(SQLITESRC),$(sf:.c=.obj)) SQLITEDEFINES=-DSQLITE4_OMIT_LOAD_EXTENSION=1 -DSQLITE4_THREADSAFE=0 -DSQLITE4_DEFAULT_FILE_FORMAT=4 -Dlocaltime=fossil_localtime -DSQLITE4_ENABLE_LOCKING_STYLE=0 # define the sqlite shell files, which need special flags on compile SQLITESHELLSRC=shell.c ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf)) SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj)) SQLITESHELLDEFINES=-Dmain=sqlite4_shell -DSQLITE4_OMIT_LOAD_EXTENSION=1 # define the th scripting files, which need special flags on compile THSRC=th.c th_lang.c ORIGTHSRC=$(foreach sf,$(THSRC),$(SRCDIR)$(sf)) THOBJ=$(foreach sf,$(THSRC),$(sf:.c=.obj)) # define the zlib files, needed by this compile |
︙ | ︙ | |||
1100 1101 1102 1103 1104 1105 1106 | mkindex.exe $(TRANSLATEDSRC) >$@ # extracting version info from manifest VERSION.h: version.exe ..\manifest.uuid ..\manifest ..\VERSION version.exe ..\manifest.uuid ..\manifest ..\VERSION > $@ # generate the simplified headers | | | | 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 | mkindex.exe $(TRANSLATEDSRC) >$@ # extracting version info from manifest VERSION.h: version.exe ..\manifest.uuid ..\manifest ..\VERSION version.exe ..\manifest.uuid ..\manifest ..\VERSION > $@ # generate the simplified headers headers: makeheaders.exe page_index.h VERSION.h ../src/sqlite4.h ../src/th.h VERSION.h makeheaders.exe $(foreach ts,$(TRANSLATEDSRC),$(ts):$(ts:_.c=.h)) ../src/sqlite4.h ../src/th.h VERSION.h echo Done >$@ # compile C sources with relevant options $(TRANSLATEDOBJ): %_.obj: %_.c %.h $(CC) $(CCFLAGS) $(INCLUDE) "$<" -Fo"$@" |
︙ | ︙ |
Changes to src/manifest.c.
︙ | ︙ | |||
962 963 964 965 966 967 968 | ** Parse the manifest and discarded. Use for testing only. */ void manifest_test_parse_cmd(void){ Manifest *p; Blob b; int i; int n = 1; | | | 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 | ** Parse the manifest and discarded. Use for testing only. */ void manifest_test_parse_cmd(void){ Manifest *p; Blob b; int i; int n = 1; sqlite4_open(0, ":memory:", &g.db, SQLITE4_OPEN_READWRITE); if( g.argc!=3 && g.argc!=4 ){ usage("FILENAME"); } blob_read_from_file(&b, g.argv[2]); if( g.argc>3 ) n = atoi(g.argv[3]); for(i=0; i<n; i++){ Blob b2; |
︙ | ︙ | |||
1086 1087 1088 1089 1090 1091 1092 | */ static int filename_to_fnid(const char *zFilename){ static Stmt q1, s1; int fnid; db_static_prepare(&q1, "SELECT fnid FROM filename WHERE name=:fn"); db_bind_text(&q1, ":fn", zFilename); fnid = 0; | | | 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 | */ static int filename_to_fnid(const char *zFilename){ static Stmt q1, s1; int fnid; db_static_prepare(&q1, "SELECT fnid FROM filename WHERE name=:fn"); db_bind_text(&q1, ":fn", zFilename); fnid = 0; if( db_step(&q1)==SQLITE4_ROW ){ fnid = db_column_int(&q1, 0); } db_reset(&q1); if( fnid==0 ){ db_static_prepare(&s1, "INSERT INTO filename(name) VALUES(:fn)"); db_bind_text(&s1, ":fn", zFilename); db_exec(&s1); |
︙ | ︙ | |||
1281 1282 1283 1284 1285 1286 1287 | /* If mlink table entires are already set for cid, then abort early ** doing no work. */ db_static_prepare(&eq, "SELECT 1 FROM mlink WHERE mid=:mid"); db_bind_int(&eq, ":mid", cid); rc = db_step(&eq); db_reset(&eq); | | | 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 | /* If mlink table entires are already set for cid, then abort early ** doing no work. */ db_static_prepare(&eq, "SELECT 1 FROM mlink WHERE mid=:mid"); db_bind_int(&eq, ":mid", cid); rc = db_step(&eq); db_reset(&eq); if( rc==SQLITE4_ROW ) return; /* Compute the value of the missing pParent or pChild parameter. ** Fetch the baseline checkins for both. */ assert( pParent==0 || pChild==0 ); if( pParent==0 ){ ppOther = &pParent; |
︙ | ︙ | |||
1444 1445 1446 1447 1448 1449 1450 | ** Finish up a sequence of manifest_crosslink calls. */ void manifest_crosslink_end(void){ Stmt q, u; int i; assert( manifest_crosslink_busy==1 ); db_prepare(&q, "SELECT uuid FROM pending_tkt"); | | | 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 | ** Finish up a sequence of manifest_crosslink calls. */ void manifest_crosslink_end(void){ Stmt q, u; int i; assert( manifest_crosslink_busy==1 ); db_prepare(&q, "SELECT uuid FROM pending_tkt"); while( db_step(&q)==SQLITE4_ROW ){ const char *zUuid = db_column_text(&q, 0); ticket_rebuild_entry(zUuid); } db_finalize(&q); db_multi_exec("DROP TABLE pending_tkt"); /* If multiple check-ins happen close together in time, adjust their |
︙ | ︙ | |||
1467 1468 1469 1470 1471 1472 1473 | db_prepare(&u, "UPDATE time_fudge SET m2=" "(SELECT x.m1 FROM time_fudge AS x WHERE x.mid=time_fudge.cid)" ); for(i=0; i<30; i++){ db_step(&q); db_reset(&q); | | | 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 | db_prepare(&u, "UPDATE time_fudge SET m2=" "(SELECT x.m1 FROM time_fudge AS x WHERE x.mid=time_fudge.cid)" ); for(i=0; i<30; i++){ db_step(&q); db_reset(&q); if( sqlite4_changes(g.db)==0 ) break; db_step(&u); db_reset(&u); } db_finalize(&q); db_finalize(&u); db_multi_exec( "UPDATE event SET mtime=(SELECT m1 FROM time_fudge WHERE mid=objid)" |
︙ | ︙ | |||
1623 1624 1625 1626 1627 1628 1629 | "VALUES(%d, %d, %d, %.17g)", pid, rid, i==0, p->rDate); if( i==0 ){ add_mlink(pid, 0, rid, p); parentid = pid; } } db_prepare(&q, "SELECT cid FROM plink WHERE pid=%d AND isprim", rid); | | | 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 | "VALUES(%d, %d, %d, %.17g)", pid, rid, i==0, p->rDate); if( i==0 ){ add_mlink(pid, 0, rid, p); parentid = pid; } } db_prepare(&q, "SELECT cid FROM plink WHERE pid=%d AND isprim", rid); while( db_step(&q)==SQLITE4_ROW ){ int cid = db_column_int(&q, 0); add_mlink(rid, p, cid, 0); } db_finalize(&q); if( p->nParent==0 ){ /* For root files (files without parents) add mlink entries ** showing all content as new. */ |
︙ | ︙ | |||
1725 1726 1727 1728 1729 1730 1731 | int tagid = tag_findid(zTag, 1); int prior; char *zComment; int nWiki; char zLength[40]; while( fossil_isspace(p->zWiki[0]) ) p->zWiki++; nWiki = strlen(p->zWiki); | | | 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 | int tagid = tag_findid(zTag, 1); int prior; char *zComment; int nWiki; char zLength[40]; while( fossil_isspace(p->zWiki[0]) ) p->zWiki++; nWiki = strlen(p->zWiki); sqlite4_snprintf(zLength, sizeof(zLength), "%d", nWiki); tag_insert(zTag, 1, zLength, rid, p->rDate, rid); free(zTag); prior = db_int(0, "SELECT rid FROM tagxref" " WHERE tagid=%d AND mtime<%.17g" " ORDER BY mtime DESC", tagid, p->rDate |
︙ | ︙ | |||
1765 1766 1767 1768 1769 1770 1771 | char *zTag = mprintf("event-%s", p->zEventId); int tagid = tag_findid(zTag, 1); int prior, subsequent; int nWiki; char zLength[40]; while( fossil_isspace(p->zWiki[0]) ) p->zWiki++; nWiki = strlen(p->zWiki); | | | 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 | char *zTag = mprintf("event-%s", p->zEventId); int tagid = tag_findid(zTag, 1); int prior, subsequent; int nWiki; char zLength[40]; while( fossil_isspace(p->zWiki[0]) ) p->zWiki++; nWiki = strlen(p->zWiki); sqlite4_snprintf(zLength, sizeof(zLength), "%d", nWiki); tag_insert(zTag, 1, zLength, rid, p->rDate, rid); free(zTag); prior = db_int(0, "SELECT rid FROM tagxref" " WHERE tagid=%d AND mtime<%.17g AND rid!=%d" " ORDER BY mtime DESC", tagid, p->rDate, rid |
︙ | ︙ |
Changes to src/md5.c.
︙ | ︙ | |||
16 17 18 19 20 21 22 | * To compute the message digest of a chunk of bytes, declare an * MD5Context structure, pass it to MD5Init, call MD5Update as * needed on buffers full of bytes, and then call MD5Final, which * will fill a supplied 16-byte array with the digest. */ #include <string.h> #include <stdio.h> | | | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | * To compute the message digest of a chunk of bytes, declare an * MD5Context structure, pass it to MD5Init, call MD5Update as * needed on buffers full of bytes, and then call MD5Final, which * will fill a supplied 16-byte array with the digest. */ #include <string.h> #include <stdio.h> #include <sqlite4.h> #include "md5.h" /* * If compiled on a machine that doesn't have a 32-bit integer, * you just set "uint32" to the appropriate datatype for an * unsigned 32-bit integer. For example: * |
︙ | ︙ | |||
335 336 337 338 339 340 341 | pFirst = (unsigned int*)&incrCtx; pLast = (unsigned int*)((&incrCtx)+1); while( pFirst<pLast ){ cksum += *pFirst; pFirst++; } | | | 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | pFirst = (unsigned int*)&incrCtx; pLast = (unsigned int*)((&incrCtx)+1); while( pFirst<pLast ){ cksum += *pFirst; pFirst++; } sqlite4_snprintf(zResult, sizeof(zResult), "%08x", cksum); return zResult; } /* ** Finish the incremental MD5 checksum. Store the result in blob pOut ** if pOut!=0. Also return a pointer to the result. ** |
︙ | ︙ |
Changes to src/merge.c.
︙ | ︙ | |||
31 32 33 34 35 36 37 | "SELECT datetime(mtime,'localtime')," " coalesce(euser,user), coalesce(ecomment,comment)," " (SELECT uuid FROM blob WHERE rid=%d)," " (SELECT group_concat(substr(tagname,5), ', ') FROM tag, tagxref" " WHERE tagname GLOB 'sym-*' AND tag.tagid=tagxref.tagid" " AND tagxref.rid=%d AND tagxref.tagtype>0)" " FROM event WHERE objid=%d", rid, rid, rid); | | | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | "SELECT datetime(mtime,'localtime')," " coalesce(euser,user), coalesce(ecomment,comment)," " (SELECT uuid FROM blob WHERE rid=%d)," " (SELECT group_concat(substr(tagname,5), ', ') FROM tag, tagxref" " WHERE tagname GLOB 'sym-*' AND tag.tagid=tagxref.tagid" " AND tagxref.rid=%d AND tagxref.tagtype>0)" " FROM event WHERE objid=%d", rid, rid, rid); if( db_step(&q)==SQLITE4_ROW ){ const char *zTagList = db_column_text(&q, 4); char *zCom; if( zTagList && zTagList[0] ){ zCom = mprintf("%s (%s)", db_column_text(&q, 2), zTagList); }else{ zCom = mprintf("%s", db_column_text(&q,2)); } |
︙ | ︙ | |||
156 157 158 159 160 161 162 | if( pid<=0 ){ fossil_fatal("cannot find an ancestor for %s", g.argv[2]); } }else{ pivot_set_primary(mid); pivot_set_secondary(vid); db_prepare(&q, "SELECT merge FROM vmerge WHERE id=0"); | | | 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | if( pid<=0 ){ fossil_fatal("cannot find an ancestor for %s", g.argv[2]); } }else{ pivot_set_primary(mid); pivot_set_secondary(vid); db_prepare(&q, "SELECT merge FROM vmerge WHERE id=0"); while( db_step(&q)==SQLITE4_ROW ){ pivot_set_secondary(db_column_int(&q,0)); } db_finalize(&q); pid = pivot_find(); if( pid<=0 ){ fossil_fatal("cannot find a common ancestor between the current " "checkout and %s", g.argv[2]); |
︙ | ︙ | |||
307 308 309 310 311 312 313 | ); if( debugFlag ){ db_prepare(&q, "SELECT rowid, fn, fnp, fnm, chnged, ridv, ridp, ridm, " " isexe, islinkv, islinkm FROM fv" ); | | | 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | ); if( debugFlag ){ db_prepare(&q, "SELECT rowid, fn, fnp, fnm, chnged, ridv, ridp, ridm, " " isexe, islinkv, islinkm FROM fv" ); while( db_step(&q)==SQLITE4_ROW ){ fossil_print("%3d: ridv=%-4d ridp=%-4d ridm=%-4d chnged=%d isexe=%d " " islinkv=%d islinkm=%d\n", db_column_int(&q, 0), db_column_int(&q, 5), db_column_int(&q, 6), db_column_int(&q, 7), db_column_int(&q, 4), |
︙ | ︙ | |||
333 334 335 336 337 338 339 | ** Find files in M and V but not in P and report conflicts. ** The file in M will be ignored. It will be treated as if it ** does not exist. */ db_prepare(&q, "SELECT idm FROM fv WHERE idp=0 AND idv>0 AND idm>0" ); | | | | 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | ** Find files in M and V but not in P and report conflicts. ** The file in M will be ignored. It will be treated as if it ** does not exist. */ db_prepare(&q, "SELECT idm FROM fv WHERE idp=0 AND idv>0 AND idm>0" ); while( db_step(&q)==SQLITE4_ROW ){ int idm = db_column_int(&q, 0); char *zName = db_text(0, "SELECT pathname FROM vfile WHERE id=%d", idm); fossil_warning("WARNING - no common ancestor: %s\n", zName); free(zName); db_multi_exec("UPDATE fv SET idm=0 WHERE idm=%d", idm); } db_finalize(&q); /* ** Add to V files that are not in V or P but are in M */ db_prepare(&q, "SELECT idm, rowid, fnm FROM fv AS x" " WHERE idp=0 AND idv=0 AND idm>0" ); while( db_step(&q)==SQLITE4_ROW ){ int idm = db_column_int(&q, 0); int rowid = db_column_int(&q, 1); int idv; const char *zName; char *zFullName; db_multi_exec( "INSERT INTO vfile(vid,chnged,deleted,rid,mrid,isexe,islink,pathname)" |
︙ | ︙ | |||
387 388 389 390 391 392 393 | ** Copy the M content over into V. */ db_prepare(&q, "SELECT idv, ridm, fn, islinkm FROM fv" " WHERE idp>0 AND idv>0 AND idm>0" " AND ridm!=ridp AND ridv=ridp AND NOT chnged" ); | | | 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | ** Copy the M content over into V. */ db_prepare(&q, "SELECT idv, ridm, fn, islinkm FROM fv" " WHERE idp>0 AND idv>0 AND idm>0" " AND ridm!=ridp AND ridv=ridp AND NOT chnged" ); while( db_step(&q)==SQLITE4_ROW ){ int idv = db_column_int(&q, 0); int ridm = db_column_int(&q, 1); const char *zName = db_column_text(&q, 2); int islinkm = db_column_int(&q, 3); /* Copy content from idm over into idv. Overwrite idv. */ fossil_print("UPDATE %s\n", zName); if( !nochangeFlag ){ |
︙ | ︙ | |||
414 415 416 417 418 419 420 | */ db_prepare(&q, "SELECT ridm, idv, ridp, ridv, %s, fn, isexe, islinkv, islinkm FROM fv" " WHERE idp>0 AND idv>0 AND idm>0" " AND ridm!=ridp AND (ridv!=ridp OR chnged)", glob_expr("fv.fn", zBinGlob) ); | | | 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | */ db_prepare(&q, "SELECT ridm, idv, ridp, ridv, %s, fn, isexe, islinkv, islinkm FROM fv" " WHERE idp>0 AND idv>0 AND idm>0" " AND ridm!=ridp AND (ridv!=ridp OR chnged)", glob_expr("fv.fn", zBinGlob) ); while( db_step(&q)==SQLITE4_ROW ){ int ridm = db_column_int(&q, 0); int idv = db_column_int(&q, 1); int ridp = db_column_int(&q, 2); int ridv = db_column_int(&q, 3); int isBinary = db_column_int(&q, 4); const char *zName = db_column_text(&q, 5); int isExe = db_column_int(&q, 6); |
︙ | ︙ | |||
478 479 480 481 482 483 484 | /* ** Drop files that are in P and V but not in M */ db_prepare(&q, "SELECT idv, fn, chnged FROM fv" " WHERE idp>0 AND idv>0 AND idm=0" ); | | | 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 | /* ** Drop files that are in P and V but not in M */ db_prepare(&q, "SELECT idv, fn, chnged FROM fv" " WHERE idp>0 AND idv>0 AND idm=0" ); while( db_step(&q)==SQLITE4_ROW ){ int idv = db_column_int(&q, 0); const char *zName = db_column_text(&q, 1); int chnged = db_column_int(&q, 2); /* Delete the file idv */ fossil_print("DELETE %s\n", zName); if( chnged ){ fossil_warning("WARNING: local edits lost for %s\n", zName); |
︙ | ︙ | |||
509 510 511 512 513 514 515 | ** name o P->V. If a file is renamed on P->V only or on both P->V and ** P->M then we retain the V name of the file. */ db_prepare(&q, "SELECT idv, fnp, fnm FROM fv" " WHERE idv>0 AND idp>0 AND idm>0 AND fnp=fn AND fnm!=fnp" ); | | | 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 | ** name o P->V. If a file is renamed on P->V only or on both P->V and ** P->M then we retain the V name of the file. */ db_prepare(&q, "SELECT idv, fnp, fnm FROM fv" " WHERE idv>0 AND idp>0 AND idm>0 AND fnp=fn AND fnm!=fnp" ); while( db_step(&q)==SQLITE4_ROW ){ int idv = db_column_int(&q, 0); const char *zOldName = db_column_text(&q, 1); const char *zNewName = db_column_text(&q, 2); fossil_print("RENAME %s -> %s\n", zOldName, zNewName); undo_save(zOldName); undo_save(zNewName); db_multi_exec( |
︙ | ︙ |
Changes to src/name.c.
︙ | ︙ | |||
160 161 162 163 164 165 166 | /* symbolic-name ":" date-time */ nTag = strlen(zTag); for(i=0; i<nTag-10 && zTag[i]!=':'; i++){} if( zTag[i]==':' && is_date(&zTag[i+1]) ){ char *zDate = mprintf("%s", &zTag[i+1]); char *zTagBase = mprintf("%.*s", i, zTag); int nDate = strlen(zDate); | | | 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | /* symbolic-name ":" date-time */ nTag = strlen(zTag); for(i=0; i<nTag-10 && zTag[i]!=':'; i++){} if( zTag[i]==':' && is_date(&zTag[i+1]) ){ char *zDate = mprintf("%s", &zTag[i+1]); char *zTagBase = mprintf("%.*s", i, zTag); int nDate = strlen(zDate); if( sqlite4_strnicmp(&zDate[nDate-3],"utc",3)==0 ){ zDate[nDate-3] = 'z'; zDate[nDate-2] = 0; } rid = db_int(0, "SELECT event.objid" " FROM tag, tagxref, event" " WHERE tag.tagname='sym-%q' " |
︙ | ︙ | |||
197 198 199 200 201 202 203 | " FROM blob, event" " WHERE blob.uuid GLOB '%s*'" " AND event.objid=blob.rid" " AND event.type GLOB '%q'", zUuid, zType ); } | | | | 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | " FROM blob, event" " WHERE blob.uuid GLOB '%s*'" " AND event.objid=blob.rid" " AND event.type GLOB '%q'", zUuid, zType ); } if( db_step(&q)==SQLITE4_ROW ){ rid = db_column_int(&q, 0); if( db_step(&q)==SQLITE4_ROW ) rid = -1; } db_finalize(&q); if( rid ) return rid; } /* Symbolic name */ rid = db_int(0, |
︙ | ︙ | |||
363 364 365 366 367 368 369 | style_header("Ambiguous Artifact ID"); @ <p>The artifact id <b>%h(zName)</b> is ambiguous and might @ mean any of the following: @ <ol> z = mprintf("%s", zName); canonical16(z, strlen(z)); db_prepare(&q, "SELECT uuid, rid FROM blob WHERE uuid GLOB '%q*'", z); | | | 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | style_header("Ambiguous Artifact ID"); @ <p>The artifact id <b>%h(zName)</b> is ambiguous and might @ mean any of the following: @ <ol> z = mprintf("%s", zName); canonical16(z, strlen(z)); db_prepare(&q, "SELECT uuid, rid FROM blob WHERE uuid GLOB '%q*'", z); while( db_step(&q)==SQLITE4_ROW ){ const char *zUuid = db_column_text(&q, 0); int rid = db_column_int(&q, 1); @ <li><p><a href="%s(g.zTop)/%T(zSrc)/%S(zUuid)"> @ %S(zUuid)</a> - object_description(rid, 0, 0); @ </p></li> } |
︙ | ︙ | |||
430 431 432 433 434 435 436 | " (SELECT group_concat(substr(tagname,5), ', ') FROM tag, tagxref" " WHERE tagname GLOB 'sym-*' AND tag.tagid=tagxref.tagid" " AND tagxref.rid=blob.rid AND tagxref.tagtype>0)" " FROM blob, rcvfrom" " WHERE rid=%d" " AND rcvfrom.rcvid=blob.rcvid", rid); | | | | 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 | " (SELECT group_concat(substr(tagname,5), ', ') FROM tag, tagxref" " WHERE tagname GLOB 'sym-*' AND tag.tagid=tagxref.tagid" " AND tagxref.rid=blob.rid AND tagxref.tagtype>0)" " FROM blob, rcvfrom" " WHERE rid=%d" " AND rcvfrom.rcvid=blob.rcvid", rid); if( db_step(&q)==SQLITE4_ROW ){ const char *zTagList = db_column_text(&q, 4); if( fExtra ){ fossil_print("artifact: %s (%d)\n", db_column_text(&q,0), rid); fossil_print("size: %d bytes\n", db_column_int(&q,1)); fossil_print("received: %s from %s\n", db_column_text(&q, 2), db_column_text(&q, 3)); }else{ fossil_print("artifact: %s\n", db_column_text(&q,0)); fossil_print("size: %d bytes\n", db_column_int(&q,1)); } if( zTagList && zTagList[0] ){ fossil_print("tags: %s\n", zTagList); } } db_finalize(&q); db_prepare(&q, "SELECT type, datetime(mtime,'localtime')," " coalesce(euser,user), coalesce(ecomment,comment)" " FROM event WHERE objid=%d", rid); if( db_step(&q)==SQLITE4_ROW ){ const char *zType; switch( db_column_text(&q,0)[0] ){ case 'c': zType = "Check-in"; break; case 'w': zType = "Wiki-edit"; break; case 'e': zType = "Event"; break; case 't': zType = "Ticket-change"; break; case 'g': zType = "Tag-change"; break; |
︙ | ︙ | |||
477 478 479 480 481 482 483 | " FROM mlink, filename, blob, event" " WHERE mlink.fid=%d" " AND filename.fnid=mlink.fnid" " AND event.objid=mlink.mid" " AND blob.rid=mlink.mid" " ORDER BY event.mtime DESC /*sort*/", rid); | | | 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 | " FROM mlink, filename, blob, event" " WHERE mlink.fid=%d" " AND filename.fnid=mlink.fnid" " AND event.objid=mlink.mid" " AND blob.rid=mlink.mid" " ORDER BY event.mtime DESC /*sort*/", rid); while( db_step(&q)==SQLITE4_ROW ){ fossil_print("file: %s\n", db_column_text(&q,0)); fossil_print(" part of [%.10s] by %s on %s\n", db_column_text(&q, 1), db_column_text(&q, 3), db_column_text(&q, 2)); fossil_print(" "); comment_print(db_column_text(&q,4), 10, 78); } db_finalize(&q); } } |
Changes to src/path.c.
︙ | ︙ | |||
158 159 160 161 162 163 164 | } while( path.pCurrent ){ path.nStep++; pPrev = path.pCurrent; path.pCurrent = 0; while( pPrev ){ db_bind_int(&s, ":pid", pPrev->rid); | | | 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | } while( path.pCurrent ){ path.nStep++; pPrev = path.pCurrent; path.pCurrent = 0; while( pPrev ){ db_bind_int(&s, ":pid", pPrev->rid); while( db_step(&s)==SQLITE4_ROW ){ int cid = db_column_int(&s, 0); int isParent = db_column_int(&s, 1); if( bag_find(&path.seen, cid) ) continue; p = path_new_node(cid, pPrev, isParent); if( cid==iTo ){ db_finalize(&s); path.pEnd = p; |
︙ | ︙ | |||
261 262 263 264 265 266 267 | bag_init(&you); bag_insert(&you, iYou); while( path.pCurrent ){ pPrev = path.pCurrent; path.pCurrent = 0; while( pPrev ){ db_bind_int(&s, ":cid", pPrev->rid); | | | 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | bag_init(&you); bag_insert(&you, iYou); while( path.pCurrent ){ pPrev = path.pCurrent; path.pCurrent = 0; while( pPrev ){ db_bind_int(&s, ":cid", pPrev->rid); while( db_step(&s)==SQLITE4_ROW ){ int pid = db_column_int(&s, 0); if( bag_find(pPrev->isPrim ? &you : &me, pid) ){ /* pid is the common ancestor */ PathNode *pNext; for(p=path.pAll; p && p->rid!=pid; p=p->pAll){} assert( p!=0 ); pNext = p; |
︙ | ︙ | |||
396 397 398 399 400 401 402 | for(p=path.pStart; p; p=p->u.pTo){ int fnid, pfnid; if( !p->fromIsParent && (p->u.pTo==0 || p->u.pTo->fromIsParent) ){ /* Skip nodes where the parent is not on the path */ continue; } db_bind_int(&q1, ":mid", p->rid); | | | 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 | for(p=path.pStart; p; p=p->u.pTo){ int fnid, pfnid; if( !p->fromIsParent && (p->u.pTo==0 || p->u.pTo->fromIsParent) ){ /* Skip nodes where the parent is not on the path */ continue; } db_bind_int(&q1, ":mid", p->rid); while( db_step(&q1)==SQLITE4_ROW ){ fnid = db_column_int(&q1, 1); pfnid = db_column_int(&q1, 0); if( pfnid==0 ){ pfnid = fnid; fnid = 0; } if( !p->fromIsParent ){ |
︙ | ︙ |
Changes to src/pivot.c.
︙ | ︙ | |||
123 124 125 126 127 128 129 | " 1," " aqueue.src " " FROM plink, aqueue" " WHERE plink.cid=:rid" " AND aqueue.rid=:rid" ); | | | | 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | " 1," " aqueue.src " " FROM plink, aqueue" " WHERE plink.cid=:rid" " AND aqueue.rid=:rid" ); while( db_step(&q1)==SQLITE4_ROW ){ rid = db_column_int(&q1, 0); db_reset(&q1); db_bind_int(&q2, ":rid", rid); if( db_step(&q2)==SQLITE4_ROW ){ break; } db_reset(&q2); db_bind_int(&i1, ":rid", rid); db_exec(&i1); db_bind_int(&u1, ":rid", rid); db_exec(&u1); |
︙ | ︙ |
Changes to src/printf.c.
︙ | ︙ | |||
897 898 899 900 901 902 903 | if( zA==0 ){ if( zB==0 ) return 0; return -1; }else if( zB==0 ){ return +1; } if( nByte<0 ) nByte = strlen(zB); | | | | 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 | if( zA==0 ){ if( zB==0 ) return 0; return -1; }else if( zB==0 ){ return +1; } if( nByte<0 ) nByte = strlen(zB); return sqlite4_strnicmp(zA, zB, nByte); } int fossil_stricmp(const char *zA, const char *zB){ int nByte; int rc; if( zA==0 ){ if( zB==0 ) return 0; return -1; }else if( zB==0 ){ return +1; } nByte = strlen(zB); rc = sqlite4_strnicmp(zA, zB, nByte); if( rc==0 && zA[nByte] ) rc = 1; return rc; } |
Changes to src/rebuild.c.
︙ | ︙ | |||
231 232 233 234 235 236 237 | ); } /* Find all children of artifact rid */ db_static_prepare(&q1, "SELECT rid FROM delta WHERE srcid=:rid"); db_bind_int(&q1, ":rid", rid); bag_init(&children); | | | 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | ); } /* Find all children of artifact rid */ db_static_prepare(&q1, "SELECT rid FROM delta WHERE srcid=:rid"); db_bind_int(&q1, ":rid", rid); bag_init(&children); while( db_step(&q1)==SQLITE4_ROW ){ int cid = db_column_int(&q1, 0); if( !bag_find(&bagDone, cid) ){ bag_insert(&children, cid); } } nChild = bag_count(&children); db_reset(&q1); |
︙ | ︙ | |||
269 270 271 272 273 274 275 | /* Call all children recursively */ rid = 0; for(cid=bag_first(&children), i=1; cid; cid=bag_next(&children, cid), i++){ static Stmt q2; int sz; db_static_prepare(&q2, "SELECT content, size FROM blob WHERE rid=:rid"); db_bind_int(&q2, ":rid", cid); | | | 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | /* Call all children recursively */ rid = 0; for(cid=bag_first(&children), i=1; cid; cid=bag_next(&children, cid), i++){ static Stmt q2; int sz; db_static_prepare(&q2, "SELECT content, size FROM blob WHERE rid=:rid"); db_bind_int(&q2, ":rid", cid); if( db_step(&q2)==SQLITE4_ROW && (sz = db_column_int(&q2,1))>=0 ){ Blob delta, next; db_ephemeral_blob(&q2, 0, &delta); blob_uncompress(&delta, &delta); blob_delta_apply(pBase, &delta, &next); blob_reset(&delta); db_reset(&q2); if( i<nChild ){ |
︙ | ︙ | |||
381 382 383 384 385 386 387 | totalSize += incrSize*2; db_prepare(&s, "SELECT rid, size FROM blob /*scan*/" " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)" " AND NOT EXISTS(SELECT 1 FROM delta WHERE rid=blob.rid)" ); manifest_crosslink_begin(); | | | | 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | totalSize += incrSize*2; db_prepare(&s, "SELECT rid, size FROM blob /*scan*/" " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)" " AND NOT EXISTS(SELECT 1 FROM delta WHERE rid=blob.rid)" ); manifest_crosslink_begin(); while( db_step(&s)==SQLITE4_ROW ){ int rid = db_column_int(&s, 0); int size = db_column_int(&s, 1); if( size>=0 ){ Blob content; content_get(rid, &content); rebuild_step(rid, size, &content); } } db_finalize(&s); db_prepare(&s, "SELECT rid, size FROM blob" " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)" ); while( db_step(&s)==SQLITE4_ROW ){ int rid = db_column_int(&s, 0); int size = db_column_int(&s, 1); if( size>=0 ){ if( !bag_find(&bagDone, rid) ){ Blob content; content_get(rid, &content); rebuild_step(rid, size, &content); |
︙ | ︙ | |||
445 446 447 448 449 450 451 | "SELECT rid FROM event, blob" " WHERE blob.rid=event.objid" " AND event.type='ci'" " AND NOT EXISTS(SELECT 1 FROM delta WHERE rid=blob.rid)" " ORDER BY event.mtime DESC" ); topid = previd = 0; | | | 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 | "SELECT rid FROM event, blob" " WHERE blob.rid=event.objid" " AND event.type='ci'" " AND NOT EXISTS(SELECT 1 FROM delta WHERE rid=blob.rid)" " ORDER BY event.mtime DESC" ); topid = previd = 0; while( db_step(&q)==SQLITE4_ROW ){ rid = db_column_int(&q, 0); if( topid==0 ){ topid = previd = rid; }else{ if( content_deltify(rid, previd, 0)==0 && previd!=topid ){ content_deltify(rid, topid, 0); } |
︙ | ︙ | |||
467 468 469 470 471 472 473 | " WHERE NOT EXISTS(SELECT 1 FROM delta WHERE rid=blob.rid)" " AND mlink.fid=blob.rid" " AND mlink.mid=plink.cid" " AND plink.cid=mlink.mid" " ORDER BY mlink.fnid, plink.mtime DESC" ); prevfnid = 0; | | | 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 | " WHERE NOT EXISTS(SELECT 1 FROM delta WHERE rid=blob.rid)" " AND mlink.fid=blob.rid" " AND mlink.mid=plink.cid" " AND plink.cid=mlink.mid" " ORDER BY mlink.fnid, plink.mtime DESC" ); prevfnid = 0; while( db_step(&q)==SQLITE4_ROW ){ rid = db_column_int(&q, 0); fnid = db_column_int(&q, 1); if( prevfnid!=fnid ){ prevfnid = fnid; topid = previd = rid; }else{ if( content_deltify(rid, previd, 0)==0 && previd!=topid ){ |
︙ | ︙ | |||
695 696 697 698 699 700 701 | "INSERT OR IGNORE INTO xdone" " SELECT blob.rid FROM shun JOIN blob USING(uuid);" ); db_prepare(&q, "SELECT rid FROM unclustered WHERE rid IN" " (SELECT rid FROM tagxref WHERE tagid=%d)", TAG_CLUSTER ); | | | 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 | "INSERT OR IGNORE INTO xdone" " SELECT blob.rid FROM shun JOIN blob USING(uuid);" ); db_prepare(&q, "SELECT rid FROM unclustered WHERE rid IN" " (SELECT rid FROM tagxref WHERE tagid=%d)", TAG_CLUSTER ); while( db_step(&q)==SQLITE4_ROW ){ bag_insert(&pending, db_column_int(&q, 0)); } db_finalize(&q); while( bag_count(&pending)>0 ){ Manifest *p; int rid = bag_first(&pending); int i; |
︙ | ︙ | |||
732 733 734 735 736 737 738 | n = db_int(0, "SELECT count(*) FROM /*scan*/" " (SELECT rid FROM blob EXCEPT SELECT x FROM xdone)"); if( n==0 ){ fossil_print("all artifacts reachable through clusters\n"); }else{ fossil_print("%d unreachable artifacts:\n", n); db_prepare(&q, "SELECT rid, uuid FROM blob WHERE rid NOT IN xdone"); | | | 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 | n = db_int(0, "SELECT count(*) FROM /*scan*/" " (SELECT rid FROM blob EXCEPT SELECT x FROM xdone)"); if( n==0 ){ fossil_print("all artifacts reachable through clusters\n"); }else{ fossil_print("%d unreachable artifacts:\n", n); db_prepare(&q, "SELECT rid, uuid FROM blob WHERE rid NOT IN xdone"); while( db_step(&q)==SQLITE4_ROW ){ fossil_print(" %3d %s\n", db_column_int(&q,0), db_column_text(&q,1)); } db_finalize(&q); } } /* |
︙ | ︙ | |||
990 991 992 993 994 995 996 | } totalSize = db_int(0, "SELECT count(*) FROM blob"); db_prepare(&s, "SELECT rid, size FROM blob /*scan*/" " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)" " AND NOT EXISTS(SELECT 1 FROM delta WHERE rid=blob.rid)" ); | | | | 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 | } totalSize = db_int(0, "SELECT count(*) FROM blob"); db_prepare(&s, "SELECT rid, size FROM blob /*scan*/" " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)" " AND NOT EXISTS(SELECT 1 FROM delta WHERE rid=blob.rid)" ); while( db_step(&s)==SQLITE4_ROW ){ int rid = db_column_int(&s, 0); int size = db_column_int(&s, 1); if( size>=0 ){ Blob content; content_get(rid, &content); rebuild_step(rid, size, &content); } } db_finalize(&s); db_prepare(&s, "SELECT rid, size FROM blob" " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)" ); while( db_step(&s)==SQLITE4_ROW ){ int rid = db_column_int(&s, 0); int size = db_column_int(&s, 1); if( size>=0 ){ if( !bag_find(&bagDone, rid) ){ Blob content; content_get(rid, &content); rebuild_step(rid, size, &content); |
︙ | ︙ |
Changes to src/report.c.
︙ | ︙ | |||
42 43 44 45 46 47 48 | zScript = ticket_reportlist_code(); if( g.thTrace ) Th_Trace("BEGIN_REPORTLIST_SCRIPT<br />\n", -1); blob_zero(&ril); ticket_init(); db_prepare(&q, "SELECT rn, title, owner FROM reportfmt ORDER BY title"); | | | 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | zScript = ticket_reportlist_code(); if( g.thTrace ) Th_Trace("BEGIN_REPORTLIST_SCRIPT<br />\n", -1); blob_zero(&ril); ticket_init(); db_prepare(&q, "SELECT rn, title, owner FROM reportfmt ORDER BY title"); while( db_step(&q)==SQLITE4_ROW ){ const char *zTitle = db_column_text(&q, 1); const char *zOwner = db_column_text(&q, 2); if( zTitle[0] =='_' && !g.perm.TktFmt ){ continue; } rn = db_column_int(&q, 0); cnt++; |
︙ | ︙ | |||
157 158 159 160 161 162 163 | void *pError, int code, const char *zArg1, const char *zArg2, const char *zArg3, const char *zArg4 ){ | | | | | | | | | | | | | | | | | | | 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | void *pError, int code, const char *zArg1, const char *zArg2, const char *zArg3, const char *zArg4 ){ int rc = SQLITE4_OK; if( *(char**)pError ){ /* We've already seen an error. No need to continue. */ return SQLITE4_OK; } switch( code ){ case SQLITE4_SELECT: case SQLITE4_FUNCTION: { break; } case SQLITE4_READ: { static const char *azAllowed[] = { "ticket", "blob", "filename", "mlink", "plink", "event", "tag", "tagxref", }; int i; for(i=0; i<sizeof(azAllowed)/sizeof(azAllowed[0]); i++){ if( fossil_stricmp(zArg1, azAllowed[i])==0 ) break; } if( i>=sizeof(azAllowed)/sizeof(azAllowed[0]) ){ *(char**)pError = mprintf("access to table \"%s\" is restricted",zArg1); rc = SQLITE4_DENY; }else if( !g.perm.RdAddr && strncmp(zArg2, "private_", 8)==0 ){ rc = SQLITE4_IGNORE; } break; } default: { *(char**)pError = mprintf("only SELECT statements are allowed"); rc = SQLITE4_DENY; break; } } return rc; } /* ** Activate the query authorizer */ static void report_restrict_sql(char **pzErr){ (void)fossil_localtime(0); sqlite4_set_authorizer(g.db, report_query_authorizer, (void*)pzErr); } static void report_unrestrict_sql(void){ sqlite4_set_authorizer(g.db, 0, 0); } /* ** Check the given SQL to see if is a valid query that does not ** attempt to do anything dangerous. Return 0 on success and a ** pointer to an error message string (obtained from malloc) if ** there is a problem. */ char *verify_sql_statement(char *zSql){ int i; char *zErr = 0; const char *zTail; sqlite4_stmt *pStmt; int rc; /* First make sure the SQL is a single query command by verifying that ** the first token is "SELECT" and that there are no unquoted semicolons. */ for(i=0; fossil_isspace(zSql[i]); i++){} if( fossil_strnicmp(&zSql[i],"select",6)!=0 ){ return mprintf("The SQL must be a SELECT statement"); } for(i=0; zSql[i]; i++){ if( zSql[i]==';' ){ int bad; int c = zSql[i+1]; zSql[i+1] = 0; bad = sqlite4_complete(zSql); zSql[i+1] = c; if( bad ){ /* A complete statement basically means that an unquoted semi-colon ** was found. We don't actually check what's after that. */ return mprintf("Semi-colon detected! " "Only a single SQL statement is allowed"); } } } /* Compile the statement and check for illegal accesses or syntax errors. */ report_restrict_sql(&zErr); rc = sqlite4_prepare(g.db, zSql, -1, &pStmt, &zTail); if( rc!=SQLITE4_OK ){ zErr = mprintf("Syntax error: %s", sqlite4_errmsg(g.db)); } if( !sqlite4_stmt_readonly(pStmt) ){ zErr = mprintf("SQL must not modify the database"); } if( pStmt ){ sqlite4_finalize(pStmt); } report_unrestrict_sql(); return zErr; } /* ** WEBPAGE: /rptsql |
︙ | ︙ | |||
284 285 286 287 288 289 290 | login_needed(); return; } rn = atoi(PD("rn","0")); db_prepare(&q, "SELECT title, sqlcode, owner, cols " "FROM reportfmt WHERE rn=%d",rn); style_header("SQL For Report Format Number %d", rn); | | | 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | login_needed(); return; } rn = atoi(PD("rn","0")); db_prepare(&q, "SELECT title, sqlcode, owner, cols " "FROM reportfmt WHERE rn=%d",rn); style_header("SQL For Report Format Number %d", rn); if( db_step(&q)!=SQLITE4_ROW ){ @ <p>Unknown report number: %d(rn)</p> style_footer(); return; } zTitle = db_column_text(&q, 0); zSQL = db_column_text(&q, 1); zOwner = db_column_text(&q, 2); |
︙ | ︙ | |||
401 402 403 404 405 406 407 | zTitle = ""; zSQL = ticket_report_template(); zClrKey = ticket_key_template(); }else{ Stmt q; db_prepare(&q, "SELECT title, sqlcode, owner, cols " "FROM reportfmt WHERE rn=%d",rn); | | | 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | zTitle = ""; zSQL = ticket_report_template(); zClrKey = ticket_key_template(); }else{ Stmt q; db_prepare(&q, "SELECT title, sqlcode, owner, cols " "FROM reportfmt WHERE rn=%d",rn); if( db_step(&q)==SQLITE4_ROW ){ zTitle = db_column_malloc(&q, 0); zSQL = db_column_malloc(&q, 1); zOwner = db_column_malloc(&q, 2); zClrKey = db_column_malloc(&q, 3); } db_finalize(&q); if( P("copy") ){ |
︙ | ︙ | |||
639 640 641 642 643 644 645 | /* Do initialization */ if( pState->nCount==0 ){ /* Turn off the authorizer. It is no longer doing anything since the ** query has already been prepared. */ | | | 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 | /* Do initialization */ if( pState->nCount==0 ){ /* Turn off the authorizer. It is no longer doing anything since the ** query has already been prepared. */ sqlite4_set_authorizer(g.db, 0, 0); /* Figure out the number of columns, the column that determines background ** color, and whether or not this row of data is represented by multiple ** rows in the table. */ pState->nCol = 0; pState->isMultirow = 0; |
︙ | ︙ | |||
832 833 834 835 836 837 838 | @ </table> } /* ** Execute a single read-only SQL statement. Invoke xCallback() on each ** row. */ | | | | | | | | | | | | | | | | | | | 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 | @ </table> } /* ** Execute a single read-only SQL statement. Invoke xCallback() on each ** row. */ int sqlite4_exec_readonly( sqlite4 *db, /* The database on which the SQL executes */ const char *zSql, /* The SQL to be executed */ sqlite4_callback xCallback, /* Invoke this callback routine */ void *pArg, /* First argument to xCallback() */ char **pzErrMsg /* Write error messages here */ ){ int rc = SQLITE4_OK; /* Return code */ const char *zLeftover; /* Tail of unprocessed SQL */ sqlite4_stmt *pStmt = 0; /* The current SQL statement */ char **azCols = 0; /* Names of result columns */ int nCol; /* Number of columns of output */ char **azVals = 0; /* Text of all output columns */ int i; /* Loop counter */ pStmt = 0; rc = sqlite4_prepare(db, zSql, -1, &pStmt, &zLeftover); assert( rc==SQLITE4_OK || pStmt==0 ); if( rc!=SQLITE4_OK ){ return rc; } if( !pStmt ){ /* this happens for a comment or white-space */ return SQLITE4_OK; } if( !sqlite4_stmt_readonly(pStmt) ){ sqlite4_finalize(pStmt); return SQLITE4_ERROR; } nCol = sqlite4_column_count(pStmt); azVals = fossil_malloc(2*nCol*sizeof(const char*) + 1); while( (rc = sqlite4_step(pStmt))==SQLITE4_ROW ){ if( azCols==0 ){ azCols = &azVals[nCol]; for(i=0; i<nCol; i++){ azCols[i] = (char *)sqlite4_column_name(pStmt, i); } } for(i=0; i<nCol; i++){ azVals[i] = (char *)sqlite4_column_text(pStmt, i); } if( xCallback(pArg, nCol, azVals, azCols) ){ break; } } rc = sqlite4_finalize(pStmt); fossil_free(azVals); return rc; } /* ** WEBPAGE: /rptview |
︙ | ︙ | |||
915 916 917 918 919 920 921 | cgi_redirect("reportlist"); return; } tabs = P("tablist")!=0; /* view_add_functions(tabs); */ db_prepare(&q, "SELECT title, sqlcode, owner, cols FROM reportfmt WHERE rn=%d", rn); | | | 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 | cgi_redirect("reportlist"); return; } tabs = P("tablist")!=0; /* view_add_functions(tabs); */ db_prepare(&q, "SELECT title, sqlcode, owner, cols FROM reportfmt WHERE rn=%d", rn); if( db_step(&q)!=SQLITE4_ROW ){ cgi_redirect("reportlist"); return; } zTitle = db_column_malloc(&q, 0); zSql = db_column_malloc(&q, 1); zOwner = db_column_malloc(&q, 2); zClrKey = db_column_malloc(&q, 3); |
︙ | ︙ | |||
965 966 967 968 969 970 971 | style_header(zTitle); output_color_key(zClrKey, 1, "border=\"0\" cellpadding=\"3\" cellspacing=\"0\" class=\"report\""); @ <table border="1" cellpadding="2" cellspacing="0" class="report"> sState.rn = rn; sState.nCount = 0; report_restrict_sql(&zErr1); | | | | 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 | style_header(zTitle); output_color_key(zClrKey, 1, "border=\"0\" cellpadding=\"3\" cellspacing=\"0\" class=\"report\""); @ <table border="1" cellpadding="2" cellspacing="0" class="report"> sState.rn = rn; sState.nCount = 0; report_restrict_sql(&zErr1); sqlite4_exec_readonly(g.db, zSql, generate_html, &sState, &zErr2); report_unrestrict_sql(); @ </table> if( zErr1 ){ @ <p class="reportError">Error: %h(zErr1)</p> }else if( zErr2 ){ @ <p class="reportError">Error: %h(zErr2)</p> } style_footer(); }else{ report_restrict_sql(&zErr1); sqlite4_exec_readonly(g.db, zSql, output_tab_separated, &count, &zErr2); report_unrestrict_sql(); cgi_set_content_type("text/plain"); } } /* ** report number for full table ticket export |
︙ | ︙ | |||
1004 1005 1006 1007 1008 1009 1010 | Stmt q; char const aRptOutFrmt[] = "%s\t%s\n"; fossil_print("Available reports:\n"); fossil_print(aRptOutFrmt,"report number","report title"); fossil_print(aRptOutFrmt,zFullTicketRptRn,zFullTicketRptTitle); db_prepare(&q,"SELECT rn,title FROM reportfmt ORDER BY rn"); | | | 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 | Stmt q; char const aRptOutFrmt[] = "%s\t%s\n"; fossil_print("Available reports:\n"); fossil_print(aRptOutFrmt,"report number","report title"); fossil_print(aRptOutFrmt,zFullTicketRptRn,zFullTicketRptTitle); db_prepare(&q,"SELECT rn,title FROM reportfmt ORDER BY rn"); while( db_step(&q)==SQLITE4_ROW ){ const char *zRn = db_column_text(&q, 0); const char *zTitle = db_column_text(&q, 1); fossil_print(aRptOutFrmt,zRn,zTitle); } db_finalize(&q); } |
︙ | ︙ | |||
1114 1115 1116 1117 1118 1119 1120 | if( rn ){ db_prepare(&q, "SELECT sqlcode FROM reportfmt WHERE rn=%d", rn); }else{ db_prepare(&q, "SELECT sqlcode FROM reportfmt WHERE title=%Q", zRep); } | | | | 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 | if( rn ){ db_prepare(&q, "SELECT sqlcode FROM reportfmt WHERE rn=%d", rn); }else{ db_prepare(&q, "SELECT sqlcode FROM reportfmt WHERE title=%Q", zRep); } if( db_step(&q)!=SQLITE4_ROW ){ db_finalize(&q); rpt_list_reports(); fossil_fatal("unknown report format(%s)!",zRep); } zSql = db_column_malloc(&q, 0); db_finalize(&q); } if( zFilter ){ zSql = mprintf("SELECT * FROM (%s) WHERE %s",zSql,zFilter); } count = 0; tktEncode = enc; zSep = zSepIn; report_restrict_sql(&zErr1); sqlite4_exec_readonly(g.db, zSql, output_separated_file, &count, &zErr2); report_unrestrict_sql(); if( zFilter ){ free(zSql); } } |
Changes to src/rss.c.
︙ | ︙ | |||
102 103 104 105 106 107 108 | @ <link>%s(g.zBaseURL)</link> @ <description>%h(zProjectDescr)</description> @ <pubDate>%s(zPubDate)</pubDate> @ <generator>Fossil version %s(MANIFEST_VERSION) %s(MANIFEST_DATE)</generator> free(zPubDate); db_prepare(&q, blob_str(&bSQL)); blob_reset( &bSQL ); | | | 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | @ <link>%s(g.zBaseURL)</link> @ <description>%h(zProjectDescr)</description> @ <pubDate>%s(zPubDate)</pubDate> @ <generator>Fossil version %s(MANIFEST_VERSION) %s(MANIFEST_DATE)</generator> free(zPubDate); db_prepare(&q, blob_str(&bSQL)); blob_reset( &bSQL ); while( db_step(&q)==SQLITE4_ROW && nLine<=nLimit ){ const char *zId = db_column_text(&q, 1); const char *zCom = db_column_text(&q, 3); const char *zAuthor = db_column_text(&q, 4); char *zPrefix = ""; char *zDate; int nChild = db_column_int(&q, 5); int nParent = db_column_int(&q, 6); |
︙ | ︙ |
Changes to src/search.c.
︙ | ︙ | |||
109 110 111 112 113 114 115 | memset(seen, 0, sizeof(seen)); for(i=0; zDoc[i]; i++){ char c = zDoc[i]; if( isBoundary[c&0xff] ) continue; for(j=0; j<p->nTerm; j++){ int n = p->a[j].n; | | | 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | memset(seen, 0, sizeof(seen)); for(i=0; zDoc[i]; i++){ char c = zDoc[i]; if( isBoundary[c&0xff] ) continue; for(j=0; j<p->nTerm; j++){ int n = p->a[j].n; if( sqlite4_strnicmp(p->a[j].z, &zDoc[i], n)==0 ){ score += 1; if( !seen[j] ){ if( isBoundary[zDoc[i+n]&0xff] ) score += 10; seen[j] = 1; } if( j==iPrev+1 ){ score += iBonus; |
︙ | ︙ | |||
141 142 143 144 145 146 147 | } /* ** This is an SQLite function that scores its input using ** a pre-computed pattern. */ static void search_score_sqlfunc( | | | | | | | | 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | } /* ** This is an SQLite function that scores its input using ** a pre-computed pattern. */ static void search_score_sqlfunc( sqlite4_context *context, int argc, sqlite4_value **argv ){ Search *p = (Search*)sqlite4_user_data(context); int score = search_score(p, (const char*)sqlite4_value_text(argv[0])); sqlite4_result_int(context, score); } /* ** Register the "score()" SQL function to score its input text ** using the given Search object. Once this function is registered, ** do not delete the Search object. */ void search_sql_setup(Search *p){ sqlite4_create_function(g.db, "score", 1, SQLITE4_UTF8, p, search_score_sqlfunc, 0, 0); } /* ** Testing the search function. ** ** COMMAND: search* |
︙ | ︙ |
Changes to src/setup.c.
︙ | ︙ | |||
131 132 133 134 135 136 137 | "SELECT uid, login, cap, info, 1 FROM user" " WHERE login IN ('anonymous','nobody','developer','reader') " " UNION ALL " "SELECT uid, login, cap, info, 2 FROM user" " WHERE login NOT IN ('anonymous','nobody','developer','reader') " "ORDER BY 5, 2" ); | | | 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | "SELECT uid, login, cap, info, 1 FROM user" " WHERE login IN ('anonymous','nobody','developer','reader') " " UNION ALL " "SELECT uid, login, cap, info, 2 FROM user" " WHERE login NOT IN ('anonymous','nobody','developer','reader') " "ORDER BY 5, 2" ); while( db_step(&s)==SQLITE4_ROW ){ int iLevel = db_column_int(&s, 4); const char *zCap = db_column_text(&s, 2); const char *zLogin = db_column_text(&s, 1); if( iLevel>prevLevel ){ if( prevLevel>0 ){ @ <tr><td colspan="3"><hr></td></tr> } |
︙ | ︙ | |||
1066 1067 1068 1069 1070 1071 1072 | "SELECT value," " (SELECT value FROM config" " WHERE name=('peer-name-' || substr(x.name,11)))" " FROM config AS x" " WHERE name GLOB 'peer-repo-*'" " ORDER BY value" ); | | | 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 | "SELECT value," " (SELECT value FROM config" " WHERE name=('peer-name-' || substr(x.name,11)))" " FROM config AS x" " WHERE name GLOB 'peer-repo-*'" " ORDER BY value" ); while( db_step(&q)==SQLITE4_ROW ){ const char *zRepo = db_column_text(&q, 0); const char *zTitle = db_column_text(&q, 1); n++; @ <tr><td align="right">%d(n).</td><td width="4"> @ <td>%h(zTitle)<td width="10"><td>%h(zRepo)</tr> } db_finalize(&q); |
︙ | ︙ | |||
1567 1568 1569 1570 1571 1572 1573 | @ SQL:<br /> @ <textarea name="q" rows="5" cols="80">%h(zQ)</textarea><br /> @ <input type="submit" name="go" value="Run SQL"> @ <input type="submit" name="schema" value="Show Schema"> @ <input type="submit" name="tablelist" value="List Tables"> @ </form> if( P("schema") ){ | | | | | | | | | | | | | | | | | | | | | | | | | 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 | @ SQL:<br /> @ <textarea name="q" rows="5" cols="80">%h(zQ)</textarea><br /> @ <input type="submit" name="go" value="Run SQL"> @ <input type="submit" name="schema" value="Show Schema"> @ <input type="submit" name="tablelist" value="List Tables"> @ </form> if( P("schema") ){ zQ = sqlite4_mprintf(0, "SELECT sql FROM %s.sqlite_master WHERE sql IS NOT NULL", db_name("repository")); go = 1; }else if( P("tablelist") ){ zQ = sqlite4_mprintf(0, "SELECT name FROM %s.sqlite_master WHERE type='table'" " ORDER BY name", db_name("repository")); go = 1; } if( go ){ sqlite4_stmt *pStmt; int rc; const char *zTail; int nCol; int nRow = 0; int i; @ <hr /> login_verify_csrf_secret(); rc = sqlite4_prepare(g.db, zQ, -1, &pStmt, &zTail); if( rc!=SQLITE4_OK ){ @ <div class="generalError">%h(sqlite4_errmsg(g.db))</div> sqlite4_finalize(pStmt); }else if( pStmt==0 ){ /* No-op */ }else if( (nCol = sqlite4_column_count(pStmt))==0 ){ sqlite4_step(pStmt); rc = sqlite4_finalize(pStmt); if( rc ){ @ <div class="generalError">%h(sqlite4_errmsg(g.db))</div> } }else{ @ <table border=1> while( sqlite4_step(pStmt)==SQLITE4_ROW ){ if( nRow==0 ){ @ <tr> for(i=0; i<nCol; i++){ @ <th>%h(sqlite4_column_name(pStmt, i))</th> } @ </tr> } nRow++; @ <tr> for(i=0; i<nCol; i++){ switch( sqlite4_column_type(pStmt, i) ){ case SQLITE4_INTEGER: case SQLITE4_FLOAT: { @ <td align="right" valign="top"> @ %s(sqlite4_column_text(pStmt, i))</td> break; } case SQLITE4_NULL: { @ <td valign="top" align="center"><i>NULL</i></td> break; } case SQLITE4_TEXT: { const char *zText = (const char*)sqlite4_column_text(pStmt, i); @ <td align="left" valign="top" @ style="white-space:pre;">%h(zText)</td> break; } case SQLITE4_BLOB: { @ <td valign="top" align="center"> @ <i>%d(sqlite4_column_bytes(pStmt, i))-byte BLOB</i></td> break; } } } @ </tr> } sqlite4_finalize(pStmt); @ </table> } } style_footer(); } |
Changes to src/sha1.c.
︙ | ︙ | |||
411 412 413 414 415 416 417 | ** (1) The cleartext password ** (2) The login name ** (3) The project code ** ** Returns sha1($password/$login/$projcode). */ void sha1_shared_secret_sql_function( | | | | | | | | 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 | ** (1) The cleartext password ** (2) The login name ** (3) The project code ** ** Returns sha1($password/$login/$projcode). */ void sha1_shared_secret_sql_function( sqlite4_context *context, int argc, sqlite4_value **argv ){ const char *zPw; const char *zLogin; const char *zProjid; assert( argc==2 || argc==3 ); zPw = (const char*)sqlite4_value_text(argv[0]); if( zPw==0 || zPw[0]==0 ) return; zLogin = (const char*)sqlite4_value_text(argv[1]); if( zLogin==0 ) return; if( argc==3 ){ zProjid = (const char*)sqlite4_value_text(argv[2]); if( zProjid && zProjid[0]==0 ) zProjid = 0; }else{ zProjid = 0; } sqlite4_result_text(context, sha1_shared_secret(zPw, zLogin, zProjid), -1, fossil_free); } /* ** COMMAND: sha1sum* ** %fossil sha1sum FILE... ** |
︙ | ︙ |
Changes to src/shell.c.
︙ | ︙ | |||
16 17 18 19 20 21 22 | /* This needs to come before any includes for MSVC compiler */ #define _CRT_SECURE_NO_WARNINGS #endif /* ** Enable large-file support for fopen() and friends on unix. */ | | | | > > > > < < | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | /* This needs to come before any includes for MSVC compiler */ #define _CRT_SECURE_NO_WARNINGS #endif /* ** Enable large-file support for fopen() and friends on unix. */ #ifndef SQLITE4_DISABLE_LFS # define _LARGE_FILE 1 # ifndef _FILE_OFFSET_BITS # define _FILE_OFFSET_BITS 64 # endif # define _LARGEFILE_SOURCE 1 #endif #include <stdlib.h> #include <string.h> #include <stdio.h> #include <assert.h> #include "sqlite4.h" #include <ctype.h> #include <stdarg.h> #if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__) # include <signal.h> # if !defined(__RTP__) && !defined(_WRS_KERNEL) # include <pwd.h> # endif # include <unistd.h> # include <sys/types.h> #endif #ifdef __OS2__ # include <unistd.h> #endif #ifdef HAVE_EDITLINE # include <editline/editline.h> #endif #if defined(HAVE_READLINE) && HAVE_READLINE==1 # include <readline/readline.h> # include <readline/history.h> #endif #if !defined(HAVE_EDITLINE) && (!defined(HAVE_READLINE) || HAVE_READLINE!=1) # define readline(p) local_getline(p,stdin,0) # define add_history(X) # define read_history(X) # define write_history(X) # define stifle_history(X) #endif #if defined(_WIN32) || defined(WIN32) # include <io.h> #define isatty(h) _isatty(h) #define access(f,m) _access((f),(m)) #else /* Make sure isatty() has a prototype. */ extern int isatty(int); #endif #if defined(_WIN32_WCE) |
︙ | ︙ | |||
84 85 86 87 88 89 90 | static int enableTimer = 0; /* ctype macros that work with signed characters */ #define IsSpace(X) isspace((unsigned char)X) #define IsDigit(X) isdigit((unsigned char)X) #define ToLower(X) (char)tolower((unsigned char)X) | | | 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | static int enableTimer = 0; /* ctype macros that work with signed characters */ #define IsSpace(X) isspace((unsigned char)X) #define IsDigit(X) isdigit((unsigned char)X) #define ToLower(X) (char)tolower((unsigned char)X) #if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__) && !defined(__RTP__) && !defined(_WRS_KERNEL) #include <sys/time.h> #include <sys/resource.h> /* Saved resource information for the beginning of an operation */ static struct rusage sBegin; /* |
︙ | ︙ | |||
223 224 225 226 227 228 229 | static int stdin_is_interactive = 1; /* ** The following is the open SQLite database. We make a pointer ** to this database a static variable so that it can be accessed ** by the SIGINT handler to interrupt database processing. */ | | | 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | static int stdin_is_interactive = 1; /* ** The following is the open SQLite database. We make a pointer ** to this database a static variable so that it can be accessed ** by the SIGINT handler to interrupt database processing. */ static sqlite4 *db = 0; /* ** True if an interrupt (Control-C) has been received. */ static volatile int seenInterrupt = 0; /* |
︙ | ︙ | |||
246 247 248 249 250 251 252 | */ static char mainPrompt[20]; /* First line prompt. default: "sqlite> "*/ static char continuePrompt[20]; /* Continuation prompt. default: " ...> " */ /* ** Write I/O traces to the following stream. */ | | | | | | 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | */ static char mainPrompt[20]; /* First line prompt. default: "sqlite> "*/ static char continuePrompt[20]; /* Continuation prompt. default: " ...> " */ /* ** Write I/O traces to the following stream. */ #ifdef SQLITE4_ENABLE_IOTRACE static FILE *iotrace = 0; #endif /* ** This routine works like printf in that its first argument is a ** format string and subsequent arguments are values to be substituted ** in place of % fields. The result of formatting this string ** is written to iotrace. */ #ifdef SQLITE4_ENABLE_IOTRACE static void iotracePrintf(const char *zFormat, ...){ va_list ap; char *z; if( iotrace==0 ) return; va_start(ap, zFormat); z = sqlite4_vmprintf(0, zFormat, ap); va_end(ap); fprintf(iotrace, "%s", z); sqlite4_free(0, z); } #endif /* ** Determines if a string is a number of not. */ |
︙ | ︙ | |||
301 302 303 304 305 306 307 | return *z==0; } /* ** A global char* and an SQL function to access its current value ** from within an SQL statement. This program used to use the ** sqlite_exec_printf() API to substitue a string into an SQL statement. | | | | | | 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | return *z==0; } /* ** A global char* and an SQL function to access its current value ** from within an SQL statement. This program used to use the ** sqlite_exec_printf() API to substitue a string into an SQL statement. ** The correct way to do this with sqlite4 is to use the bind API, but ** since the shell is built around the callback paradigm it would be a lot ** of work. Instead just use this hack, which is quite harmless. */ static const char *zShellStatic = 0; static void shellstaticFunc( sqlite4_context *context, int argc, sqlite4_value **argv ){ assert( 0==argc ); assert( zShellStatic ); UNUSED_PARAMETER(argc); UNUSED_PARAMETER(argv); sqlite4_result_text(context, zShellStatic, -1, SQLITE4_STATIC); } /* ** This routine reads a line of text from FILE in, stores ** the text in memory obtained from malloc() and returns a pointer ** to the text. NULL is returned at end of file, or if malloc() |
︙ | ︙ | |||
408 409 410 411 412 413 414 | /* ** An pointer to an instance of this structure is passed from ** the main program to the callback. This is used to communicate ** state and mode information. */ struct callback_data { | | < | | 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | /* ** An pointer to an instance of this structure is passed from ** the main program to the callback. This is used to communicate ** state and mode information. */ struct callback_data { sqlite4 *db; /* The database */ int echoOn; /* True to echo input commands */ int statsOn; /* True to display memory stats before each finalize */ int cnt; /* Number of records displayed so far */ FILE *out; /* Write results here */ int nErr; /* Number of errors seen */ int mode; /* An output mode setting */ int writableSchema; /* True if PRAGMA writable_schema=ON */ int showHeader; /* True to show column names in List or Column mode */ char *zDestTable; /* Name of destination table when MODE_Insert */ char separator[20]; /* Separator character for MODE_List */ int colWidth[100]; /* Requested width of each column when in column mode*/ int actualWidth[100]; /* Actual width of each column */ char nullvalue[20]; /* The text to print when a NULL comes back from ** the database */ struct previous_mode_data explainPrev; /* Holds the mode information just before ** .explain ON */ char outfile[FILENAME_MAX]; /* Filename for *out */ const char *zDbFilename; /* name of the database file */ const char *zVfs; /* Name of VFS to use */ sqlite4_stmt *pStmt; /* Current statement if any. */ FILE *pLog; /* Write log output here */ }; /* ** These are the allowed modes. */ #define MODE_Line 0 /* One column per line. Blank line between records */ |
︙ | ︙ | |||
475 476 477 478 479 480 481 | static int strlen30(const char *z){ const char *z2 = z; while( *z2 ){ z2++; } return 0x3fffffff & (int)(z2 - z); } /* | | | | 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | static int strlen30(const char *z){ const char *z2 = z; while( *z2 ){ z2++; } return 0x3fffffff & (int)(z2 - z); } /* ** A callback for the sqlite4_log() interface. */ static void shellLog(void *pArg, int iErrCode, const char *zMsg){ struct callback_data *p = (struct callback_data*)pArg; if( p->pLog==0 ) return; fprintf(p->pLog, "(%d) %s\n", iErrCode, zMsg); fflush(p->pLog); } /* ** Output the given string as a hex-encoded blob (eg. X'1234' ) */ static void output_hex_blob(FILE *out, const void *pBlob, int nBlob){ int i; char *zBlob = (char *)pBlob; fprintf(out,"X'"); for(i=0; i<nBlob; i++){ fprintf(out,"%02x",zBlob[i]); } fprintf(out,"'"); } /* ** Output the given string as a quoted string using SQL quoting conventions. */ static void output_quoted_string(FILE *out, const char *z){ |
︙ | ︙ | |||
653 654 655 656 657 658 659 | #ifdef SIGINT /* ** This routine runs when the user presses Ctrl-C */ static void interrupt_handler(int NotUsed){ UNUSED_PARAMETER(NotUsed); seenInterrupt = 1; | | | 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 | #ifdef SIGINT /* ** This routine runs when the user presses Ctrl-C */ static void interrupt_handler(int NotUsed){ UNUSED_PARAMETER(NotUsed); seenInterrupt = 1; if( db ) sqlite4_interrupt(db); } #endif /* ** This is the callback routine that the shell ** invokes for each row of a query result. */ |
︙ | ︙ | |||
812 813 814 815 816 817 818 | } case MODE_Insert: { p->cnt++; if( azArg==0 ) break; fprintf(p->out,"INSERT INTO %s VALUES(",p->zDestTable); for(i=0; i<nArg; i++){ char *zSep = i>0 ? ",": ""; | | | | | | | | 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 | } case MODE_Insert: { p->cnt++; if( azArg==0 ) break; fprintf(p->out,"INSERT INTO %s VALUES(",p->zDestTable); for(i=0; i<nArg; i++){ char *zSep = i>0 ? ",": ""; if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE4_NULL) ){ fprintf(p->out,"%sNULL",zSep); }else if( aiType && aiType[i]==SQLITE4_TEXT ){ if( zSep[0] ) fprintf(p->out,"%s",zSep); output_quoted_string(p->out, azArg[i]); }else if( aiType && (aiType[i]==SQLITE4_INTEGER || aiType[i]==SQLITE4_FLOAT) ){ fprintf(p->out,"%s%s",zSep, azArg[i]); }else if( aiType && aiType[i]==SQLITE4_BLOB && p->pStmt ){ const void *pBlob = sqlite4_column_blob(p->pStmt, i); int nBlob = sqlite4_column_bytes(p->pStmt, i); if( zSep[0] ) fprintf(p->out,"%s",zSep); output_hex_blob(p->out, pBlob, nBlob); }else if( isNumber(azArg[i], 0) ){ fprintf(p->out,"%s%s",zSep, azArg[i]); }else{ if( zSep[0] ) fprintf(p->out,"%s",zSep); output_quoted_string(p->out, azArg[i]); |
︙ | ︙ | |||
932 933 934 935 936 937 938 | } return zIn; } /* | | < | < < < > | | < < < | | | | < | < | < < < < < < < < < < | | | | | | | | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | | | < < < < < < < < < < < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 | } return zIn; } /* ** Execute a query statement that has a single result column. Print ** that result column on a line by itself with a semicolon terminator. ** ** This is used, for example, to show the schema of the database by ** querying the SQLITE4_MASTER table. */ static int run_table_dump_query( struct callback_data *p, /* Query context */ const char *zSelect, /* SELECT statement to extract content */ const char *zFirstRow /* Print before first row, if not NULL */ ){ sqlite4_stmt *pSelect; int rc; rc = sqlite4_prepare(p->db, zSelect, -1, &pSelect, 0); if( rc!=SQLITE4_OK || !pSelect ){ fprintf(p->out, "/**** ERROR: (%d) %s *****/\n", rc, sqlite4_errmsg(p->db)); p->nErr++; return rc; } rc = sqlite4_step(pSelect); while( rc==SQLITE4_ROW ){ if( zFirstRow ){ fprintf(p->out, "%s", zFirstRow); zFirstRow = 0; } fprintf(p->out, "%s;\n", sqlite4_column_text(pSelect, 0)); rc = sqlite4_step(pSelect); } rc = sqlite4_finalize(pSelect); if( rc!=SQLITE4_OK ){ fprintf(p->out, "/**** ERROR: (%d) %s *****/\n", rc, sqlite4_errmsg(p->db)); p->nErr++; } return rc; } /* ** Allocate space and save off current error string. */ static char *save_err_msg( sqlite4 *db /* Database to query */ ){ int nErrMsg = 1+strlen30(sqlite4_errmsg(db)); char *zErrMsg = sqlite4_malloc(0, nErrMsg); if( zErrMsg ){ memcpy(zErrMsg, sqlite4_errmsg(db), nErrMsg); } return zErrMsg; } /* ** Display memory stats. */ static int display_stats( sqlite4 *db, /* Database to query */ struct callback_data *pArg, /* Pointer to struct callback_data */ int bReset /* True to reset the stats */ ){ int iCur; int iHiwtr; if( pArg && pArg->out && db ){ iHiwtr = iCur = -1; sqlite4_db_status(db, SQLITE4_DBSTATUS_LOOKASIDE_USED, &iCur, &iHiwtr, bReset); fprintf(pArg->out, "Lookaside Slots Used: %d (max %d)\n", iCur, iHiwtr); sqlite4_db_status(db, SQLITE4_DBSTATUS_LOOKASIDE_HIT, &iCur, &iHiwtr, bReset); fprintf(pArg->out, "Successful lookaside attempts: %d\n", iHiwtr); sqlite4_db_status(db, SQLITE4_DBSTATUS_LOOKASIDE_MISS_SIZE, &iCur, &iHiwtr, bReset); fprintf(pArg->out, "Lookaside failures due to size: %d\n", iHiwtr); sqlite4_db_status(db, SQLITE4_DBSTATUS_LOOKASIDE_MISS_FULL, &iCur, &iHiwtr, bReset); fprintf(pArg->out, "Lookaside failures due to OOM: %d\n", iHiwtr); iHiwtr = iCur = -1; sqlite4_db_status(db, SQLITE4_DBSTATUS_SCHEMA_USED, &iCur, &iHiwtr, bReset); fprintf(pArg->out, "Schema Heap Usage: %d bytes\n", iCur); iHiwtr = iCur = -1; sqlite4_db_status(db, SQLITE4_DBSTATUS_STMT_USED, &iCur, &iHiwtr, bReset); fprintf(pArg->out, "Statement Heap/Lookaside Usage: %d bytes\n", iCur); } if( pArg && pArg->out && db && pArg->pStmt ){ iCur = sqlite4_stmt_status(pArg->pStmt, SQLITE4_STMTSTATUS_FULLSCAN_STEP, bReset); fprintf(pArg->out, "Fullscan Steps: %d\n", iCur); iCur = sqlite4_stmt_status(pArg->pStmt, SQLITE4_STMTSTATUS_SORT, bReset); fprintf(pArg->out, "Sort Operations: %d\n", iCur); iCur = sqlite4_stmt_status(pArg->pStmt, SQLITE4_STMTSTATUS_AUTOINDEX, bReset); fprintf(pArg->out, "Autoindex Inserts: %d\n", iCur); } return 0; } /* ** Execute a statement or set of statements. Print ** any result rows/columns depending on the current mode ** set via the supplied callback. ** ** This is very similar to SQLite's built-in sqlite4_exec() ** function except it takes a slightly different callback ** and callback data argument. */ static int shell_exec( sqlite4 *db, /* An open database */ const char *zSql, /* SQL to be evaluated */ int (*xCallback)(void*,int,char**,char**,int*), /* Callback function */ /* (not the same as sqlite4_exec) */ struct callback_data *pArg, /* Pointer to struct callback_data */ char **pzErrMsg /* Error msg written here */ ){ sqlite4_stmt *pStmt = NULL; /* Statement to execute. */ int rc = SQLITE4_OK; /* Return Code */ int rc2; const char *zLeftover; /* Tail of unprocessed SQL */ if( pzErrMsg ){ *pzErrMsg = NULL; } while( zSql[0] && (SQLITE4_OK == rc) ){ rc = sqlite4_prepare(db, zSql, -1, &pStmt, &zLeftover); if( SQLITE4_OK != rc ){ if( pzErrMsg ){ *pzErrMsg = save_err_msg(db); } }else{ if( !pStmt ){ /* this happens for a comment or white-space */ zSql = zLeftover; while( IsSpace(zSql[0]) ) zSql++; continue; } /* save off the prepared statment handle and reset row count */ if( pArg ){ pArg->pStmt = pStmt; pArg->cnt = 0; } /* echo the sql statement if echo on */ if( pArg && pArg->echoOn ){ const char *zStmtSql = sqlite4_sql(pStmt); fprintf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql); } /* Output TESTCTRL_EXPLAIN text of requested */ if( pArg && pArg->mode==MODE_Explain ){ const char *zExplain = 0; sqlite4_test_control(SQLITE4_TESTCTRL_EXPLAIN_STMT, pStmt, &zExplain); if( zExplain && zExplain[0] ){ fprintf(pArg->out, "%s", zExplain); } } /* perform the first step. this will tell us if we ** have a result set or not and how wide it is. */ rc = sqlite4_step(pStmt); /* if we have a result set... */ if( SQLITE4_ROW == rc ){ /* if we have a callback... */ if( xCallback ){ /* allocate space for col name ptr, value ptr, and type */ int nCol = sqlite4_column_count(pStmt); void *pData = sqlite4_malloc(0, 3*nCol*sizeof(const char*) + 1); if( !pData ){ rc = SQLITE4_NOMEM; }else{ char **azCols = (char **)pData; /* Names of result columns */ char **azVals = &azCols[nCol]; /* Results */ int *aiTypes = (int *)&azVals[nCol]; /* Result types */ int i; assert(sizeof(int) <= sizeof(char *)); /* save off ptrs to column names */ for(i=0; i<nCol; i++){ azCols[i] = (char *)sqlite4_column_name(pStmt, i); } do{ /* extract the data and data types */ for(i=0; i<nCol; i++){ azVals[i] = (char *)sqlite4_column_text(pStmt, i); aiTypes[i] = sqlite4_column_type(pStmt, i); if( !azVals[i] && (aiTypes[i]!=SQLITE4_NULL) ){ rc = SQLITE4_NOMEM; break; /* from for */ } } /* end for */ /* if data and types extracted successfully... */ if( SQLITE4_ROW == rc ){ /* call the supplied callback with the result row data */ if( xCallback(pArg, nCol, azVals, azCols, aiTypes) ){ rc = SQLITE4_ABORT; }else{ rc = sqlite4_step(pStmt); } } } while( SQLITE4_ROW == rc ); sqlite4_free(0, pData); } }else{ do{ rc = sqlite4_step(pStmt); } while( rc == SQLITE4_ROW ); } } /* print usage stats if stats on */ if( pArg && pArg->statsOn ){ display_stats(db, pArg, 0); } /* Finalize the statement just executed. If this fails, save a ** copy of the error message. Otherwise, set zSql to point to the ** next statement to execute. */ rc2 = sqlite4_finalize(pStmt); if( rc!=SQLITE4_NOMEM ) rc = rc2; if( rc==SQLITE4_OK ){ zSql = zLeftover; while( IsSpace(zSql[0]) ) zSql++; }else if( pzErrMsg ){ *pzErrMsg = save_err_msg(db); } /* clear saved stmt handle */ |
︙ | ︙ | |||
1268 1269 1270 1271 1272 1273 1274 | return 0; }else if( strncmp(zSql, "CREATE VIRTUAL TABLE", 20)==0 ){ char *zIns; if( !p->writableSchema ){ fprintf(p->out, "PRAGMA writable_schema=ON;\n"); p->writableSchema = 1; } | | | | | | < < < | | | | | | | | | | | | | | | | | | < | | < < < < | | | | | | | | 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 | return 0; }else if( strncmp(zSql, "CREATE VIRTUAL TABLE", 20)==0 ){ char *zIns; if( !p->writableSchema ){ fprintf(p->out, "PRAGMA writable_schema=ON;\n"); p->writableSchema = 1; } zIns = sqlite4_mprintf(0, "INSERT INTO sqlite_master(type,name,tbl_name,rootpage,sql)" "VALUES('table','%q','%q',0,'%q');", zTable, zTable, zSql); fprintf(p->out, "%s\n", zIns); sqlite4_free(0, zIns); return 0; }else{ fprintf(p->out, "%s;\n", zSql); } if( strcmp(zType, "table")==0 ){ sqlite4_stmt *pTableInfo = 0; char *zSelect = 0; char *zTableInfo = 0; char *zTmp = 0; int nRow = 0; zTableInfo = appendText(zTableInfo, "PRAGMA table_info(", 0); zTableInfo = appendText(zTableInfo, zTable, '"'); zTableInfo = appendText(zTableInfo, ");", 0); rc = sqlite4_prepare(p->db, zTableInfo, -1, &pTableInfo, 0); free(zTableInfo); if( rc!=SQLITE4_OK || !pTableInfo ){ return 1; } zSelect = appendText(zSelect, "SELECT 'INSERT INTO ' || ", 0); zTmp = appendText(zTmp, zTable, '"'); if( zTmp ){ zSelect = appendText(zSelect, zTmp, '\''); } zSelect = appendText(zSelect, " || ' VALUES(' || ", 0); rc = sqlite4_step(pTableInfo); while( rc==SQLITE4_ROW ){ const char *zText = (const char *)sqlite4_column_text(pTableInfo, 1); zSelect = appendText(zSelect, "quote(", 0); zSelect = appendText(zSelect, zText, '"'); rc = sqlite4_step(pTableInfo); if( rc==SQLITE4_ROW ){ zSelect = appendText(zSelect, ") || ',' || ", 0); }else{ zSelect = appendText(zSelect, ") ", 0); } nRow++; } rc = sqlite4_finalize(pTableInfo); if( rc!=SQLITE4_OK || nRow==0 ){ free(zSelect); return 1; } zSelect = appendText(zSelect, "|| ')' FROM ", 0); zSelect = appendText(zSelect, zTable, '"'); rc = run_table_dump_query(p, zSelect, zPrepStmt); if( rc==SQLITE4_CORRUPT ){ zSelect = appendText(zSelect, " ORDER BY rowid DESC", 0); run_table_dump_query(p, zSelect, 0); } if( zSelect ) free(zSelect); } return 0; } /* ** Run zQuery. Use dump_callback() as the callback routine so that ** the contents of the query are output as SQL statements. ** ** If we get a SQLITE4_CORRUPT error, rerun the query after appending ** "ORDER BY rowid DESC" to the end. */ static int run_schema_dump_query( struct callback_data *p, const char *zQuery ){ int rc; char *zErr = 0; rc = sqlite4_exec(p->db, zQuery, dump_callback, p, &zErr); if( rc==SQLITE4_CORRUPT ){ char *zQ2; int len = strlen30(zQuery); fprintf(p->out, "/****** CORRUPTION ERROR *******/\n"); if( zErr ){ fprintf(p->out, "/****** %s ******/\n", zErr); sqlite4_free(0, zErr); zErr = 0; } zQ2 = malloc( len+100 ); if( zQ2==0 ) return rc; sqlite4_snprintf(zQ2,sizeof(zQ2), "%s ORDER BY rowid DESC", zQuery); rc = sqlite4_exec(p->db, zQ2, dump_callback, p, &zErr); if( rc ){ fprintf(p->out, "/****** ERROR: %s ******/\n", zErr); }else{ rc = SQLITE4_CORRUPT; } sqlite4_free(0, zErr); free(zQ2); } return rc; } /* ** Text of a help message */ static char zHelp[] = ".bail ON|OFF Stop after hitting an error. Default OFF\n" ".databases List names and files of attached databases\n" ".dump ?TABLE? ... Dump the database in an SQL text format\n" " If TABLE specified, only dump tables matching\n" " LIKE pattern TABLE.\n" ".echo ON|OFF Turn command echo on or off\n" ".exit Exit this program\n" ".explain ?ON|OFF? Turn output mode suitable for EXPLAIN on or off.\n" " With no args, it turns EXPLAIN on.\n" ".header(s) ON|OFF Turn display of headers on or off\n" ".help Show this message\n" ".import FILE TABLE Import data from FILE into TABLE\n" ".indices ?TABLE? Show names of all indices\n" " If TABLE specified, only show indices for tables\n" " matching LIKE pattern TABLE.\n" #ifdef SQLITE4_ENABLE_IOTRACE ".iotrace FILE Enable I/O diagnostic logging to FILE\n" #endif #ifndef SQLITE4_OMIT_LOAD_EXTENSION ".load FILE ?ENTRY? Load an extension library\n" #endif ".log FILE|off Turn logging on or off. FILE can be stderr/stdout\n" ".mode MODE ?TABLE? Set output mode where MODE is one of:\n" " csv Comma-separated values\n" " column Left-aligned columns. (See .width)\n" " html HTML <table> code\n" " insert SQL insert statements for TABLE\n" " line One value per line\n" " list Values delimited by .separator string\n" " tabs Tab-separated values\n" " tcl TCL list elements\n" ".nullvalue STRING Print STRING in place of NULL values\n" ".output FILENAME Send output to FILENAME\n" ".output stdout Send output to the screen\n" ".prompt MAIN CONTINUE Replace the standard prompts\n" ".quit Exit this program\n" ".read FILENAME Execute SQL in FILENAME\n" ".schema ?TABLE? Show the CREATE statements\n" " If TABLE specified, only show tables matching\n" " LIKE pattern TABLE.\n" ".separator STRING Change separator used by output mode and .import\n" ".show Show the current values for various settings\n" ".stats ON|OFF Turn stats on or off\n" ".tables ?TABLE? List names of tables\n" " If TABLE specified, only list tables matching\n" " LIKE pattern TABLE.\n" ".width NUM1 NUM2 ... Set column widths for \"column\" mode\n" ; static char zTimerHelp[] = ".timer ON|OFF Turn the CPU timer measurement on or off\n" ; /* Forward reference */ static int process_input(struct callback_data *p, FILE *in); /* ** Make sure the database is open. If it is not, then open it. If ** the database fails to open, print an error message and exit. */ static void open_db(struct callback_data *p){ if( p->db==0 ){ sqlite4_open(0, p->zDbFilename, &p->db, 0); db = p->db; if( db && sqlite4_errcode(db)==SQLITE4_OK ){ sqlite4_create_function(db, "shellstatic", 0, SQLITE4_UTF8, 0, shellstaticFunc, 0, 0); } if( db==0 || SQLITE4_OK!=sqlite4_errcode(db) ){ fprintf(stderr,"Error: unable to open database \"%s\": %s\n", p->zDbFilename, sqlite4_errmsg(db)); exit(1); } #if 0 /*ndef SQLITE4_OMIT_LOAD_EXTENSION*/ sqlite4_enable_load_extension(p->db, 1); #endif } } /* ** Do C-language style dequoting. ** |
︙ | ︙ | |||
1517 1518 1519 1520 1521 1522 1523 | val = 1; }else if( strcmp(zArg,"yes")==0 ){ val = 1; } return val; } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < > | 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 | val = 1; }else if( strcmp(zArg,"yes")==0 ){ val = 1; } return val; } /* ** If an input line begins with "." then invoke this routine to ** process that line. ** ** Return 1 on error, 2 to exit, and 0 otherwise. */ static int do_meta_command(char *zLine, struct callback_data *p){ int i = 1; int nArg = 0; int rc = 0; int c, n; char *azArg[50]; /* Parse the input line into tokens. */ while( zLine[i] && nArg<ArraySize(azArg) ){ while( IsSpace(zLine[i]) ){ i++; } if( zLine[i]==0 ) break; |
︙ | ︙ | |||
1597 1598 1599 1600 1601 1602 1603 | azArg[nArg++] = &zLine[i]; while( zLine[i] && !IsSpace(zLine[i]) ){ i++; } if( zLine[i] ) zLine[i++] = 0; resolve_backslashes(azArg[nArg-1]); } } | | < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | | | 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 | azArg[nArg++] = &zLine[i]; while( zLine[i] && !IsSpace(zLine[i]) ){ i++; } if( zLine[i] ) zLine[i++] = 0; resolve_backslashes(azArg[nArg-1]); } } if( nArg==0 ) return 0; /* no tokens, no error */ n = strlen30(azArg[0]); c = azArg[0][0]; if( c=='b' && n>=3 && strncmp(azArg[0], "bail", n)==0 && nArg>1 && nArg<3 ){ bail_on_error = booleanValue(azArg[1]); }else if( c=='d' && n>1 && strncmp(azArg[0], "databases", n)==0 && nArg==1 ){ struct callback_data data; char *zErrMsg = 0; open_db(p); memcpy(&data, p, sizeof(data)); data.showHeader = 1; data.mode = MODE_Column; data.colWidth[0] = 3; data.colWidth[1] = 15; data.colWidth[2] = 58; data.cnt = 0; sqlite4_exec(p->db, "PRAGMA database_list; ", callback, &data, &zErrMsg); if( zErrMsg ){ fprintf(stderr,"Error: %s\n", zErrMsg); sqlite4_free(0, zErrMsg); rc = 1; } }else if( c=='d' && strncmp(azArg[0], "dump", n)==0 && nArg<3 ){ open_db(p); /* When playing back a "dump", the content might appear in an order ** which causes immediate foreign key constraints to be violated. ** So disable foreign-key constraint enforcement to prevent problems. */ fprintf(p->out, "PRAGMA foreign_keys=OFF;\n"); fprintf(p->out, "BEGIN TRANSACTION;\n"); p->writableSchema = 0; sqlite4_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0); p->nErr = 0; if( nArg==1 ){ run_schema_dump_query(p, "SELECT name, type, sql FROM sqlite_master " "WHERE sql NOT NULL AND type=='table' AND name!='sqlite_sequence'" ); run_schema_dump_query(p, |
︙ | ︙ | |||
1712 1713 1714 1715 1716 1717 1718 | zShellStatic = 0; } } if( p->writableSchema ){ fprintf(p->out, "PRAGMA writable_schema=OFF;\n"); p->writableSchema = 0; } | | | | 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 | zShellStatic = 0; } } if( p->writableSchema ){ fprintf(p->out, "PRAGMA writable_schema=OFF;\n"); p->writableSchema = 0; } sqlite4_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0); sqlite4_exec(p->db, "RELEASE dump;", 0, 0, 0); fprintf(p->out, p->nErr ? "ROLLBACK; -- due to errors\n" : "COMMIT;\n"); }else if( c=='e' && strncmp(azArg[0], "echo", n)==0 && nArg>1 && nArg<3 ){ p->echoOn = booleanValue(azArg[1]); }else |
︙ | ︙ | |||
1775 1776 1777 1778 1779 1780 1781 | fprintf(stderr,"%s",zTimerHelp); } }else if( c=='i' && strncmp(azArg[0], "import", n)==0 && nArg==3 ){ char *zTable = azArg[2]; /* Insert data into this table */ char *zFile = azArg[1]; /* The file from which to extract data */ | | | | | | | | | | | | | | | | | 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 | fprintf(stderr,"%s",zTimerHelp); } }else if( c=='i' && strncmp(azArg[0], "import", n)==0 && nArg==3 ){ char *zTable = azArg[2]; /* Insert data into this table */ char *zFile = azArg[1]; /* The file from which to extract data */ sqlite4_stmt *pStmt = NULL; /* A statement */ int nCol; /* Number of columns in the table */ int nByte; /* Number of bytes in an SQL string */ int i, j; /* Loop counters */ int nSep; /* Number of bytes in p->separator[] */ char *zSql; /* An SQL statement */ char *zLine; /* A single line of input from the file */ char **azCol; /* zLine[] broken up into columns */ char *zCommit; /* How to commit changes */ FILE *in; /* The input file */ int lineno = 0; /* Line number of input file */ open_db(p); nSep = strlen30(p->separator); if( nSep==0 ){ fprintf(stderr, "Error: non-null separator required for import\n"); return 1; } zSql = sqlite4_mprintf(0, "SELECT * FROM %s", zTable); if( zSql==0 ){ fprintf(stderr, "Error: out of memory\n"); return 1; } nByte = strlen30(zSql); rc = sqlite4_prepare(p->db, zSql, -1, &pStmt, 0); sqlite4_free(0, zSql); if( rc ){ if (pStmt) sqlite4_finalize(pStmt); fprintf(stderr,"Error: %s\n", sqlite4_errmsg(db)); return 1; } nCol = sqlite4_column_count(pStmt); sqlite4_finalize(pStmt); pStmt = 0; if( nCol==0 ) return 0; /* no columns, no error */ zSql = malloc( nByte + 20 + nCol*2 ); if( zSql==0 ){ fprintf(stderr, "Error: out of memory\n"); return 1; } sqlite4_snprintf(zSql, nByte+20, "INSERT INTO %s VALUES(?", zTable); j = strlen30(zSql); for(i=1; i<nCol; i++){ zSql[j++] = ','; zSql[j++] = '?'; } zSql[j++] = ')'; zSql[j] = 0; rc = sqlite4_prepare(p->db, zSql, -1, &pStmt, 0); free(zSql); if( rc ){ fprintf(stderr, "Error: %s\n", sqlite4_errmsg(db)); if (pStmt) sqlite4_finalize(pStmt); return 1; } in = fopen(zFile, "rb"); if( in==0 ){ fprintf(stderr, "Error: cannot open \"%s\"\n", zFile); sqlite4_finalize(pStmt); return 1; } azCol = malloc( sizeof(azCol[0])*(nCol+1) ); if( azCol==0 ){ fprintf(stderr, "Error: out of memory\n"); fclose(in); sqlite4_finalize(pStmt); return 1; } sqlite4_exec(p->db, "BEGIN", 0, 0, 0); zCommit = "COMMIT"; while( (zLine = local_getline(0, in, 1))!=0 ){ char *z, c; int inQuote = 0; lineno++; azCol[0] = zLine; for(i=0, z=zLine; (c = *z)!=0; z++){ |
︙ | ︙ | |||
1881 1882 1883 1884 1885 1886 1887 | int k; for(z=azCol[i], j=1, k=0; z[j]; j++){ if( z[j]=='"' ){ j++; if( z[j]==0 ) break; } z[k++] = z[j]; } z[k] = 0; } | | | | | | | | | | | | | | | | | | | | | | > | | > > > > > > > > > > > > > | | | 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 | int k; for(z=azCol[i], j=1, k=0; z[j]; j++){ if( z[j]=='"' ){ j++; if( z[j]==0 ) break; } z[k++] = z[j]; } z[k] = 0; } sqlite4_bind_text(pStmt, i+1, azCol[i], -1, SQLITE4_STATIC); } sqlite4_step(pStmt); rc = sqlite4_reset(pStmt); free(zLine); if( rc!=SQLITE4_OK ){ fprintf(stderr,"Error: %s\n", sqlite4_errmsg(db)); zCommit = "ROLLBACK"; rc = 1; break; /* from while */ } } /* end while */ free(azCol); fclose(in); sqlite4_finalize(pStmt); sqlite4_exec(p->db, zCommit, 0, 0, 0); }else if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg<3 ){ struct callback_data data; char *zErrMsg = 0; open_db(p); memcpy(&data, p, sizeof(data)); data.showHeader = 0; data.mode = MODE_List; if( nArg==1 ){ rc = sqlite4_exec(p->db, "SELECT name FROM sqlite_master " "WHERE type='index' AND name NOT LIKE 'sqlite_%' " "UNION ALL " "SELECT name FROM sqlite_temp_master " "WHERE type='index' " "ORDER BY 1", callback, &data, &zErrMsg ); }else{ zShellStatic = azArg[1]; rc = sqlite4_exec(p->db, "SELECT name FROM sqlite_master " "WHERE type='index' AND tbl_name LIKE shellstatic() " "UNION ALL " "SELECT name FROM sqlite_temp_master " "WHERE type='index' AND tbl_name LIKE shellstatic() " "ORDER BY 1", callback, &data, &zErrMsg ); zShellStatic = 0; } if( zErrMsg ){ fprintf(stderr,"Error: %s\n", zErrMsg); sqlite4_free(0, zErrMsg); rc = 1; }else if( rc != SQLITE4_OK ){ fprintf(stderr,"Error: querying sqlite_master and sqlite_temp_master\n"); rc = 1; } }else #ifdef SQLITE4_ENABLE_IOTRACE if( c=='i' && strncmp(azArg[0], "iotrace", n)==0 ){ extern void (*sqlite4IoTrace)(const char*, ...); if( iotrace && iotrace!=stdout ) fclose(iotrace); iotrace = 0; if( nArg<2 ){ sqlite4IoTrace = 0; }else if( strcmp(azArg[1], "-")==0 ){ sqlite4IoTrace = iotracePrintf; iotrace = stdout; }else{ iotrace = fopen(azArg[1], "w"); if( iotrace==0 ){ fprintf(stderr, "Error: cannot open \"%s\"\n", azArg[1]); sqlite4IoTrace = 0; rc = 1; }else{ sqlite4IoTrace = iotracePrintf; } } }else #endif #if 0 /*ndef SQLITE4_OMIT_LOAD_EXTENSION*/ if( c=='l' && strncmp(azArg[0], "load", n)==0 && nArg>=2 ){ const char *zFile, *zProc; char *zErrMsg = 0; zFile = azArg[1]; zProc = nArg>=3 ? azArg[2] : 0; open_db(p); rc = sqlite4_load_extension(p->db, zFile, zProc, &zErrMsg); if( rc!=SQLITE4_OK ){ fprintf(stderr, "Error: %s\n", zErrMsg); sqlite4_free(0, zErrMsg); rc = 1; } }else #endif if( c=='l' && strncmp(azArg[0], "log", n)==0 && nArg>=2 ){ const char *zFile = azArg[1]; if( p->pLog && p->pLog!=stdout && p->pLog!=stderr ){ fclose(p->pLog); p->pLog = 0; } if( strcmp(zFile,"stdout")==0 ){ p->pLog = stdout; }else if( strcmp(zFile, "stderr")==0 ){ p->pLog = stderr; }else if( strcmp(zFile, "off")==0 ){ p->pLog = 0; }else{ p->pLog = fopen(zFile, "w"); if( p->pLog==0 ){ fprintf(stderr, "Error: cannot open \"%s\"\n", zFile); } } }else if( c=='m' && strncmp(azArg[0], "mode", n)==0 && nArg==2 ){ int n2 = strlen30(azArg[1]); if( (n2==4 && strncmp(azArg[1],"line",n2)==0) || (n2==5 && strncmp(azArg[1],"lines",n2)==0) ){ p->mode = MODE_Line; }else if( (n2==6 && strncmp(azArg[1],"column",n2)==0) || (n2==7 && strncmp(azArg[1],"columns",n2)==0) ){ p->mode = MODE_Column; }else if( n2==4 && strncmp(azArg[1],"list",n2)==0 ){ p->mode = MODE_List; }else if( n2==4 && strncmp(azArg[1],"html",n2)==0 ){ p->mode = MODE_Html; }else if( n2==3 && strncmp(azArg[1],"tcl",n2)==0 ){ p->mode = MODE_Tcl; }else if( n2==3 && strncmp(azArg[1],"csv",n2)==0 ){ p->mode = MODE_Csv; sqlite4_snprintf(p->separator, sizeof(p->separator), ","); }else if( n2==4 && strncmp(azArg[1],"tabs",n2)==0 ){ p->mode = MODE_List; sqlite4_snprintf(p->separator, sizeof(p->separator), "\t"); }else if( n2==6 && strncmp(azArg[1],"insert",n2)==0 ){ p->mode = MODE_Insert; set_table_name(p, "table"); }else { fprintf(stderr,"Error: mode should be one of: " "column csv html insert line list tabs tcl\n"); rc = 1; |
︙ | ︙ | |||
2029 2030 2031 2032 2033 2034 2035 | fprintf(stderr, "Error: invalid arguments: " " \"%s\". Enter \".help\" for help\n", azArg[2]); rc = 1; } }else if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 && nArg==2 ) { | | | | < < < | < < < | < < | < | < | < | | 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 | fprintf(stderr, "Error: invalid arguments: " " \"%s\". Enter \".help\" for help\n", azArg[2]); rc = 1; } }else if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 && nArg==2 ) { sqlite4_snprintf(p->nullvalue, sizeof(p->nullvalue), "%.*s", (int)ArraySize(p->nullvalue)-1, azArg[1]); }else if( c=='o' && strncmp(azArg[0], "output", n)==0 && nArg==2 ){ if( p->out!=stdout ){ fclose(p->out); } if( strcmp(azArg[1],"stdout")==0 ){ p->out = stdout; sqlite4_snprintf(p->outfile, sizeof(p->outfile), "stdout"); }else{ p->out = fopen(azArg[1], "wb"); if( p->out==0 ){ fprintf(stderr,"Error: cannot write to \"%s\"\n", azArg[1]); p->out = stdout; rc = 1; } else { sqlite4_snprintf(p->outfile, sizeof(p->outfile), "%s", azArg[1]); } } }else if( c=='p' && strncmp(azArg[0], "prompt", n)==0 && (nArg==2 || nArg==3)){ if( nArg >= 2) { strncpy(mainPrompt,azArg[1],(int)ArraySize(mainPrompt)-1); |
︙ | ︙ | |||
2087 2088 2089 2090 2091 2092 2093 | rc = 1; }else{ rc = process_input(p, alt); fclose(alt); } }else | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 | rc = 1; }else{ rc = process_input(p, alt); fclose(alt); } }else if( c=='s' && strncmp(azArg[0], "schema", n)==0 && nArg<3 ){ struct callback_data data; char *zErrMsg = 0; open_db(p); memcpy(&data, p, sizeof(data)); data.showHeader = 0; |
︙ | ︙ | |||
2157 2158 2159 2160 2161 2162 2163 | " rootpage integer,\n" " sql text\n" ")"; new_argv[1] = 0; new_colv[0] = "sql"; new_colv[1] = 0; callback(&data, 1, new_argv, new_colv); | | | | | | | < | | | | < | | | | 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 | " rootpage integer,\n" " sql text\n" ")"; new_argv[1] = 0; new_colv[0] = "sql"; new_colv[1] = 0; callback(&data, 1, new_argv, new_colv); rc = SQLITE4_OK; }else if( strcmp(azArg[1],"sqlite_temp_master")==0 ){ char *new_argv[2], *new_colv[2]; new_argv[0] = "CREATE TEMP TABLE sqlite_temp_master (\n" " type text,\n" " name text,\n" " tbl_name text,\n" " rootpage integer,\n" " sql text\n" ")"; new_argv[1] = 0; new_colv[0] = "sql"; new_colv[1] = 0; callback(&data, 1, new_argv, new_colv); rc = SQLITE4_OK; }else{ zShellStatic = azArg[1]; rc = sqlite4_exec(p->db, "SELECT sql FROM " " (SELECT sql sql, type type, tbl_name tbl_name, name name" " FROM sqlite_master UNION ALL" " SELECT sql, type, tbl_name, name FROM sqlite_temp_master) " "WHERE lower(tbl_name) LIKE shellstatic()" " AND type!='meta' AND sql NOTNULL " "ORDER BY substr(type,2,1), name", callback, &data, &zErrMsg); zShellStatic = 0; } }else{ rc = sqlite4_exec(p->db, "SELECT sql FROM " " (SELECT sql sql, type type, tbl_name tbl_name, name name" " FROM sqlite_master UNION ALL" " SELECT sql, type, tbl_name, name FROM sqlite_temp_master) " "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%'" "ORDER BY substr(type,2,1), name", callback, &data, &zErrMsg ); } if( zErrMsg ){ fprintf(stderr,"Error: %s\n", zErrMsg); sqlite4_free(0, zErrMsg); rc = 1; }else if( rc != SQLITE4_OK ){ fprintf(stderr,"Error: querying schema information\n"); rc = 1; }else{ rc = 0; } }else if( c=='s' && strncmp(azArg[0], "separator", n)==0 && nArg==2 ){ sqlite4_snprintf(p->separator, sizeof(p->separator), "%.*s", (int)sizeof(p->separator)-1, azArg[1]); }else if( c=='s' && strncmp(azArg[0], "show", n)==0 && nArg==1 ){ int i; fprintf(p->out,"%9.9s: %s\n","echo", p->echoOn ? "on" : "off"); fprintf(p->out,"%9.9s: %s\n","explain", p->explainPrev.valid ? "on" :"off"); |
︙ | ︙ | |||
2242 2243 2244 2245 2246 2247 2248 | }else if( c=='s' && strncmp(azArg[0], "stats", n)==0 && nArg>1 && nArg<3 ){ p->statsOn = booleanValue(azArg[1]); }else if( c=='t' && n>1 && strncmp(azArg[0], "tables", n)==0 && nArg<3 ){ | | | | | | | | | | | | | | | | | | | | < < < < | < < | | < | | < | 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 | }else if( c=='s' && strncmp(azArg[0], "stats", n)==0 && nArg>1 && nArg<3 ){ p->statsOn = booleanValue(azArg[1]); }else if( c=='t' && n>1 && strncmp(azArg[0], "tables", n)==0 && nArg<3 ){ sqlite4_stmt *pStmt; char **azResult; int nRow, nAlloc; char *zSql = 0; int ii; open_db(p); rc = sqlite4_prepare(p->db, "PRAGMA database_list", -1, &pStmt, 0); if( rc ) return rc; zSql = sqlite4_mprintf(0, "SELECT name FROM sqlite_master" " WHERE type IN ('table','view')" " AND name NOT LIKE 'sqlite_%%'" " AND name LIKE ?1"); while( sqlite4_step(pStmt)==SQLITE4_ROW ){ const char *zDbName = (const char*)sqlite4_column_text(pStmt, 1); if( zDbName==0 || strcmp(zDbName,"main")==0 ) continue; if( strcmp(zDbName,"temp")==0 ){ zSql = sqlite4_mprintf(0, "%z UNION ALL " "SELECT 'temp.' || name FROM sqlite_temp_master" " WHERE type IN ('table','view')" " AND name NOT LIKE 'sqlite_%%'" " AND name LIKE ?1", zSql); }else{ zSql = sqlite4_mprintf(0, "%z UNION ALL " "SELECT '%q.' || name FROM \"%w\".sqlite_master" " WHERE type IN ('table','view')" " AND name NOT LIKE 'sqlite_%%'" " AND name LIKE ?1", zSql, zDbName, zDbName); } } sqlite4_finalize(pStmt); zSql = sqlite4_mprintf(0, "%z ORDER BY 1", zSql); rc = sqlite4_prepare(p->db, zSql, -1, &pStmt, 0); sqlite4_free(0, zSql); if( rc ) return rc; nRow = nAlloc = 0; azResult = 0; if( nArg>1 ){ sqlite4_bind_text(pStmt, 1, azArg[1], -1, SQLITE4_TRANSIENT); }else{ sqlite4_bind_text(pStmt, 1, "%", -1, SQLITE4_STATIC); } while( sqlite4_step(pStmt)==SQLITE4_ROW ){ if( nRow>=nAlloc ){ char **azNew; int n = nAlloc*2 + 10; azNew = sqlite4_realloc(0, azResult, sizeof(azResult[0])*n); if( azNew==0 ){ fprintf(stderr, "Error: out of memory\n"); break; } nAlloc = n; azResult = azNew; } azResult[nRow] = sqlite4_mprintf(0, "%s", sqlite4_column_text(pStmt, 0)); if( azResult[nRow] ) nRow++; } sqlite4_finalize(pStmt); if( nRow>0 ){ int len, maxlen = 0; int i, j; int nPrintCol, nPrintRow; for(i=0; i<nRow; i++){ len = strlen30(azResult[i]); if( len>maxlen ) maxlen = len; } nPrintCol = 80/(maxlen+2); if( nPrintCol<1 ) nPrintCol = 1; nPrintRow = (nRow + nPrintCol - 1)/nPrintCol; for(i=0; i<nPrintRow; i++){ for(j=i; j<nRow; j+=nPrintRow){ char *zSp = j<nPrintRow ? "" : " "; printf("%s%-*s", zSp, maxlen, azResult[j] ? azResult[j] : ""); } printf("\n"); } } for(ii=0; ii<nRow; ii++) sqlite4_free(0, azResult[ii]); sqlite4_free(0, azResult); }else if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 && nArg>=2 ){ static const struct { const char *zCtrlName; /* Name of a test-control option */ int ctrlCode; /* Integer code for that option */ } aCtrl[] = { { "fault_install", SQLITE4_TESTCTRL_FAULT_INSTALL }, { "assert", SQLITE4_TESTCTRL_ASSERT }, { "always", SQLITE4_TESTCTRL_ALWAYS }, { "optimizations", SQLITE4_TESTCTRL_OPTIMIZATIONS }, { "iskeyword", SQLITE4_TESTCTRL_ISKEYWORD }, }; int testctrl = -1; int rc = 0; int i, n; open_db(p); /* convert testctrl text option to value. allow any unique prefix |
︙ | ︙ | |||
2364 2365 2366 2367 2368 2369 2370 | fprintf(stderr, "ambiguous option name: \"%s\"\n", azArg[1]); testctrl = -1; break; } } } if( testctrl<0 ) testctrl = atoi(azArg[1]); | | | | | | < < < < < < < < < < < < < < < < < < < < < < < < | | | | | | | | < | < < < < < < < < < < < < < < < < < < < < | < < < < < < < < < < < < | 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 | fprintf(stderr, "ambiguous option name: \"%s\"\n", azArg[1]); testctrl = -1; break; } } } if( testctrl<0 ) testctrl = atoi(azArg[1]); if( (testctrl<SQLITE4_TESTCTRL_FIRST) || (testctrl>SQLITE4_TESTCTRL_LAST) ){ fprintf(stderr,"Error: invalid testctrl option: %s\n", azArg[1]); }else{ switch(testctrl){ /* sqlite4_test_control(int, db, int) */ case SQLITE4_TESTCTRL_OPTIMIZATIONS: case SQLITE4_TESTCTRL_RESERVE: if( nArg==3 ){ int opt = (int)strtol(azArg[2], 0, 0); rc = sqlite4_test_control(testctrl, p->db, opt); printf("%d (0x%08x)\n", rc, rc); } else { fprintf(stderr,"Error: testctrl %s takes a single int option\n", azArg[1]); } break; /* sqlite4_test_control(int, int) */ case SQLITE4_TESTCTRL_ASSERT: case SQLITE4_TESTCTRL_ALWAYS: if( nArg==3 ){ int opt = atoi(azArg[2]); rc = sqlite4_test_control(testctrl, opt); printf("%d (0x%08x)\n", rc, rc); } else { fprintf(stderr,"Error: testctrl %s takes a single int option\n", azArg[1]); } break; /* sqlite4_test_control(int, char *) */ #ifdef SQLITE4_N_KEYWORD case SQLITE4_TESTCTRL_ISKEYWORD: if( nArg==3 ){ const char *opt = azArg[2]; rc = sqlite4_test_control(testctrl, opt); printf("%d (0x%08x)\n", rc, rc); } else { fprintf(stderr,"Error: testctrl %s takes a single char * option\n", azArg[1]); } break; #endif case SQLITE4_TESTCTRL_FAULT_INSTALL: default: fprintf(stderr,"Error: CLI support for testctrl %s not implemented\n", azArg[1]); break; } } }else if( HAS_TIMER && c=='t' && n>=5 && strncmp(azArg[0], "timer", n)==0 && nArg==2 ){ enableTimer = booleanValue(azArg[1]); }else if( c=='v' && strncmp(azArg[0], "version", n)==0 ){ printf("SQLite %s %s\n" /*extra-version-info*/, sqlite4_libversion(), sqlite4_sourceid()); }else if( c=='w' && strncmp(azArg[0], "width", n)==0 && nArg>1 ){ int j; assert( nArg<=ArraySize(azArg) ); for(j=1; j<nArg && j<ArraySize(p->colWidth); j++){ p->colWidth[j-1] = atoi(azArg[j]); |
︙ | ︙ | |||
2563 2564 2565 2566 2567 2568 2569 | ** ends in the middle of a string literal or C-style comment. */ static int _is_complete(char *zSql, int nSql){ int rc; if( zSql==0 ) return 1; zSql[nSql] = ';'; zSql[nSql+1] = 0; | | | 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 | ** ends in the middle of a string literal or C-style comment. */ static int _is_complete(char *zSql, int nSql){ int rc; if( zSql==0 ) return 1; zSql[nSql] = ';'; zSql[nSql+1] = 0; rc = sqlite4_complete(zSql); zSql[nSql] = 0; return rc; } /* ** Read input from *in and process it. If *in==0 then input ** is interactive - the user is typing it it. Otherwise, input |
︙ | ︙ | |||
2593 2594 2595 2596 2597 2598 2599 | int startline = 0; while( errCnt==0 || !bail_on_error || (in==0 && stdin_is_interactive) ){ fflush(p->out); free(zLine); zLine = one_input_line(zSql, in); if( zLine==0 ){ | < < | | 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 | int startline = 0; while( errCnt==0 || !bail_on_error || (in==0 && stdin_is_interactive) ){ fflush(p->out); free(zLine); zLine = one_input_line(zSql, in); if( zLine==0 ){ break; /* We have reached EOF */ } if( seenInterrupt ){ if( in!=0 ) break; seenInterrupt = 0; } lineno++; if( (zSql==0 || zSql[0]==0) && _all_whitespace(zLine) ) continue; |
︙ | ︙ | |||
2642 2643 2644 2645 2646 2647 2648 | exit(1); } zSql[nSql++] = '\n'; memcpy(&zSql[nSql], zLine, len+1); nSql += len; } if( zSql && _contains_semicolon(&zSql[nSqlPrior], nSql-nSqlPrior) | | | | | | | > > | < | < | | | | < | | | | | 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 | exit(1); } zSql[nSql++] = '\n'; memcpy(&zSql[nSql], zLine, len+1); nSql += len; } if( zSql && _contains_semicolon(&zSql[nSqlPrior], nSql-nSqlPrior) && sqlite4_complete(zSql) ){ p->cnt = 0; open_db(p); BEGIN_TIMER; rc = shell_exec(p->db, zSql, shell_callback, p, &zErrMsg); END_TIMER; if( rc || zErrMsg ){ char zPrefix[100]; if( in!=0 || !stdin_is_interactive ){ sqlite4_snprintf(zPrefix, sizeof(zPrefix), "Error: near line %d:", startline); }else{ sqlite4_snprintf(zPrefix, sizeof(zPrefix), "Error:"); } if( zErrMsg!=0 ){ fprintf(stderr, "%s %s\n", zPrefix, zErrMsg); sqlite4_free(0, zErrMsg); zErrMsg = 0; }else{ fprintf(stderr, "%s %s\n", zPrefix, sqlite4_errmsg(p->db)); } errCnt++; } free(zSql); zSql = 0; nSql = 0; } } if( zSql ){ if( !_all_whitespace(zSql) ){ fprintf(stderr, "Error: incomplete SQL: %s\n", zSql); } free(zSql); } free(zLine); return errCnt; } /* ** Return a pathname which is the user's home directory. A ** 0 return indicates an error of some kind. Space to hold the ** resulting string is obtained from malloc(). The calling ** function should free the result. */ static char *find_home_dir(void){ char *home_dir = NULL; #if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__) && !defined(_WIN32_WCE) && !defined(__RTP__) && !defined(_WRS_KERNEL) struct passwd *pwent; uid_t uid = getuid(); if( (pwent=getpwuid(uid)) != NULL) { home_dir = pwent->pw_dir; } #endif #if defined(_WIN32_WCE) /* Windows CE (arm-wince-mingw32ce-gcc) does not provide getenv() */ home_dir = strdup("/"); #else #if defined(_WIN32) || defined(WIN32) || defined(__OS2__) if (!home_dir) { home_dir = getenv("USERPROFILE"); } #endif if (!home_dir) { home_dir = getenv("HOME"); } #if defined(_WIN32) || defined(WIN32) || defined(__OS2__) if (!home_dir) { char *zDrive, *zPath; int n; zDrive = getenv("HOMEDRIVE"); zPath = getenv("HOMEPATH"); if( zDrive && zPath ){ n = strlen30(zDrive) + strlen30(zPath) + 1; home_dir = malloc( n ); if( home_dir==0 ) return 0; sqlite4_snprintf(home_dir, n, "%s%s", zDrive, zPath); return home_dir; } home_dir = "c:\\"; } #endif #endif /* !_WIN32_WCE */ |
︙ | ︙ | |||
2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 | struct callback_data *p, /* Configuration data */ const char *sqliterc_override /* Name of config file. NULL to use default */ ){ char *home_dir = NULL; const char *sqliterc = sqliterc_override; char *zBuf = 0; FILE *in = NULL; int rc = 0; if (sqliterc == NULL) { home_dir = find_home_dir(); if( home_dir==0 ){ #if !defined(__RTP__) && !defined(_WRS_KERNEL) fprintf(stderr,"%s: Error: cannot locate your home directory\n", Argv0); #endif return 1; } | > > > > > > > | > | | > > > > > < < < < < < < < < < > < | | | 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 | struct callback_data *p, /* Configuration data */ const char *sqliterc_override /* Name of config file. NULL to use default */ ){ char *home_dir = NULL; const char *sqliterc = sqliterc_override; char *zBuf = 0; FILE *in = NULL; int nBuf; int rc = 0; if (sqliterc == NULL) { home_dir = find_home_dir(); if( home_dir==0 ){ #if !defined(__RTP__) && !defined(_WRS_KERNEL) fprintf(stderr,"%s: Error: cannot locate your home directory\n", Argv0); #endif return 1; } nBuf = strlen30(home_dir) + 16; zBuf = malloc( nBuf ); if( zBuf==0 ){ fprintf(stderr,"%s: Error: out of memory\n",Argv0); return 1; } sqlite4_snprintf(zBuf,nBuf,"%s/.sqliterc",home_dir); free(home_dir); sqliterc = (const char*)zBuf; } in = fopen(sqliterc,"rb"); if( in ){ if( stdin_is_interactive ){ fprintf(stderr,"-- Loading resources from %s\n",sqliterc); } rc = process_input(p,in); fclose(in); } free(zBuf); return rc; } /* ** Show available command line options */ static const char zOptions[] = " -help show this message\n" " -init filename read/process named file\n" " -echo print commands before execution\n" " -[no]header turn headers on or off\n" " -bail stop after hitting an error\n" " -interactive force interactive I/O\n" " -batch force batch I/O\n" " -column set output mode to 'column'\n" " -csv set output mode to 'csv'\n" " -html set output mode to HTML\n" " -line set output mode to 'line'\n" " -list set output mode to 'list'\n" " -separator 'x' set output field separator (|)\n" " -stats print memory stats before each finalize\n" " -nullvalue 'text' set text string for NULL values\n" " -version show SQLite version\n" #ifdef SQLITE4_ENABLE_MULTIPLEX " -multiplex enable the multiplexor VFS\n" #endif ; static void usage(int showDetail){ fprintf(stderr, "Usage: %s [OPTIONS] FILENAME [SQL]\n" "FILENAME is the name of an SQLite database. A new database is created\n" "if the file does not previously exist.\n", Argv0); |
︙ | ︙ | |||
2832 2833 2834 2835 2836 2837 2838 | ** Initialize the state information in data */ static void main_init(struct callback_data *data) { memset(data, 0, sizeof(*data)); data->mode = MODE_List; memcpy(data->separator,"|", 2); data->showHeader = 0; | < | | | | | | | 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 | ** Initialize the state information in data */ static void main_init(struct callback_data *data) { memset(data, 0, sizeof(*data)); data->mode = MODE_List; memcpy(data->separator,"|", 2); data->showHeader = 0; sqlite4_env_config(0, SQLITE4_ENVCONFIG_LOG, shellLog, data); sqlite4_snprintf(mainPrompt,sizeof(mainPrompt), "sqlite> "); sqlite4_snprintf(continuePrompt,sizeof(continuePrompt)," ...> "); sqlite4_env_config(0, SQLITE4_ENVCONFIG_SINGLETHREAD); } int main(int argc, char **argv){ char *zErrMsg = 0; struct callback_data data; const char *zInitFile = 0; char *zFirstCmd = 0; int i; int rc = 0; if( strcmp(sqlite4_sourceid(),SQLITE4_SOURCE_ID)!=0 ){ fprintf(stderr, "SQLite header and source version mismatch\n%s\n%s\n", sqlite4_sourceid(), SQLITE4_SOURCE_ID); exit(1); } Argv0 = argv[0]; main_init(&data); stdin_is_interactive = isatty(0); /* Make sure we have a valid signal handler early, before anything |
︙ | ︙ | |||
2872 2873 2874 2875 2876 2877 2878 | ** the size of the alternative malloc heap, ** and the first command to execute. */ for(i=1; i<argc-1; i++){ char *z; if( argv[i][0]!='-' ) break; z = argv[i]; | | | < < < | | | | | | < < < < < < < < < < < | | | | < < < < < < < | | < > > > > | | 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 | ** the size of the alternative malloc heap, ** and the first command to execute. */ for(i=1; i<argc-1; i++){ char *z; if( argv[i][0]!='-' ) break; z = argv[i]; if( z[0]=='-' && z[1]=='-' ) z++; if( strcmp(argv[i],"-separator")==0 || strcmp(argv[i],"-nullvalue")==0 ){ i++; }else if( strcmp(argv[i],"-init")==0 ){ i++; zInitFile = argv[i]; /* Need to check for batch mode here to so we can avoid printing ** informational messages (like from process_sqliterc) before ** we do the actual processing of arguments later in a second pass. */ }else if( strcmp(argv[i],"-batch")==0 ){ stdin_is_interactive = 0; }else if( strcmp(argv[i],"-heap")==0 ){ #if defined(SQLITE4_ENABLE_MEMSYS3) || defined(SQLITE4_ENABLE_MEMSYS5) int j, c; const char *zSize; sqlite4_int64 szHeap; zSize = argv[++i]; szHeap = atoi(zSize); for(j=0; (c = zSize[j])!=0; j++){ if( c=='M' ){ szHeap *= 1000000; break; } if( c=='K' ){ szHeap *= 1000; break; } if( c=='G' ){ szHeap *= 1000000000; break; } } if( szHeap>0x7fff0000 ) szHeap = 0x7fff0000; sqlite4_config(0,SQLITE4_CONFIG_HEAP, malloc((int)szHeap),(int)szHeap,64); #endif #ifdef SQLITE4_ENABLE_MULTIPLEX }else if( strcmp(argv[i],"-multiplex")==0 ){ extern int sqlite4_multiple_initialize(const char*,int); sqlite4_multiplex_initialize(0, 1); #endif } } if( i<argc ){ #if defined(SQLITE4_OS_OS2) && SQLITE4_OS_OS2 data.zDbFilename = (const char *)convertCpPathToUtf8( argv[i++] ); #else data.zDbFilename = argv[i++]; #endif }else{ #ifndef SQLITE4_OMIT_MEMORYDB data.zDbFilename = ":memory:"; #else data.zDbFilename = 0; #endif /***** Begin Fossil Patch *****/ { extern void fossil_open(const char **); |
︙ | ︙ | |||
2954 2955 2956 2957 2958 2959 2960 | if( i<argc ){ fprintf(stderr,"%s: Error: too many options: \"%s\"\n", Argv0, argv[i]); fprintf(stderr,"Use -help for a list of options.\n"); return 1; } data.out = stdout; | | | 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 | if( i<argc ){ fprintf(stderr,"%s: Error: too many options: \"%s\"\n", Argv0, argv[i]); fprintf(stderr,"Use -help for a list of options.\n"); return 1; } data.out = stdout; #ifdef SQLITE4_OMIT_MEMORYDB if( data.zDbFilename==0 ){ fprintf(stderr,"%s: Error: no database filename specified\n", Argv0); return 1; } #endif /* Go ahead and open the database file if it already exists. If the |
︙ | ︙ | |||
3003 3004 3005 3006 3007 3008 3009 | data.mode = MODE_Column; }else if( strcmp(z,"-csv")==0 ){ data.mode = MODE_Csv; memcpy(data.separator,",",2); }else if( strcmp(z,"-separator")==0 ){ i++; if(i>=argc){ | | < | | < | | < < < < < < | | < < < < < < < < < < < < < < < < < < | 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 | data.mode = MODE_Column; }else if( strcmp(z,"-csv")==0 ){ data.mode = MODE_Csv; memcpy(data.separator,",",2); }else if( strcmp(z,"-separator")==0 ){ i++; if(i>=argc){ fprintf(stderr,"%s: Error: missing argument for option: %s\n", Argv0, z); fprintf(stderr,"Use -help for a list of options.\n"); return 1; } sqlite4_snprintf(data.separator, sizeof(data.separator), "%.*s",(int)sizeof(data.separator)-1,argv[i]); }else if( strcmp(z,"-nullvalue")==0 ){ i++; if(i>=argc){ fprintf(stderr,"%s: Error: missing argument for option: %s\n", Argv0, z); fprintf(stderr,"Use -help for a list of options.\n"); return 1; } sqlite4_snprintf(data.nullvalue, sizeof(data.nullvalue), "%.*s",(int)sizeof(data.nullvalue)-1,argv[i]); }else if( strcmp(z,"-header")==0 ){ data.showHeader = 1; }else if( strcmp(z,"-noheader")==0 ){ data.showHeader = 0; }else if( strcmp(z,"-echo")==0 ){ data.echoOn = 1; }else if( strcmp(z,"-stats")==0 ){ data.statsOn = 1; }else if( strcmp(z,"-bail")==0 ){ bail_on_error = 1; }else if( strcmp(z,"-version")==0 ){ printf("%s %s\n", sqlite4_libversion(), sqlite4_sourceid()); return 0; }else if( strcmp(z,"-interactive")==0 ){ stdin_is_interactive = 1; }else if( strcmp(z,"-batch")==0 ){ stdin_is_interactive = 0; }else if( strcmp(z,"-heap")==0 ){ i++; #ifdef SQLITE4_ENABLE_MULTIPLEX }else if( strcmp(z,"-multiplex")==0 ){ i++; #endif }else if( strcmp(z,"-help")==0 || strcmp(z, "--help")==0 ){ usage(1); }else{ fprintf(stderr,"%s: Error: unknown option: %s\n", Argv0, z); fprintf(stderr,"Use -help for a list of options.\n"); return 1; } } |
︙ | ︙ | |||
3103 3104 3105 3106 3107 3108 3109 | char *zHome; char *zHistory = 0; int nHistory; printf( "SQLite version %s %.19s\n" /*extra-version-info*/ "Enter \".help\" for instructions\n" "Enter SQL statements terminated with a \";\"\n", | | | > | | 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 | char *zHome; char *zHistory = 0; int nHistory; printf( "SQLite version %s %.19s\n" /*extra-version-info*/ "Enter \".help\" for instructions\n" "Enter SQL statements terminated with a \";\"\n", sqlite4_libversion(), sqlite4_sourceid() ); zHome = find_home_dir(); if( zHome ){ nHistory = strlen30(zHome) + 20; if( (zHistory = malloc(nHistory))!=0 ){ sqlite4_snprintf(zHistory, nHistory, "%s/.sqlite_history", zHome); } } #if defined(HAVE_READLINE) && HAVE_READLINE==1 if( zHistory ) read_history(zHistory); #endif rc = process_input(&data, 0); if( zHistory ){ stifle_history(100); write_history(zHistory); free(zHistory); } free(zHome); }else{ rc = process_input(&data, stdin); } } set_table_name(&data, 0); if( data.db ){ sqlite4_close(data.db); } return rc; } |
Changes to src/shun.c.
︙ | ︙ | |||
28 29 30 31 32 33 34 | static Stmt q; int rc; if( zUuid==0 || zUuid[0]==0 ) return 0; db_static_prepare(&q, "SELECT 1 FROM shun WHERE uuid=:uuid"); db_bind_text(&q, ":uuid", zUuid); rc = db_step(&q); db_reset(&q); | | | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | static Stmt q; int rc; if( zUuid==0 || zUuid[0]==0 ) return 0; db_static_prepare(&q, "SELECT 1 FROM shun WHERE uuid=:uuid"); db_bind_text(&q, ":uuid", zUuid); rc = db_step(&q); db_reset(&q); return rc==SQLITE4_ROW; } /* ** WEBPAGE: shun */ void shun_page(void){ Stmt q; |
︙ | ︙ | |||
162 163 164 165 166 167 168 | @ </blockquote> @ @ <hr /><p>Shunned Artifacts:</p> @ <blockquote><p> db_prepare(&q, "SELECT uuid, EXISTS(SELECT 1 FROM blob WHERE blob.uuid=shun.uuid)" " FROM shun ORDER BY uuid"); | | | 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | @ </blockquote> @ @ <hr /><p>Shunned Artifacts:</p> @ <blockquote><p> db_prepare(&q, "SELECT uuid, EXISTS(SELECT 1 FROM blob WHERE blob.uuid=shun.uuid)" " FROM shun ORDER BY uuid"); while( db_step(&q)==SQLITE4_ROW ){ const char *zUuid = db_column_text(&q, 0); int stillExists = db_column_int(&q, 1); cnt++; if( stillExists ){ @ <b><a href="%s(g.zTop)/artifact/%s(zUuid)">%s(zUuid)</a></b><br /> }else{ @ <b>%s(zUuid)</b><br /> |
︙ | ︙ | |||
192 193 194 195 196 197 198 | db_multi_exec( "CREATE TEMP TABLE toshun(rid INTEGER PRIMARY KEY);" "INSERT INTO toshun SELECT rid FROM blob, shun WHERE blob.uuid=shun.uuid;" ); db_prepare(&q, "SELECT rid FROM delta WHERE srcid IN toshun" ); | | | 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | db_multi_exec( "CREATE TEMP TABLE toshun(rid INTEGER PRIMARY KEY);" "INSERT INTO toshun SELECT rid FROM blob, shun WHERE blob.uuid=shun.uuid;" ); db_prepare(&q, "SELECT rid FROM delta WHERE srcid IN toshun" ); while( db_step(&q)==SQLITE4_ROW ){ int srcid = db_column_int(&q, 0); content_undelta(srcid); } db_finalize(&q); db_multi_exec( "DELETE FROM delta WHERE rid IN toshun;" "DELETE FROM blob WHERE rid IN toshun;" |
︙ | ︙ | |||
247 248 249 250 251 252 253 | @ @ <table cellpadding="0" cellspacing="0" border="0"> @ <tr><th style="padding-right: 15px;text-align: right;">rcvid</th> @ <th style="padding-right: 15px;text-align: left;">Date</th> @ <th style="padding-right: 15px;text-align: left;">User</th> @ <th style="text-align: left;">IP Address</th></tr> cnt = 0; | | | 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | @ @ <table cellpadding="0" cellspacing="0" border="0"> @ <tr><th style="padding-right: 15px;text-align: right;">rcvid</th> @ <th style="padding-right: 15px;text-align: left;">Date</th> @ <th style="padding-right: 15px;text-align: left;">User</th> @ <th style="text-align: left;">IP Address</th></tr> cnt = 0; while( db_step(&q)==SQLITE4_ROW ){ int rcvid = db_column_int(&q, 0); const char *zUser = db_column_text(&q, 1); const char *zDate = db_column_text(&q, 2); const char *zIpAddr = db_column_text(&q, 3); if( cnt==30 ){ style_submenu_element("Older", "Older", "rcvfromlist?ofst=%d", ofst+30); |
︙ | ︙ | |||
293 294 295 296 297 298 299 | " FROM rcvfrom LEFT JOIN user USING(uid)" " WHERE rcvid=%d", rcvid ); @ <table cellspacing="15" cellpadding="0" border="0"> @ <tr><td valign="top" align="right"><b>rcvid:</b></td> @ <td valign="top">%d(rcvid)</td></tr> | | | | 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | " FROM rcvfrom LEFT JOIN user USING(uid)" " WHERE rcvid=%d", rcvid ); @ <table cellspacing="15" cellpadding="0" border="0"> @ <tr><td valign="top" align="right"><b>rcvid:</b></td> @ <td valign="top">%d(rcvid)</td></tr> if( db_step(&q)==SQLITE4_ROW ){ const char *zUser = db_column_text(&q, 0); const char *zDate = db_column_text(&q, 1); const char *zIpAddr = db_column_text(&q, 2); @ <tr><td valign="top" align="right"><b>User:</b></td> @ <td valign="top">%s(zUser)</td></tr> @ <tr><td valign="top" align="right"><b>Date:</b></td> @ <td valign="top">%s(zDate)</td></tr> @ <tr><td valign="top" align="right"><b>IP Address:</b></td> @ <td valign="top">%s(zIpAddr)</td></tr> } db_finalize(&q); db_prepare(&q, "SELECT rid, uuid, size FROM blob WHERE rcvid=%d", rcvid ); @ <tr><td valign="top" align="right"><b>Artifacts:</b></td> @ <td valign="top"> while( db_step(&q)==SQLITE4_ROW ){ int rid = db_column_int(&q, 0); const char *zUuid = db_column_text(&q, 1); int size = db_column_int(&q, 2); @ <a href="%s(g.zTop)/info/%s(zUuid)">%s(zUuid)</a> @ (rid: %d(rid), size: %d(size))<br /> } @ </td></tr> @ </table> db_finalize(&q); style_footer(); } |
Changes to src/skins.c.
︙ | ︙ | |||
1132 1133 1134 1135 1136 1137 1138 | } } db_prepare(&q, "SELECT substr(name, 6), value FROM config" " WHERE name GLOB 'skin:*'" " ORDER BY name" ); | | | 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 | } } db_prepare(&q, "SELECT substr(name, 6), value FROM config" " WHERE name GLOB 'skin:*'" " ORDER BY name" ); while( db_step(&q)==SQLITE4_ROW ){ const char *zN = db_column_text(&q, 0); const char *zV = db_column_text(&q, 1); if( fossil_strcmp(zV, zCurrent)==0 ){ @ <li><p>%h(zN). <b>Currently In Use</b></p> }else{ @ <li><form action="%s(g.zTop)/setup_skin" method="post"> @ %h(zN). |
︙ | ︙ |
Changes to src/sqlcmd.c.
︙ | ︙ | |||
11 12 13 14 15 16 17 | ** ** Author contact information: ** drh@hwaci.com ** http://www.hwaci.com/drh/ ** ******************************************************************************* ** | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | ** ** Author contact information: ** drh@hwaci.com ** http://www.hwaci.com/drh/ ** ******************************************************************************* ** ** This module contains the code that initializes the "sqlite4" command-line ** shell against the repository database. The command-line shell itself ** is a copy of the "shell.c" code from SQLite. This file contains logic ** to initialize the code in shell.c. */ #include "config.h" #include "sqlcmd.h" #include <zlib.h> /* ** Implementation of the "content(X)" SQL function. Return the complete ** content of artifact identified by X as a blob. */ static void sqlcmd_content( sqlite4_context *context, int argc, sqlite4_value **argv ){ int rid; Blob cx; const char *zName; assert( argc==1 ); zName = (const char*)sqlite4_value_text(argv[0]); if( zName==0 ) return; g.db = sqlite4_context_db_handle(context); g.repositoryOpen = 1; rid = name_to_rid(zName); if( rid==0 ) return; if( content_get(rid, &cx) ){ sqlite4_result_blob(context, blob_buffer(&cx), blob_size(&cx), SQLITE4_TRANSIENT); blob_reset(&cx); } } /* ** Implementation of the "compress(X)" SQL function. The input X is ** compressed using zLib and the output is returned. */ static void sqlcmd_compress( sqlite4_context *context, int argc, sqlite4_value **argv ){ const unsigned char *pIn; unsigned char *pOut; unsigned int nIn; unsigned long int nOut; pIn = sqlite4_value_blob(argv[0]); nIn = sqlite4_value_bytes(argv[0]); nOut = 13 + nIn + (nIn+999)/1000; pOut = sqlite4_malloc(0, nOut+4); pOut[0] = nIn>>24 & 0xff; pOut[1] = nIn>>16 & 0xff; pOut[2] = nIn>>8 & 0xff; pOut[3] = nIn & 0xff; compress(&pOut[4], &nOut, pIn, nIn); sqlite4_result_blob(context, pOut, nOut+4, SQLITE4_DYNAMIC); } /* ** Implementation of the "decompress(X)" SQL function. The argument X ** is a blob which was obtained from compress(Y). The output will be ** the value Y. */ static void sqlcmd_decompress( sqlite4_context *context, int argc, sqlite4_value **argv ){ const unsigned char *pIn; unsigned char *pOut; unsigned int nIn; unsigned long int nOut; int rc; pIn = sqlite4_value_blob(argv[0]); nIn = sqlite4_value_bytes(argv[0]); nOut = (pIn[0]<<24) + (pIn[1]<<16) + (pIn[2]<<8) + pIn[3]; pOut = sqlite4_malloc(0, nOut+1); rc = uncompress(pOut, &nOut, &pIn[4], nIn-4); if( rc==Z_OK ){ sqlite4_result_blob(context, pOut, nOut, SQLITE4_DYNAMIC); }else{ sqlite4_result_error(context, "input is not zlib compressed", -1); } } /* ** This is the "automatic extensionn" initializer that runs right after ** the connection to the repository database is opened. Set up the ** database connection to be more useful to the human operator. */ static int sqlcmd_autoinit( sqlite4 *db, const char **pzErrMsg, const void *notUsed ){ sqlite4_create_function(db, "content", 1, SQLITE4_ANY, 0, sqlcmd_content, 0, 0); sqlite4_create_function(db, "compress", 1, SQLITE4_ANY, 0, sqlcmd_compress, 0, 0); sqlite4_create_function(db, "decompress", 1, SQLITE4_ANY, 0, sqlcmd_decompress, 0, 0); return SQLITE4_OK; } /* ** COMMAND: sqlite4 ** ** Usage: %fossil sqlite4 ?DATABASE? ?OPTIONS? ** ** Run the standalone sqlite4 command-line shell on DATABASE with OPTIONS. ** If DATABASE is omitted, then the repository that serves the working ** directory is opened. ** ** WARNING: Careless use of this command can corrupt a Fossil repository ** in ways that are unrecoverable. Be sure you know what you are doing before ** running any SQL commands that modifies the repository database. */ void sqlite4_cmd(void){ extern int sqlite4_shell(int, char**); db_find_and_open_repository(OPEN_ANY_SCHEMA, 0); db_close(1); sqlite4_shutdown(0); sqlite4_shell(g.argc-1, g.argv+1); } /* ** This routine is called by the patched sqlite4 command-line shell in order ** to load the name and database connection for the open Fossil database. */ void fossil_open(const char **pzRepoName){ /*sqlite4_auto_extension((void(*)(void))sqlcmd_autoinit);*/ *pzRepoName = g.zRepositoryName; } |
Deleted src/sqlite3.c.
more than 10,000 changes
Deleted src/sqlite3.h.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Added src/sqlite4.c.
more than 10,000 changes
Added src/sqlite4.h.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 | /* ** 2001 September 15 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This header file defines the interface that the SQLite library ** presents to client programs. If a C-function, structure, datatype, ** or constant definition does not appear in this file, then it is ** not a published API of SQLite, is subject to change without ** notice, and should not be referenced by programs that use SQLite. ** ** Some of the definitions that are in this file are marked as ** "experimental". Experimental interfaces are normally new ** features recently added to SQLite. We do not anticipate changes ** to experimental interfaces but reserve the right to make minor changes ** if experience from use "in the wild" suggest such changes are prudent. ** ** The official C-language API documentation for SQLite is derived ** from comments in this file. This file is the authoritative source ** on how SQLite interfaces are suppose to operate. ** ** The name of this file under configuration management is "sqlite.h.in". ** The makefile makes some minor changes to this file (such as inserting ** the version number) and changes its name to "sqlite4.h" as ** part of the build process. */ #ifndef _SQLITE4_H_ #define _SQLITE4_H_ #include <stdarg.h> /* Needed for the definition of va_list */ /* ** Make sure we can call this stuff from C++. */ #ifdef __cplusplus extern "C" { #endif /* ** Add the ability to override 'extern' */ #ifndef SQLITE4_EXTERN # define SQLITE4_EXTERN extern #endif #ifndef SQLITE4_API # define SQLITE4_API #endif /* ** These no-op macros are used in front of interfaces to mark those ** interfaces as either deprecated or experimental. New applications ** should not use deprecated interfaces - they are support for backwards ** compatibility only. Application writers should be aware that ** experimental interfaces are subject to change in point releases. ** ** These macros used to resolve to various kinds of compiler magic that ** would generate warning messages when they were used. But that ** compiler magic ended up generating such a flurry of bug reports ** that we have taken it all out and gone back to using simple ** noop macros. */ #define SQLITE4_DEPRECATED #define SQLITE4_EXPERIMENTAL /* ** Ensure these symbols were not defined by some previous header file. */ #ifdef SQLITE4_VERSION # undef SQLITE4_VERSION #endif #ifdef SQLITE4_VERSION_NUMBER # undef SQLITE4_VERSION_NUMBER #endif /* ** CAPIREF: Run-time Environment Object ** ** An instance of the following object defines the run-time environment ** for an SQLite4 database connection. This object defines the interface ** to appropriate mutex routines, memory allocation routines, a ** pseudo-random number generator, real-time clock, and the key-value ** backend stores. */ typedef struct sqlite4_env sqlite4_env; /* ** CAPIREF: Find the default run-time environment ** ** Return a pointer to the default run-time environment. */ SQLITE4_API sqlite4_env *sqlite4_env_default(void); /* ** CAPIREF: Size of an sqlite4_env object ** ** Return the number of bytes of memory needed to hold an sqlite4_env ** object. This number varies from one machine to another, and from ** one release of SQLite to another. */ SQLITE4_API int sqlite4_env_size(void); /* ** CAPIREF: Configure a run-time environment */ SQLITE4_API int sqlite4_env_config(sqlite4_env*, int op, ...); /* ** CAPIREF: Configuration options for sqlite4_env_config(). */ #define SQLITE4_ENVCONFIG_INIT 1 /* size, template */ #define SQLITE4_ENVCONFIG_SINGLETHREAD 2 /* */ #define SQLITE4_ENVCONFIG_MULTITHREAD 3 /* */ #define SQLITE4_ENVCONFIG_SERIALIZED 4 /* */ #define SQLITE4_ENVCONFIG_MUTEX 5 /* sqlite4_mutex_methods* */ #define SQLITE4_ENVCONFIG_GETMUTEX 6 /* sqlite4_mutex_methods* */ #define SQLITE4_ENVCONFIG_MALLOC 7 /* sqlite4_mem_methods* */ #define SQLITE4_ENVCONFIG_GETMALLOC 8 /* sqlite4_mem_methods* */ #define SQLITE4_ENVCONFIG_MEMSTATUS 9 /* boolean */ #define SQLITE4_ENVCONFIG_LOOKASIDE 10 /* size, count */ #define SQLITE4_ENVCONFIG_LOG 11 /* xLog, pArg */ #define SQLITE4_ENVCONFIG_KVSTORE_PUSH 12 /* name, factory */ #define SQLITE4_ENVCONFIG_KVSTORE_POP 13 /* name */ #define SQLITE4_ENVCONFIG_KVSTORE_GET 14 /* name, *factor */ /* ** CAPIREF: Compile-Time Library Version Numbers ** ** ^(The [SQLITE4_VERSION] C preprocessor macro in the sqlite4.h header ** evaluates to a string literal that is the SQLite version in the ** format "X.Y.Z" where X is the major version number (always 3 for ** SQLite3) and Y is the minor version number and Z is the release number.)^ ** ^(The [SQLITE4_VERSION_NUMBER] C preprocessor macro resolves to an integer ** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same ** numbers used in [SQLITE4_VERSION].)^ ** The SQLITE4_VERSION_NUMBER for any given release of SQLite will also ** be larger than the release from which it is derived. Either Y will ** be held constant and Z will be incremented or else Y will be incremented ** and Z will be reset to zero. ** ** Since version 3.6.18, SQLite source code has been stored in the ** <a href="http://www.fossil-scm.org/">Fossil configuration management ** system</a>. ^The SQLITE4_SOURCE_ID macro evaluates to ** a string which identifies a particular check-in of SQLite ** within its configuration management system. ^The SQLITE4_SOURCE_ID ** string contains the date and time of the check-in (UTC) and an SHA1 ** hash of the entire source tree. ** ** See also: [sqlite4_libversion()], ** [sqlite4_libversion_number()], [sqlite4_sourceid()], ** [sqlite_version()] and [sqlite_source_id()]. */ #define SQLITE4_VERSION "4.0.0" #define SQLITE4_VERSION_NUMBER 4000000 #define SQLITE4_SOURCE_ID "2012-06-29 15:58:49 2aa05e9008ff9e3630161995cdb256351cc45f9b" /* ** CAPIREF: Run-Time Library Version Numbers ** KEYWORDS: sqlite4_version, sqlite4_sourceid ** ** These interfaces provide the same information as the [SQLITE4_VERSION], ** [SQLITE4_VERSION_NUMBER], and [SQLITE4_SOURCE_ID] C preprocessor macros ** but are associated with the library instead of the header file. ^(Cautious ** programmers might include assert() statements in their application to ** verify that values returned by these interfaces match the macros in ** the header, and thus insure that the application is ** compiled with matching library and header files. ** ** <blockquote><pre> ** assert( sqlite4_libversion_number()==SQLITE4_VERSION_NUMBER ); ** assert( strcmp(sqlite4_sourceid(),SQLITE4_SOURCE_ID)==0 ); ** assert( strcmp(sqlite4_libversion(),SQLITE4_VERSION)==0 ); ** </pre></blockquote>)^ ** ** ^The sqlite4_libversion() function returns a pointer to a string ** constant that contains the text of [SQLITE4_VERSION]. ^The ** sqlite4_libversion_number() function returns an integer equal to ** [SQLITE4_VERSION_NUMBER]. ^The sqlite4_sourceid() function returns ** a pointer to a string constant whose value is the same as the ** [SQLITE4_SOURCE_ID] C preprocessor macro. ** ** See also: [sqlite_version()] and [sqlite_source_id()]. */ SQLITE4_API const char *sqlite4_libversion(void); SQLITE4_API const char *sqlite4_sourceid(void); SQLITE4_API int sqlite4_libversion_number(void); /* ** CAPIREF: Run-Time Library Compilation Options Diagnostics ** ** ^The sqlite4_compileoption_used() function returns 0 or 1 ** indicating whether the specified option was defined at ** compile time. ^The SQLITE4_ prefix may be omitted from the ** option name passed to sqlite4_compileoption_used(). ** ** ^The sqlite4_compileoption_get() function allows iterating ** over the list of options that were defined at compile time by ** returning the N-th compile time option string. ^If N is out of range, ** sqlite4_compileoption_get() returns a NULL pointer. ^The SQLITE4_ ** prefix is omitted from any strings returned by ** sqlite4_compileoption_get(). ** ** ^Support for the diagnostic functions sqlite4_compileoption_used() ** and sqlite4_compileoption_get() may be omitted by specifying the ** [SQLITE4_OMIT_COMPILEOPTION_DIAGS] option at compile time. ** ** See also: SQL functions [sqlite_compileoption_used()] and ** [sqlite_compileoption_get()] and the [compile_options pragma]. */ #ifndef SQLITE4_OMIT_COMPILEOPTION_DIAGS SQLITE4_API int sqlite4_compileoption_used(const char *zOptName); SQLITE4_API const char *sqlite4_compileoption_get(int N); #endif /* ** CAPIREF: Test To See If The Library Is Threadsafe ** ** ^The sqlite4_threadsafe(E) function returns zero if the [sqlite4_env] ** object is configured in such a way that it should only be used by a ** single thread at a time. In other words, this routine returns zero ** if the environment is configured as [SQLITE4_ENVCONFIG_SINGLETHREAD]. ** ** ^The sqlite4_threadsafe(E) function returns one if multiple ** [database connection] objects associated with E can be used at the ** same time in different threads, so long as no single [database connection] ** object is used by two or more threads at the same time. This ** corresponds to [SQLITE4_ENVCONFIG_MULTITHREAD]. ** ** ^The sqlite4_threadsafe(E) function returns two if the same ** [database connection] can be used at the same time from two or more ** separate threads. This setting corresponds to [SQLITE4_ENVCONFIG_SERIALIZED]. ** ** Note that SQLite4 is always threadsafe in this sense: Two or more ** objects each associated with different [sqlite4_env] objects can ** always be used at the same time in separate threads. */ SQLITE4_API int sqlite4_threadsafe(sqlite4_env*); /* ** CAPIREF: Database Connection Handle ** KEYWORDS: {database connection} {database connections} ** ** Each open SQLite database is represented by a pointer to an instance of ** the opaque structure named "sqlite4". It is useful to think of an sqlite4 ** pointer as an object. The [sqlite4_open()] ** interface is its constructors, and [sqlite4_close()] ** is its destructor. There are many other interfaces (such as ** [sqlite4_prepare], [sqlite4_create_function()], and ** [sqlite4_busy_timeout()] to name but three) that are methods on an ** sqlite4 object. */ typedef struct sqlite4 sqlite4; /* ** CAPIREF: 64-Bit Integer Types ** KEYWORDS: sqlite_int64 sqlite_uint64 ** ** Because there is no cross-platform way to specify 64-bit integer types ** SQLite includes typedefs for 64-bit signed and unsigned integers. ** ** The sqlite4_int64 and sqlite4_uint64 are the preferred type definitions. ** The sqlite_int64 and sqlite_uint64 types are supported for backwards ** compatibility only. ** ** ^The sqlite4_int64 and sqlite_int64 types can store integer values ** between -9223372036854775808 and +9223372036854775807 inclusive. ^The ** sqlite4_uint64 and sqlite_uint64 types can store integer values ** between 0 and +18446744073709551615 inclusive. */ #ifdef SQLITE4_INT64_TYPE typedef SQLITE4_INT64_TYPE sqlite_int64; typedef unsigned SQLITE4_INT64_TYPE sqlite_uint64; #elif defined(_MSC_VER) || defined(__BORLANDC__) typedef __int64 sqlite_int64; typedef unsigned __int64 sqlite_uint64; #else typedef long long int sqlite_int64; typedef unsigned long long int sqlite_uint64; #endif typedef sqlite_int64 sqlite4_int64; typedef sqlite_uint64 sqlite4_uint64; /* ** CAPIREF: String length type ** ** A type for measuring the length of the string. Like size_t but ** does not require <stddef.h> */ typedef int sqlite4_size_t; /* ** If compiling for a processor that lacks floating point support, ** substitute integer for floating-point. */ #ifdef SQLITE4_OMIT_FLOATING_POINT # define double sqlite4_int64 #endif /* ** CAPIREF: Closing A Database Connection ** ** ^The sqlite4_close() routine is the destructor for the [sqlite4] object. ** ^Calls to sqlite4_close() return SQLITE4_OK if the [sqlite4] object is ** successfully destroyed and all associated resources are deallocated. ** ** Applications must [sqlite4_finalize | finalize] all [prepared statements] ** and [sqlite4_blob_close | close] all [BLOB handles] associated with ** the [sqlite4] object prior to attempting to close the object. ^If ** sqlite4_close() is called on a [database connection] that still has ** outstanding [prepared statements] or [BLOB handles], then it returns ** SQLITE4_BUSY. ** ** ^If [sqlite4_close()] is invoked while a transaction is open, ** the transaction is automatically rolled back. ** ** The C parameter to [sqlite4_close(C)] must be either a NULL ** pointer or an [sqlite4] object pointer obtained ** from [sqlite4_open()] and not previously closed. ** ^Calling sqlite4_close() with a NULL pointer argument is a ** harmless no-op. */ SQLITE4_API int sqlite4_close(sqlite4 *); /* ** The type for a callback function. ** This is legacy and deprecated. It is included for historical ** compatibility and is not documented. */ typedef int (*sqlite4_callback)(void*,int,char**, char**); /* ** CAPIREF: One-Step Query Execution Interface ** ** The sqlite4_exec() interface is a convenience wrapper around ** [sqlite4_prepare()], [sqlite4_step()], and [sqlite4_finalize()], ** that allows an application to run multiple statements of SQL ** without having to use a lot of C code. ** ** ^The sqlite4_exec() interface runs zero or more UTF-8 encoded, ** semicolon-separate SQL statements passed into its 2nd argument, ** in the context of the [database connection] passed in as its 1st ** argument. ^If the callback function of the 3rd argument to ** sqlite4_exec() is not NULL, then it is invoked for each result row ** coming out of the evaluated SQL statements. ^The 4th argument to ** sqlite4_exec() is relayed through to the 1st argument of each ** callback invocation. ^If the callback pointer to sqlite4_exec() ** is NULL, then no callback is ever invoked and result rows are ** ignored. ** ** ^If an error occurs while evaluating the SQL statements passed into ** sqlite4_exec(), then execution of the current statement stops and ** subsequent statements are skipped. ^If the 5th parameter to sqlite4_exec() ** is not NULL then any error message is written into memory obtained ** from [sqlite4_malloc()] and passed back through the 5th parameter. ** To avoid memory leaks, the application should invoke [sqlite4_free()] ** on error message strings returned through the 5th parameter of ** of sqlite4_exec() after the error message string is no longer needed. ** ^If the 5th parameter to sqlite4_exec() is not NULL and no errors ** occur, then sqlite4_exec() sets the pointer in its 5th parameter to ** NULL before returning. ** ** ^If an sqlite4_exec() callback returns non-zero, the sqlite4_exec() ** routine returns SQLITE4_ABORT without invoking the callback again and ** without running any subsequent SQL statements. ** ** ^The 2nd argument to the sqlite4_exec() callback function is the ** number of columns in the result. ^The 3rd argument to the sqlite4_exec() ** callback is an array of pointers to strings obtained as if from ** [sqlite4_column_text()], one for each column. ^If an element of a ** result row is NULL then the corresponding string pointer for the ** sqlite4_exec() callback is a NULL pointer. ^The 4th argument to the ** sqlite4_exec() callback is an array of pointers to strings where each ** entry represents the name of corresponding result column as obtained ** from [sqlite4_column_name()]. ** ** ^If the 2nd parameter to sqlite4_exec() is a NULL pointer, a pointer ** to an empty string, or a pointer that contains only whitespace and/or ** SQL comments, then no SQL statements are evaluated and the database ** is not changed. ** ** Restrictions: ** ** <ul> ** <li> The application must insure that the 1st parameter to sqlite4_exec() ** is a valid and open [database connection]. ** <li> The application must not close [database connection] specified by ** the 1st parameter to sqlite4_exec() while sqlite4_exec() is running. ** <li> The application must not modify the SQL statement text passed into ** the 2nd parameter of sqlite4_exec() while sqlite4_exec() is running. ** </ul> */ SQLITE4_API int sqlite4_exec( sqlite4*, /* An open database */ const char *sql, /* SQL to be evaluated */ int (*callback)(void*,int,char**,char**), /* Callback function */ void *, /* 1st argument to callback */ char **errmsg /* Error msg written here */ ); /* ** CAPIREF: Result Codes ** KEYWORDS: SQLITE4_OK {error code} {error codes} ** KEYWORDS: {result code} {result codes} ** ** Many SQLite functions return an integer result code from the set shown ** here in order to indicate success or failure. ** ** New error codes may be added in future versions of SQLite. ** ** See also: [SQLITE4_IOERR_READ | extended result codes], ** [sqlite4_vtab_on_conflict()] [SQLITE4_ROLLBACK | result codes]. */ #define SQLITE4_OK 0 /* Successful result */ /* beginning-of-error-codes */ #define SQLITE4_ERROR 1 /* SQL error or missing database */ #define SQLITE4_INTERNAL 2 /* Internal logic error in SQLite */ #define SQLITE4_PERM 3 /* Access permission denied */ #define SQLITE4_ABORT 4 /* Callback routine requested an abort */ #define SQLITE4_BUSY 5 /* The database file is locked */ #define SQLITE4_LOCKED 6 /* A table in the database is locked */ #define SQLITE4_NOMEM 7 /* A malloc() failed */ #define SQLITE4_READONLY 8 /* Attempt to write a readonly database */ #define SQLITE4_INTERRUPT 9 /* Operation terminated by sqlite4_interrupt()*/ #define SQLITE4_IOERR 10 /* Some kind of disk I/O error occurred */ #define SQLITE4_CORRUPT 11 /* The database disk image is malformed */ #define SQLITE4_NOTFOUND 12 /* Unknown opcode in sqlite4_file_control() */ #define SQLITE4_FULL 13 /* Insertion failed because database is full */ #define SQLITE4_CANTOPEN 14 /* Unable to open the database file */ #define SQLITE4_PROTOCOL 15 /* Database lock protocol error */ #define SQLITE4_EMPTY 16 /* Database is empty */ #define SQLITE4_SCHEMA 17 /* The database schema changed */ #define SQLITE4_TOOBIG 18 /* String or BLOB exceeds size limit */ #define SQLITE4_CONSTRAINT 19 /* Abort due to constraint violation */ #define SQLITE4_MISMATCH 20 /* Data type mismatch */ #define SQLITE4_MISUSE 21 /* Library used incorrectly */ #define SQLITE4_NOLFS 22 /* Uses OS features not supported on host */ #define SQLITE4_AUTH 23 /* Authorization denied */ #define SQLITE4_FORMAT 24 /* Auxiliary database format error */ #define SQLITE4_RANGE 25 /* 2nd parameter to sqlite4_bind out of range */ #define SQLITE4_NOTADB 26 /* File opened that is not a database file */ #define SQLITE4_ROW 100 /* sqlite4_step() has another row ready */ #define SQLITE4_DONE 101 /* sqlite4_step() has finished executing */ #define SQLITE4_INEXACT 102 /* xSeek method of storage finds nearby ans */ /* end-of-error-codes */ /* ** CAPIREF: Extended Result Codes ** KEYWORDS: {extended error code} {extended error codes} ** KEYWORDS: {extended result code} {extended result codes} ** ** In its default configuration, SQLite API routines return one of 26 integer ** [SQLITE4_OK | result codes]. However, experience has shown that many of ** these result codes are too coarse-grained. They do not provide as ** much information about problems as programmers might like. In an effort to ** address this, newer versions of SQLite (version 3.3.8 and later) include ** support for additional result codes that provide more detailed information ** about errors. The extended result codes are enabled or disabled ** on a per database connection basis using the ** [sqlite4_extended_result_codes()] API. ** ** Some of the available extended result codes are listed here. ** One may expect the number of extended result codes will be expand ** over time. Software that uses extended result codes should expect ** to see new result codes in future releases of SQLite. ** ** The SQLITE4_OK result code will never be extended. It will always ** be exactly zero. */ #define SQLITE4_IOERR_READ (SQLITE4_IOERR | (1<<8)) #define SQLITE4_IOERR_SHORT_READ (SQLITE4_IOERR | (2<<8)) #define SQLITE4_IOERR_WRITE (SQLITE4_IOERR | (3<<8)) #define SQLITE4_IOERR_FSYNC (SQLITE4_IOERR | (4<<8)) #define SQLITE4_IOERR_DIR_FSYNC (SQLITE4_IOERR | (5<<8)) #define SQLITE4_IOERR_TRUNCATE (SQLITE4_IOERR | (6<<8)) #define SQLITE4_IOERR_FSTAT (SQLITE4_IOERR | (7<<8)) #define SQLITE4_IOERR_UNLOCK (SQLITE4_IOERR | (8<<8)) #define SQLITE4_IOERR_RDLOCK (SQLITE4_IOERR | (9<<8)) #define SQLITE4_IOERR_DELETE (SQLITE4_IOERR | (10<<8)) #define SQLITE4_IOERR_BLOCKED (SQLITE4_IOERR | (11<<8)) #define SQLITE4_IOERR_NOMEM (SQLITE4_IOERR | (12<<8)) #define SQLITE4_IOERR_ACCESS (SQLITE4_IOERR | (13<<8)) #define SQLITE4_IOERR_CHECKRESERVEDLOCK (SQLITE4_IOERR | (14<<8)) #define SQLITE4_IOERR_LOCK (SQLITE4_IOERR | (15<<8)) #define SQLITE4_IOERR_CLOSE (SQLITE4_IOERR | (16<<8)) #define SQLITE4_IOERR_DIR_CLOSE (SQLITE4_IOERR | (17<<8)) #define SQLITE4_IOERR_SHMOPEN (SQLITE4_IOERR | (18<<8)) #define SQLITE4_IOERR_SHMSIZE (SQLITE4_IOERR | (19<<8)) #define SQLITE4_IOERR_SHMLOCK (SQLITE4_IOERR | (20<<8)) #define SQLITE4_IOERR_SHMMAP (SQLITE4_IOERR | (21<<8)) #define SQLITE4_IOERR_SEEK (SQLITE4_IOERR | (22<<8)) #define SQLITE4_LOCKED_SHAREDCACHE (SQLITE4_LOCKED | (1<<8)) #define SQLITE4_BUSY_RECOVERY (SQLITE4_BUSY | (1<<8)) #define SQLITE4_CANTOPEN_NOTEMPDIR (SQLITE4_CANTOPEN | (1<<8)) #define SQLITE4_CORRUPT_VTAB (SQLITE4_CORRUPT | (1<<8)) #define SQLITE4_READONLY_RECOVERY (SQLITE4_READONLY | (1<<8)) #define SQLITE4_READONLY_CANTLOCK (SQLITE4_READONLY | (2<<8)) /* ** CAPIREF: Flags For File Open Operations ** ** These bit values are intended for use as options in the ** [sqlite4_open()] interface */ #define SQLITE4_OPEN_READONLY 0x00000001 /* Ok for sqlite4_open() */ #define SQLITE4_OPEN_READWRITE 0x00000002 /* Ok for sqlite4_open() */ #define SQLITE4_OPEN_CREATE 0x00000004 /* Ok for sqlite4_open() */ /* NB: The above must not overlap with the SQLITE4_KVOPEN_xxxxx flags ** defined below */ /* ** CAPIREF: Mutex Handle ** ** The mutex module within SQLite defines [sqlite4_mutex] to be an ** abstract type for a mutex object. The SQLite core never looks ** at the internal representation of an [sqlite4_mutex]. It only ** deals with pointers to the [sqlite4_mutex] object. ** ** Mutexes are created using [sqlite4_mutex_alloc()]. */ typedef struct sqlite4_mutex sqlite4_mutex; struct sqlite4_mutex { struct sqlite4_mutex_methods *pMutexMethods; /* Subclasses will typically add additional fields */ }; /* ** CAPIREF: Initialize The SQLite Library ** ** ^The sqlite4_initialize(A) routine initializes an sqlite4_env object A. ** ^The sqlite4_shutdown(A) routine ** deallocates any resources that were allocated by sqlite4_initialize(A). ** ** A call to sqlite4_initialize(A) is an "effective" call if it is ** the first time sqlite4_initialize(A) is invoked during the lifetime of ** A, or if it is the first time sqlite4_initialize(A) is invoked ** following a call to sqlite4_shutdown(A). ^(Only an effective call ** of sqlite4_initialize(A) does any initialization or A. All other calls ** are harmless no-ops.)^ ** ** A call to sqlite4_shutdown(A) is an "effective" call if it is the first ** call to sqlite4_shutdown(A) since the last sqlite4_initialize(A). ^(Only ** an effective call to sqlite4_shutdown(A) does any deinitialization. ** All other valid calls to sqlite4_shutdown(A) are harmless no-ops.)^ ** ** The sqlite4_initialize(A) interface is threadsafe, but sqlite4_shutdown(A) ** is not. The sqlite4_shutdown(A) interface must only be called from a ** single thread. All open [database connections] must be closed and all ** other SQLite resources must be deallocated prior to invoking ** sqlite4_shutdown(A). ** ** ^The sqlite4_initialize(A) routine returns [SQLITE4_OK] on success. ** ^If for some reason, sqlite4_initialize(A) is unable to initialize ** the sqlite4_env object A (perhaps it is unable to allocate a needed ** resource such as a mutex) it returns an [error code] other than [SQLITE4_OK]. ** ** ^The sqlite4_initialize() routine is called internally by many other ** SQLite interfaces so that an application usually does not need to ** invoke sqlite4_initialize() directly. For example, [sqlite4_open()] ** calls sqlite4_initialize() so the SQLite library will be automatically ** initialized when [sqlite4_open()] is called if it has not be initialized ** already. ^However, if SQLite is compiled with the [SQLITE4_OMIT_AUTOINIT] ** compile-time option, then the automatic calls to sqlite4_initialize() ** are omitted and the application must call sqlite4_initialize() directly ** prior to using any other SQLite interface. For maximum portability, ** it is recommended that applications always invoke sqlite4_initialize() ** directly prior to using any other SQLite interface. Future releases ** of SQLite may require this. In other words, the behavior exhibited ** when SQLite is compiled with [SQLITE4_OMIT_AUTOINIT] might become the ** default behavior in some future release of SQLite. */ SQLITE4_API int sqlite4_initialize(sqlite4_env*); SQLITE4_API int sqlite4_shutdown(sqlite4_env*); /* ** CAPIREF: Configure database connections ** ** The sqlite4_db_config() interface is used to make configuration ** changes to a [database connection]. The interface is similar to ** [sqlite4_env_config()] except that the changes apply to a single ** [database connection] (specified in the first argument). ** ** The second argument to sqlite4_db_config(D,V,...) is the ** [SQLITE4_DBCONFIG_LOOKASIDE | configuration verb] - an integer code ** that indicates what aspect of the [database connection] is being configured. ** Subsequent arguments vary depending on the configuration verb. ** ** ^Calls to sqlite4_db_config() return SQLITE4_OK if and only if ** the call is considered successful. */ SQLITE4_API int sqlite4_db_config(sqlite4*, int op, ...); /* ** CAPIREF: Run-time environment of a database connection ** ** Return the sqlite4_env object to which the database connection ** belongs. */ SQLITE4_API sqlite4_env *sqlite4_db_env(sqlite4*); /* ** CAPIREF: Memory Allocation Routines ** ** An instance of this object defines the interface between SQLite ** and low-level memory allocation routines. ** ** This object is used in only one place in the SQLite interface. ** A pointer to an instance of this object is the argument to ** [sqlite4_env_config()] when the configuration option is ** [SQLITE4_ENVCONFIG_MALLOC] or [SQLITE4_ENVCONFIG_GETMALLOC]. ** By creating an instance of this object ** and passing it to [sqlite4_env_config]([SQLITE4_ENVCONFIG_MALLOC]) ** during configuration, an application can specify an alternative ** memory allocation subsystem for SQLite to use for all of its ** dynamic memory needs. ** ** Note that SQLite comes with several [built-in memory allocators] ** that are perfectly adequate for the overwhelming majority of applications ** and that this object is only useful to a tiny minority of applications ** with specialized memory allocation requirements. This object is ** also used during testing of SQLite in order to specify an alternative ** memory allocator that simulates memory out-of-memory conditions in ** order to verify that SQLite recovers gracefully from such ** conditions. ** ** The xMalloc, xRealloc, and xFree methods must work like the ** malloc(), realloc() and free() functions from the standard C library. ** ^SQLite guarantees that the second argument to ** xRealloc is always a value returned by a prior call to xRoundup. ** ** xSize should return the allocated size of a memory allocation ** previously obtained from xMalloc or xRealloc. The allocated size ** is always at least as big as the requested size but may be larger. ** ** The xRoundup method returns what would be the allocated size of ** a memory allocation given a particular requested size. Most memory ** allocators round up memory allocations at least to the next multiple ** of 8. Some allocators round up to a larger multiple or to a power of 2. ** Every memory allocation request coming in through [sqlite4_malloc()] ** or [sqlite4_realloc()] first calls xRoundup. If xRoundup returns 0, ** that causes the corresponding memory allocation to fail. ** ** The xInit method initializes the memory allocator. (For example, ** it might allocate any require mutexes or initialize internal data ** structures. The xShutdown method is invoked (indirectly) by ** [sqlite4_shutdown()] and should deallocate any resources acquired ** by xInit. The pMemEnv pointer is used as the only parameter to ** xInit and xShutdown. ** ** SQLite holds the [SQLITE4_MUTEX_STATIC_MASTER] mutex when it invokes ** the xInit method, so the xInit method need not be threadsafe. The ** xShutdown method is only called from [sqlite4_shutdown()] so it does ** not need to be threadsafe either. For all other methods, SQLite ** holds the [SQLITE4_MUTEX_STATIC_MEM] mutex as long as the ** [SQLITE4_CONFIG_MEMSTATUS] configuration option is turned on (which ** it is by default) and so the methods are automatically serialized. ** However, if [SQLITE4_CONFIG_MEMSTATUS] is disabled, then the other ** methods must be threadsafe or else make their own arrangements for ** serialization. ** ** SQLite will never invoke xInit() more than once without an intervening ** call to xShutdown(). */ typedef struct sqlite4_mem_methods sqlite4_mem_methods; struct sqlite4_mem_methods { void *(*xMalloc)(void*,sqlite4_size_t); /* Memory allocation function */ void (*xFree)(void*,void*); /* Free a prior allocation */ void *(*xRealloc)(void*,void*,int); /* Resize an allocation */ sqlite4_size_t (*xSize)(void*,void*); /* Return the size of an allocation */ int (*xInit)(void*); /* Initialize the memory allocator */ void (*xShutdown)(void*); /* Deinitialize the allocator */ void (*xBeginBenign)(void*); /* Enter a benign malloc region */ void (*xEndBenign)(void*); /* Leave a benign malloc region */ void *pMemEnv; /* 1st argument to all routines */ }; /* ** CAPIREF: Database Connection Configuration Options ** ** These constants are the available integer configuration options that ** can be passed as the second argument to the [sqlite4_db_config()] interface. ** ** New configuration options may be added in future releases of SQLite. ** Existing configuration options might be discontinued. Applications ** should check the return code from [sqlite4_db_config()] to make sure that ** the call worked. ^The [sqlite4_db_config()] interface will return a ** non-zero [error code] if a discontinued or unsupported configuration option ** is invoked. ** ** <dl> ** <dt>SQLITE4_DBCONFIG_LOOKASIDE</dt> ** <dd> ^This option takes three additional arguments that determine the ** [lookaside memory allocator] configuration for the [database connection]. ** ^The first argument (the third parameter to [sqlite4_db_config()] is a ** pointer to a memory buffer to use for lookaside memory. ** ^The first argument after the SQLITE4_DBCONFIG_LOOKASIDE verb ** may be NULL in which case SQLite will allocate the ** lookaside buffer itself using [sqlite4_malloc()]. ^The second argument is the ** size of each lookaside buffer slot. ^The third argument is the number of ** slots. The size of the buffer in the first argument must be greater than ** or equal to the product of the second and third arguments. The buffer ** must be aligned to an 8-byte boundary. ^If the second argument to ** SQLITE4_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally ** rounded down to the next smaller multiple of 8. ^(The lookaside memory ** configuration for a database connection can only be changed when that ** connection is not currently using lookaside memory, or in other words ** when the "current value" returned by ** [sqlite4_db_status](D,[SQLITE4_CONFIG_LOOKASIDE],...) is zero. ** Any attempt to change the lookaside memory configuration when lookaside ** memory is in use leaves the configuration unchanged and returns ** [SQLITE4_BUSY].)^</dd> ** ** <dt>SQLITE4_DBCONFIG_ENABLE_FKEY</dt> ** <dd> ^This option is used to enable or disable the enforcement of ** [foreign key constraints]. There should be two additional arguments. ** The first argument is an integer which is 0 to disable FK enforcement, ** positive to enable FK enforcement or negative to leave FK enforcement ** unchanged. The second parameter is a pointer to an integer into which ** is written 0 or 1 to indicate whether FK enforcement is off or on ** following this call. The second parameter may be a NULL pointer, in ** which case the FK enforcement setting is not reported back. </dd> ** ** <dt>SQLITE4_DBCONFIG_ENABLE_TRIGGER</dt> ** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers]. ** There should be two additional arguments. ** The first argument is an integer which is 0 to disable triggers, ** positive to enable triggers or negative to leave the setting unchanged. ** The second parameter is a pointer to an integer into which ** is written 0 or 1 to indicate whether triggers are disabled or enabled ** following this call. The second parameter may be a NULL pointer, in ** which case the trigger setting is not reported back. </dd> ** ** </dl> */ #define SQLITE4_DBCONFIG_LOOKASIDE 1001 /* void* int int */ #define SQLITE4_DBCONFIG_ENABLE_FKEY 1002 /* int int* */ #define SQLITE4_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */ /* ** CAPIREF: Last Insert Rowid ** ** ^Each entry in an SQLite table has a unique 64-bit signed ** integer key called the [ROWID | "rowid"]. ^The rowid is always available ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those ** names are not also used by explicitly declared columns. ^If ** the table has a column of type [INTEGER PRIMARY KEY] then that column ** is another alias for the rowid. ** ** ^This routine returns the [rowid] of the most recent ** successful [INSERT] into the database from the [database connection] ** in the first argument. ^As of SQLite version 3.7.7, this routines ** records the last insert rowid of both ordinary tables and [virtual tables]. ** ^If no successful [INSERT]s ** have ever occurred on that database connection, zero is returned. ** ** ^(If an [INSERT] occurs within a trigger or within a [virtual table] ** method, then this routine will return the [rowid] of the inserted ** row as long as the trigger or virtual table method is running. ** But once the trigger or virtual table method ends, the value returned ** by this routine reverts to what it was before the trigger or virtual ** table method began.)^ ** ** ^An [INSERT] that fails due to a constraint violation is not a ** successful [INSERT] and does not change the value returned by this ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK, ** and INSERT OR ABORT make no changes to the return value of this ** routine when their insertion fails. ^(When INSERT OR REPLACE ** encounters a constraint violation, it does not fail. The ** INSERT continues to completion after deleting rows that caused ** the constraint problem so INSERT OR REPLACE will always change ** the return value of this interface.)^ ** ** ^For the purposes of this routine, an [INSERT] is considered to ** be successful even if it is subsequently rolled back. ** ** This function is accessible to SQL statements via the ** [last_insert_rowid() SQL function]. ** ** If a separate thread performs a new [INSERT] on the same ** database connection while the [sqlite4_last_insert_rowid()] ** function is running and thus changes the last insert [rowid], ** then the value returned by [sqlite4_last_insert_rowid()] is ** unpredictable and might not equal either the old or the new ** last insert [rowid]. */ SQLITE4_API sqlite4_int64 sqlite4_last_insert_rowid(sqlite4*); /* ** CAPIREF: Count The Number Of Rows Modified ** ** ^This function returns the number of database rows that were changed ** or inserted or deleted by the most recently completed SQL statement ** on the [database connection] specified by the first parameter. ** ^(Only changes that are directly specified by the [INSERT], [UPDATE], ** or [DELETE] statement are counted. Auxiliary changes caused by ** triggers or [foreign key actions] are not counted.)^ Use the ** [sqlite4_total_changes()] function to find the total number of changes ** including changes caused by triggers and foreign key actions. ** ** ^Changes to a view that are simulated by an [INSTEAD OF trigger] ** are not counted. Only real table changes are counted. ** ** ^(A "row change" is a change to a single row of a single table ** caused by an INSERT, DELETE, or UPDATE statement. Rows that ** are changed as side effects of [REPLACE] constraint resolution, ** rollback, ABORT processing, [DROP TABLE], or by any other ** mechanisms do not count as direct row changes.)^ ** ** A "trigger context" is a scope of execution that begins and ** ends with the script of a [CREATE TRIGGER | trigger]. ** Most SQL statements are ** evaluated outside of any trigger. This is the "top level" ** trigger context. If a trigger fires from the top level, a ** new trigger context is entered for the duration of that one ** trigger. Subtriggers create subcontexts for their duration. ** ** ^Calling [sqlite4_exec()] or [sqlite4_step()] recursively does ** not create a new trigger context. ** ** ^This function returns the number of direct row changes in the ** most recent INSERT, UPDATE, or DELETE statement within the same ** trigger context. ** ** ^Thus, when called from the top level, this function returns the ** number of changes in the most recent INSERT, UPDATE, or DELETE ** that also occurred at the top level. ^(Within the body of a trigger, ** the sqlite4_changes() interface can be called to find the number of ** changes in the most recently completed INSERT, UPDATE, or DELETE ** statement within the body of the same trigger. ** However, the number returned does not include changes ** caused by subtriggers since those have their own context.)^ ** ** See also the [sqlite4_total_changes()] interface, the ** [count_changes pragma], and the [changes() SQL function]. ** ** If a separate thread makes changes on the same database connection ** while [sqlite4_changes()] is running then the value returned ** is unpredictable and not meaningful. */ SQLITE4_API int sqlite4_changes(sqlite4*); /* ** CAPIREF: Total Number Of Rows Modified ** ** ^This function returns the number of row changes caused by [INSERT], ** [UPDATE] or [DELETE] statements since the [database connection] was opened. ** ^(The count returned by sqlite4_total_changes() includes all changes ** from all [CREATE TRIGGER | trigger] contexts and changes made by ** [foreign key actions]. However, ** the count does not include changes used to implement [REPLACE] constraints, ** do rollbacks or ABORT processing, or [DROP TABLE] processing. The ** count does not include rows of views that fire an [INSTEAD OF trigger], ** though if the INSTEAD OF trigger makes changes of its own, those changes ** are counted.)^ ** ^The sqlite4_total_changes() function counts the changes as soon as ** the statement that makes them is completed (when the statement handle ** is passed to [sqlite4_reset()] or [sqlite4_finalize()]). ** ** See also the [sqlite4_changes()] interface, the ** [count_changes pragma], and the [total_changes() SQL function]. ** ** If a separate thread makes changes on the same database connection ** while [sqlite4_total_changes()] is running then the value ** returned is unpredictable and not meaningful. */ SQLITE4_API int sqlite4_total_changes(sqlite4*); /* ** CAPIREF: Interrupt A Long-Running Query ** ** ^This function causes any pending database operation to abort and ** return at its earliest opportunity. This routine is typically ** called in response to a user action such as pressing "Cancel" ** or Ctrl-C where the user wants a long query operation to halt ** immediately. ** ** ^It is safe to call this routine from a thread different from the ** thread that is currently running the database operation. But it ** is not safe to call this routine with a [database connection] that ** is closed or might close before sqlite4_interrupt() returns. ** ** ^If an SQL operation is very nearly finished at the time when ** sqlite4_interrupt() is called, then it might not have an opportunity ** to be interrupted and might continue to completion. ** ** ^An SQL operation that is interrupted will return [SQLITE4_INTERRUPT]. ** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE ** that is inside an explicit transaction, then the entire transaction ** will be rolled back automatically. ** ** ^The sqlite4_interrupt(D) call is in effect until all currently running ** SQL statements on [database connection] D complete. ^Any new SQL statements ** that are started after the sqlite4_interrupt() call and before the ** running statements reaches zero are interrupted as if they had been ** running prior to the sqlite4_interrupt() call. ^New SQL statements ** that are started after the running statement count reaches zero are ** not effected by the sqlite4_interrupt(). ** ^A call to sqlite4_interrupt(D) that occurs when there are no running ** SQL statements is a no-op and has no effect on SQL statements ** that are started after the sqlite4_interrupt() call returns. ** ** If the database connection closes while [sqlite4_interrupt()] ** is running then bad things will likely happen. */ SQLITE4_API void sqlite4_interrupt(sqlite4*); /* ** CAPIREF: Determine If An SQL Statement Is Complete ** ** These routines are useful during command-line input to determine if the ** currently entered text seems to form a complete SQL statement or ** if additional input is needed before sending the text into ** SQLite for parsing. ^These routines return 1 if the input string ** appears to be a complete SQL statement. ^A statement is judged to be ** complete if it ends with a semicolon token and is not a prefix of a ** well-formed CREATE TRIGGER statement. ^Semicolons that are embedded within ** string literals or quoted identifier names or comments are not ** independent tokens (they are part of the token in which they are ** embedded) and thus do not count as a statement terminator. ^Whitespace ** and comments that follow the final semicolon are ignored. ** ** ^These routines return 0 if the statement is incomplete. ^If a ** memory allocation fails, then SQLITE4_NOMEM is returned. ** ** ^These routines do not parse the SQL statements thus ** will not detect syntactically incorrect SQL. ** ** ^(If SQLite has not been initialized using [sqlite4_initialize()] prior ** to invoking sqlite4_complete16() then sqlite4_initialize() is invoked ** automatically by sqlite4_complete16(). If that initialization fails, ** then the return value from sqlite4_complete16() will be non-zero ** regardless of whether or not the input SQL is complete.)^ ** ** The input to [sqlite4_complete()] must be a zero-terminated ** UTF-8 string. ** ** The input to [sqlite4_complete16()] must be a zero-terminated ** UTF-16 string in native byte order. */ SQLITE4_API int sqlite4_complete(const char *sql); SQLITE4_API int sqlite4_complete16(const void *sql); /* ** CAPIREF: Formatted String Printing Functions ** ** These routines are work-alikes of the "printf()" family of functions ** from the standard C library. ** ** ^The sqlite4_mprintf() and sqlite4_vmprintf() routines write their ** results into memory obtained from [sqlite4_malloc()]. ** The strings returned by these two routines should be ** released by [sqlite4_free()]. ^Both routines return a ** NULL pointer if [sqlite4_malloc()] is unable to allocate enough ** memory to hold the resulting string. ** ** ^(The sqlite4_snprintf() routine is similar to "snprintf()" from ** the standard C library. The result is written into the ** buffer supplied as the first parameter whose size is given by ** the second parameter.)^ The return value from sqltie4_snprintf() ** is the number of bytes actually written into the buffer, not ** counting the zero terminator. The buffer is always zero-terminated ** as long as it it at least one byte in length. ** ** The sqlite4_snprintf() differs from the standard library snprintf() ** routine in two ways: (1) sqlite4_snprintf() returns the number of ** bytes actually written, not the number of bytes that would have been ** written if the buffer had been infinitely long. (2) If the buffer is ** at least one byte long, sqlite4_snprintf() always zero-terminates its ** result. ** ** ^As long as the buffer size is greater than zero, sqlite4_snprintf() ** guarantees that the buffer is always zero-terminated. ^The second ** parameter "n" is the total size of the buffer, including space for ** the zero terminator. So the longest string that can be completely ** written will be n-1 characters. ** ** ^The sqlite4_vsnprintf() routine is a varargs version of sqlite4_snprintf(). ** ** These routines all implement some additional formatting ** options that are useful for constructing SQL statements. ** All of the usual printf() formatting options apply. In addition, there ** is are "%q", "%Q", and "%z" options. ** ** ^(The %q option works like %s in that it substitutes a nul-terminated ** string from the argument list. But %q also doubles every '\'' character. ** %q is designed for use inside a string literal.)^ By doubling each '\'' ** character it escapes that character and allows it to be inserted into ** the string. ** ** For example, assume the string variable zText contains text as follows: ** ** <blockquote><pre> ** char *zText = "It's a happy day!"; ** </pre></blockquote> ** ** One can use this text in an SQL statement as follows: ** ** <blockquote><pre> ** char *zSQL = sqlite4_mprintf("INSERT INTO table VALUES('%q')", zText); ** sqlite4_exec(db, zSQL, 0, 0, 0); ** sqlite4_free(zSQL); ** </pre></blockquote> ** ** Because the %q format string is used, the '\'' character in zText ** is escaped and the SQL generated is as follows: ** ** <blockquote><pre> ** INSERT INTO table1 VALUES('It''s a happy day!') ** </pre></blockquote> ** ** This is correct. Had we used %s instead of %q, the generated SQL ** would have looked like this: ** ** <blockquote><pre> ** INSERT INTO table1 VALUES('It's a happy day!'); ** </pre></blockquote> ** ** This second example is an SQL syntax error. As a general rule you should ** always use %q instead of %s when inserting text into a string literal. ** ** ^(The %Q option works like %q except it also adds single quotes around ** the outside of the total string. Additionally, if the parameter in the ** argument list is a NULL pointer, %Q substitutes the text "NULL" (without ** single quotes).)^ So, for example, one could say: ** ** <blockquote><pre> ** char *zSQL = sqlite4_mprintf("INSERT INTO table VALUES(%Q)", zText); ** sqlite4_exec(db, zSQL, 0, 0, 0); ** sqlite4_free(zSQL); ** </pre></blockquote> ** ** The code above will render a correct SQL statement in the zSQL ** variable even if the zText variable is a NULL pointer. ** ** ^(The "%z" formatting option works like "%s" but with the ** addition that after the string has been read and copied into ** the result, [sqlite4_free()] is called on the input string.)^ */ SQLITE4_API char *sqlite4_mprintf(sqlite4_env*, const char*,...); SQLITE4_API char *sqlite4_vmprintf(sqlite4_env*, const char*, va_list); SQLITE4_API sqlite4_size_t sqlite4_snprintf(char*,sqlite4_size_t,const char*, ...); SQLITE4_API sqlite4_size_t sqlite4_vsnprintf(char*,sqlite4_size_t,const char*, va_list); /* ** CAPIREF: Memory Allocation Subsystem ** ** The SQLite core uses these three routines for all of its own ** internal memory allocation needs. ** ** ^The sqlite4_malloc() routine returns a pointer to a block ** of memory at least N bytes in length, where N is the parameter. ** ^If sqlite4_malloc() is unable to obtain sufficient free ** memory, it returns a NULL pointer. ^If the parameter N to ** sqlite4_malloc() is zero or negative then sqlite4_malloc() returns ** a NULL pointer. ** ** ^Calling sqlite4_free() with a pointer previously returned ** by sqlite4_malloc() or sqlite4_realloc() releases that memory so ** that it might be reused. ^The sqlite4_free() routine is ** a no-op if is called with a NULL pointer. Passing a NULL pointer ** to sqlite4_free() is harmless. After being freed, memory ** should neither be read nor written. Even reading previously freed ** memory might result in a segmentation fault or other severe error. ** Memory corruption, a segmentation fault, or other severe error ** might result if sqlite4_free() is called with a non-NULL pointer that ** was not obtained from sqlite4_malloc() or sqlite4_realloc(). ** ** ^(The sqlite4_realloc() interface attempts to resize a ** prior memory allocation to be at least N bytes, where N is the ** second parameter. The memory allocation to be resized is the first ** parameter.)^ ^ If the first parameter to sqlite4_realloc() ** is a NULL pointer then its behavior is identical to calling ** sqlite4_malloc(N) where N is the second parameter to sqlite4_realloc(). ** ^If the second parameter to sqlite4_realloc() is zero or ** negative then the behavior is exactly the same as calling ** sqlite4_free(P) where P is the first parameter to sqlite4_realloc(). ** ^sqlite4_realloc() returns a pointer to a memory allocation ** of at least N bytes in size or NULL if sufficient memory is unavailable. ** ^If M is the size of the prior allocation, then min(N,M) bytes ** of the prior allocation are copied into the beginning of buffer returned ** by sqlite4_realloc() and the prior allocation is freed. ** ^If sqlite4_realloc() returns NULL, then the prior allocation ** is not freed. ** ** ^The memory returned by sqlite4_malloc() and sqlite4_realloc() ** is always aligned to at least an 8 byte boundary, or to a ** 4 byte boundary if the [SQLITE4_4_BYTE_ALIGNED_MALLOC] compile-time ** option is used. ** ** The pointer arguments to [sqlite4_free()] and [sqlite4_realloc()] ** must be either NULL or else pointers obtained from a prior ** invocation of [sqlite4_malloc()] or [sqlite4_realloc()] that have ** not yet been released. ** ** The application must not read or write any part of ** a block of memory after it has been released using ** [sqlite4_free()] or [sqlite4_realloc()]. */ SQLITE4_API void *sqlite4_malloc(sqlite4_env*, sqlite4_size_t); SQLITE4_API void *sqlite4_realloc(sqlite4_env*, void*, sqlite4_size_t); SQLITE4_API void sqlite4_free(sqlite4_env*, void*); /* ** CAPIREF: Memory Allocator Statistics ** ** SQLite provides these two interfaces for reporting on the status ** of the [sqlite4_malloc()], [sqlite4_free()], and [sqlite4_realloc()] ** routines, which form the built-in memory allocation subsystem. ** ** ^The [sqlite4_memory_used(E)] routine returns the number of bytes ** of memory currently outstanding (malloced but not freed) for ** sqlite4_env environment E. ** ^The [sqlite4_memory_highwater(E)] routine returns the maximum ** value of [sqlite4_memory_used(E)] since the high-water mark ** was last reset. ^The values returned by [sqlite4_memory_used()] and ** [sqlite4_memory_highwater()] include any overhead ** added by SQLite in its implementation of [sqlite4_malloc()], ** but not overhead added by the any underlying system library ** routines that [sqlite4_malloc()] may call. ** ** ^The memory high-water mark is reset to the current value of ** [sqlite4_memory_used(E)] if and only if the R parameter to ** [sqlite4_memory_highwater(E,R)] is true. ^The value returned ** by [sqlite4_memory_highwater(E,1)] is the high-water mark ** prior to the reset. */ SQLITE4_API sqlite4_uint64 sqlite4_memory_used(sqlite4_env*); SQLITE4_API sqlite4_uint64 sqlite4_memory_highwater(sqlite4_env*, int resetFlag); /* ** CAPIREF: Pseudo-Random Number Generator ** ** ^A call to this routine stores N bytes of pseudo-randomness into buffer P. */ SQLITE4_API void sqlite4_randomness(sqlite4_env*, int N, void *P); /* ** CAPIREF: Compile-Time Authorization Callbacks ** ** ^This routine registers an authorizer callback with a particular ** [database connection], supplied in the first argument. ** ^The authorizer callback is invoked as SQL statements are being compiled ** by [sqlite4_prepare()] or its variants [sqlite4_prepare()], ** [sqlite4_prepare16()] and [sqlite4_prepare16_v2()]. ^At various ** points during the compilation process, as logic is being created ** to perform various actions, the authorizer callback is invoked to ** see if those actions are allowed. ^The authorizer callback should ** return [SQLITE4_OK] to allow the action, [SQLITE4_IGNORE] to disallow the ** specific action but allow the SQL statement to continue to be ** compiled, or [SQLITE4_DENY] to cause the entire SQL statement to be ** rejected with an error. ^If the authorizer callback returns ** any value other than [SQLITE4_IGNORE], [SQLITE4_OK], or [SQLITE4_DENY] ** then the [sqlite4_prepare()] or equivalent call that triggered ** the authorizer will fail with an error message. ** ** When the callback returns [SQLITE4_OK], that means the operation ** requested is ok. ^When the callback returns [SQLITE4_DENY], the ** [sqlite4_prepare()] or equivalent call that triggered the ** authorizer will fail with an error message explaining that ** access is denied. ** ** ^The first parameter to the authorizer callback is a copy of the third ** parameter to the sqlite4_set_authorizer() interface. ^The second parameter ** to the callback is an integer [SQLITE4_COPY | action code] that specifies ** the particular action to be authorized. ^The third through sixth parameters ** to the callback are zero-terminated strings that contain additional ** details about the action to be authorized. ** ** ^If the action code is [SQLITE4_READ] ** and the callback returns [SQLITE4_IGNORE] then the ** [prepared statement] statement is constructed to substitute ** a NULL value in place of the table column that would have ** been read if [SQLITE4_OK] had been returned. The [SQLITE4_IGNORE] ** return can be used to deny an untrusted user access to individual ** columns of a table. ** ^If the action code is [SQLITE4_DELETE] and the callback returns ** [SQLITE4_IGNORE] then the [DELETE] operation proceeds but the ** [truncate optimization] is disabled and all rows are deleted individually. ** ** An authorizer is used when [sqlite4_prepare | preparing] ** SQL statements from an untrusted source, to ensure that the SQL statements ** do not try to access data they are not allowed to see, or that they do not ** try to execute malicious statements that damage the database. For ** example, an application may allow a user to enter arbitrary ** SQL queries for evaluation by a database. But the application does ** not want the user to be able to make arbitrary changes to the ** database. An authorizer could then be put in place while the ** user-entered SQL is being [sqlite4_prepare | prepared] that ** disallows everything except [SELECT] statements. ** ** Applications that need to process SQL from untrusted sources ** might also consider lowering resource limits using [sqlite4_limit()] ** and limiting database size using the [max_page_count] [PRAGMA] ** in addition to using an authorizer. ** ** ^(Only a single authorizer can be in place on a database connection ** at a time. Each call to sqlite4_set_authorizer overrides the ** previous call.)^ ^Disable the authorizer by installing a NULL callback. ** The authorizer is disabled by default. ** ** The authorizer callback must not do anything that will modify ** the database connection that invoked the authorizer callback. ** Note that [sqlite4_prepare()] and [sqlite4_step()] both modify their ** database connections for the meaning of "modify" in this paragraph. ** ** ^When [sqlite4_prepare()] is used to prepare a statement, the ** statement might be re-prepared during [sqlite4_step()] due to a ** schema change. Hence, the application should ensure that the ** correct authorizer callback remains in place during the [sqlite4_step()]. ** ** ^Note that the authorizer callback is invoked only during ** [sqlite4_prepare()] or its variants. Authorization is not ** performed during statement evaluation in [sqlite4_step()], unless ** as stated in the previous paragraph, sqlite4_step() invokes ** sqlite4_prepare() to reprepare a statement after a schema change. */ SQLITE4_API int sqlite4_set_authorizer( sqlite4*, int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), void *pUserData ); /* ** CAPIREF: Authorizer Return Codes ** ** The [sqlite4_set_authorizer | authorizer callback function] must ** return either [SQLITE4_OK] or one of these two constants in order ** to signal SQLite whether or not the action is permitted. See the ** [sqlite4_set_authorizer | authorizer documentation] for additional ** information. ** ** Note that SQLITE4_IGNORE is also used as a [SQLITE4_ROLLBACK | return code] ** from the [sqlite4_vtab_on_conflict()] interface. */ #define SQLITE4_DENY 1 /* Abort the SQL statement with an error */ #define SQLITE4_IGNORE 2 /* Don't allow access, but don't generate an error */ /* ** CAPIREF: Authorizer Action Codes ** ** The [sqlite4_set_authorizer()] interface registers a callback function ** that is invoked to authorize certain SQL statement actions. The ** second parameter to the callback is an integer code that specifies ** what action is being authorized. These are the integer action codes that ** the authorizer callback may be passed. ** ** These action code values signify what kind of operation is to be ** authorized. The 3rd and 4th parameters to the authorization ** callback function will be parameters or NULL depending on which of these ** codes is used as the second parameter. ^(The 5th parameter to the ** authorizer callback is the name of the database ("main", "temp", ** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback ** is the name of the inner-most trigger or view that is responsible for ** the access attempt or NULL if this access attempt is directly from ** top-level SQL code. */ /******************************************* 3rd ************ 4th ***********/ #define SQLITE4_CREATE_INDEX 1 /* Index Name Table Name */ #define SQLITE4_CREATE_TABLE 2 /* Table Name NULL */ #define SQLITE4_CREATE_TEMP_INDEX 3 /* Index Name Table Name */ #define SQLITE4_CREATE_TEMP_TABLE 4 /* Table Name NULL */ #define SQLITE4_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */ #define SQLITE4_CREATE_TEMP_VIEW 6 /* View Name NULL */ #define SQLITE4_CREATE_TRIGGER 7 /* Trigger Name Table Name */ #define SQLITE4_CREATE_VIEW 8 /* View Name NULL */ #define SQLITE4_DELETE 9 /* Table Name NULL */ #define SQLITE4_DROP_INDEX 10 /* Index Name Table Name */ #define SQLITE4_DROP_TABLE 11 /* Table Name NULL */ #define SQLITE4_DROP_TEMP_INDEX 12 /* Index Name Table Name */ #define SQLITE4_DROP_TEMP_TABLE 13 /* Table Name NULL */ #define SQLITE4_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */ #define SQLITE4_DROP_TEMP_VIEW 15 /* View Name NULL */ #define SQLITE4_DROP_TRIGGER 16 /* Trigger Name Table Name */ #define SQLITE4_DROP_VIEW 17 /* View Name NULL */ #define SQLITE4_INSERT 18 /* Table Name NULL */ #define SQLITE4_PRAGMA 19 /* Pragma Name 1st arg or NULL */ #define SQLITE4_READ 20 /* Table Name Column Name */ #define SQLITE4_SELECT 21 /* NULL NULL */ #define SQLITE4_TRANSACTION 22 /* Operation NULL */ #define SQLITE4_UPDATE 23 /* Table Name Column Name */ #define SQLITE4_ATTACH 24 /* Filename NULL */ #define SQLITE4_DETACH 25 /* Database Name NULL */ #define SQLITE4_ALTER_TABLE 26 /* Database Name Table Name */ #define SQLITE4_REINDEX 27 /* Index Name NULL */ #define SQLITE4_ANALYZE 28 /* Table Name NULL */ #define SQLITE4_CREATE_VTABLE 29 /* Table Name Module Name */ #define SQLITE4_DROP_VTABLE 30 /* Table Name Module Name */ #define SQLITE4_FUNCTION 31 /* NULL Function Name */ #define SQLITE4_SAVEPOINT 32 /* Operation Savepoint Name */ #define SQLITE4_COPY 0 /* No longer used */ /* ** CAPIREF: Tracing And Profiling Functions ** ** These routines register callback functions that can be used for ** tracing and profiling the execution of SQL statements. ** ** ^The callback function registered by sqlite4_trace() is invoked at ** various times when an SQL statement is being run by [sqlite4_step()]. ** ^The sqlite4_trace() callback is invoked with a UTF-8 rendering of the ** SQL statement text as the statement first begins executing. ** ^(Additional sqlite4_trace() callbacks might occur ** as each triggered subprogram is entered. The callbacks for triggers ** contain a UTF-8 SQL comment that identifies the trigger.)^ ** ** ^The callback function registered by sqlite4_profile() is invoked ** as each SQL statement finishes. ^The profile callback contains ** the original statement text and an estimate of wall-clock time ** of how long that statement took to run. ^The profile callback ** time is in units of nanoseconds, however the current implementation ** is only capable of millisecond resolution so the six least significant ** digits in the time are meaningless. Future versions of SQLite ** might provide greater resolution on the profiler callback. The ** sqlite4_profile() function is considered experimental and is ** subject to change in future versions of SQLite. */ SQLITE4_API void *sqlite4_trace(sqlite4*, void(*xTrace)(void*,const char*), void*); SQLITE4_API SQLITE4_EXPERIMENTAL void *sqlite4_profile(sqlite4*, void(*xProfile)(void*,const char*,sqlite4_uint64), void*); /* ** CAPIREF: Query Progress Callbacks ** ** ^The sqlite4_progress_handler(D,N,X,P) interface causes the callback ** function X to be invoked periodically during long running calls to ** [sqlite4_exec()] and [sqlite4_step()] for ** database connection D. An example use for this ** interface is to keep a GUI updated during a large query. ** ** ^The parameter P is passed through as the only parameter to the ** callback function X. ^The parameter N is the number of ** [virtual machine instructions] that are evaluated between successive ** invocations of the callback X. ** ** ^Only a single progress handler may be defined at one time per ** [database connection]; setting a new progress handler cancels the ** old one. ^Setting parameter X to NULL disables the progress handler. ** ^The progress handler is also disabled by setting N to a value less ** than 1. ** ** ^If the progress callback returns non-zero, the operation is ** interrupted. This feature can be used to implement a ** "Cancel" button on a GUI progress dialog box. ** ** The progress handler callback must not do anything that will modify ** the database connection that invoked the progress handler. ** Note that [sqlite4_prepare()] and [sqlite4_step()] both modify their ** database connections for the meaning of "modify" in this paragraph. ** */ SQLITE4_API void sqlite4_progress_handler(sqlite4*, int, int(*)(void*), void*); /* ** CAPIREF: Opening A New Database Connection ** ** ^These routines open an SQLite4 database file as specified by the ** URI argument. ** ^(A [database connection] handle is usually ** returned in *ppDb, even if an error occurs. The only exception is that ** if SQLite is unable to allocate memory to hold the [sqlite4] object, ** a NULL will be written into *ppDb instead of a pointer to the [sqlite4] ** object.)^ ^(If the database is opened (and/or created) successfully, then ** [SQLITE4_OK] is returned. Otherwise an [error code] is returned.)^ ^The ** [sqlite4_errmsg()] routine can be used to obtain ** an English language description of the error following a failure of any ** of the sqlite4_open() routines. ** ** Whether or not an error occurs when it is opened, resources ** associated with the [database connection] handle should be released by ** passing it to [sqlite4_close()] when it is no longer required. ** */ SQLITE4_API int sqlite4_open( sqlite4_env *pEnv, /* Run-time environment. NULL means use the default */ const char *filename, /* Database filename (UTF-8) */ sqlite4 **ppDb, /* OUT: SQLite db handle */ ... /* Optional parameters. Zero terminates options */ ); /* ** CAPIREF: Obtain Values For URI Parameters ** ** These are utility routines, useful to VFS implementations, that check ** to see if a database file was a URI that contained a specific query ** parameter, and if so obtains the value of that query parameter. ** ** If F is the database filename pointer passed into the xOpen() method of ** a VFS implementation when the flags parameter to xOpen() has one or ** more of the [SQLITE4_OPEN_URI] or [SQLITE4_OPEN_MAIN_DB] bits set and ** P is the name of the query parameter, then ** sqlite4_uri_parameter(F,P) returns the value of the P ** parameter if it exists or a NULL pointer if P does not appear as a ** query parameter on F. If P is a query parameter of F ** has no explicit value, then sqlite4_uri_parameter(F,P) returns ** a pointer to an empty string. ** ** The sqlite4_uri_boolean(F,P,B) routine assumes that P is a boolean ** parameter and returns true (1) or false (0) according to the value ** of P. The value of P is true if it is "yes" or "true" or "on" or ** a non-zero number and is false otherwise. If P is not a query parameter ** on F then sqlite4_uri_boolean(F,P,B) returns (B!=0). ** ** The sqlite4_uri_int64(F,P,D) routine converts the value of P into a ** 64-bit signed integer and returns that integer, or D if P does not ** exist. If the value of P is something other than an integer, then ** zero is returned. ** ** If F is a NULL pointer, then sqlite4_uri_parameter(F,P) returns NULL and ** sqlite4_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and ** is not a database file pathname pointer that SQLite passed into the xOpen ** VFS method, then the behavior of this routine is undefined and probably ** undesirable. */ SQLITE4_API const char *sqlite4_uri_parameter(const char *zFilename, const char *zParam); SQLITE4_API int sqlite4_uri_boolean(const char *zFile, const char *zParam, int bDefault); SQLITE4_API sqlite4_int64 sqlite4_uri_int64(const char*, const char*, sqlite4_int64); /* ** CAPIREF: Error Codes And Messages ** ** ^The sqlite4_errcode() interface returns the numeric ** [extended result code] for the most recent failed sqlite4_* API call ** associated with a [database connection]. If a prior API call failed ** but the most recent API call succeeded, the return value from ** sqlite4_errcode() is undefined. ** ** ^The sqlite4_errmsg() and sqlite4_errmsg16() return English-language ** text that describes the error, as either UTF-8 or UTF-16 respectively. ** ^(Memory to hold the error message string is managed internally. ** The application does not need to worry about freeing the result. ** However, the error string might be overwritten or deallocated by ** subsequent calls to other SQLite interface functions.)^ ** ** When the serialized [threading mode] is in use, it might be the ** case that a second error occurs on a separate thread in between ** the time of the first error and the call to these interfaces. ** When that happens, the second error will be reported since these ** interfaces always report the most recent result. To avoid ** this, each thread can obtain exclusive use of the [database connection] D ** by invoking [sqlite4_mutex_enter]([sqlite4_db_mutex](D)) before beginning ** to use D and invoking [sqlite4_mutex_leave]([sqlite4_db_mutex](D)) after ** all calls to the interfaces listed here are completed. ** ** If an interface fails with SQLITE4_MISUSE, that means the interface ** was invoked incorrectly by the application. In that case, the ** error code and message may or may not be set. */ SQLITE4_API int sqlite4_errcode(sqlite4 *db); SQLITE4_API const char *sqlite4_errmsg(sqlite4*); SQLITE4_API const void *sqlite4_errmsg16(sqlite4*); /* ** CAPIREF: SQL Statement Object ** KEYWORDS: {prepared statement} {prepared statements} ** ** An instance of this object represents a single SQL statement. ** This object is variously known as a "prepared statement" or a ** "compiled SQL statement" or simply as a "statement". ** ** The life of a statement object goes something like this: ** ** <ol> ** <li> Create the object using [sqlite4_prepare()] or a related ** function. ** <li> Bind values to [host parameters] using the sqlite4_bind_*() ** interfaces. ** <li> Run the SQL by calling [sqlite4_step()] one or more times. ** <li> Reset the statement using [sqlite4_reset()] then go back ** to step 2. Do this zero or more times. ** <li> Destroy the object using [sqlite4_finalize()]. ** </ol> ** ** Refer to documentation on individual methods above for additional ** information. */ typedef struct sqlite4_stmt sqlite4_stmt; /* ** CAPIREF: Run-time Limits ** ** ^(This interface allows the size of various constructs to be limited ** on a connection by connection basis. The first parameter is the ** [database connection] whose limit is to be set or queried. The ** second parameter is one of the [limit categories] that define a ** class of constructs to be size limited. The third parameter is the ** new limit for that construct.)^ ** ** ^If the new limit is a negative number, the limit is unchanged. ** ^(For each limit category SQLITE4_LIMIT_<i>NAME</i> there is a ** [limits | hard upper bound] ** set at compile-time by a C preprocessor macro called ** [limits | SQLITE4_MAX_<i>NAME</i>]. ** (The "_LIMIT_" in the name is changed to "_MAX_".))^ ** ^Attempts to increase a limit above its hard upper bound are ** silently truncated to the hard upper bound. ** ** ^Regardless of whether or not the limit was changed, the ** [sqlite4_limit()] interface returns the prior value of the limit. ** ^Hence, to find the current value of a limit without changing it, ** simply invoke this interface with the third parameter set to -1. ** ** Run-time limits are intended for use in applications that manage ** both their own internal database and also databases that are controlled ** by untrusted external sources. An example application might be a ** web browser that has its own databases for storing history and ** separate databases controlled by JavaScript applications downloaded ** off the Internet. The internal databases can be given the ** large, default limits. Databases managed by external sources can ** be given much smaller limits designed to prevent a denial of service ** attack. Developers might also want to use the [sqlite4_set_authorizer()] ** interface to further control untrusted SQL. The size of the database ** created by an untrusted script can be contained using the ** [max_page_count] [PRAGMA]. ** ** New run-time limit categories may be added in future releases. */ SQLITE4_API int sqlite4_limit(sqlite4*, int id, int newVal); /* ** CAPIREF: Run-Time Limit Categories ** KEYWORDS: {limit category} {*limit categories} ** ** These constants define various performance limits ** that can be lowered at run-time using [sqlite4_limit()]. ** The synopsis of the meanings of the various limits is shown below. ** Additional information is available at [limits | Limits in SQLite]. ** ** <dl> ** [[SQLITE4_LIMIT_LENGTH]] ^(<dt>SQLITE4_LIMIT_LENGTH</dt> ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^ ** ** [[SQLITE4_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE4_LIMIT_SQL_LENGTH</dt> ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^ ** ** [[SQLITE4_LIMIT_COLUMN]] ^(<dt>SQLITE4_LIMIT_COLUMN</dt> ** <dd>The maximum number of columns in a table definition or in the ** result set of a [SELECT] or the maximum number of columns in an index ** or in an ORDER BY or GROUP BY clause.</dd>)^ ** ** [[SQLITE4_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE4_LIMIT_EXPR_DEPTH</dt> ** <dd>The maximum depth of the parse tree on any expression.</dd>)^ ** ** [[SQLITE4_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE4_LIMIT_COMPOUND_SELECT</dt> ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^ ** ** [[SQLITE4_LIMIT_VDBE_OP]] ^(<dt>SQLITE4_LIMIT_VDBE_OP</dt> ** <dd>The maximum number of instructions in a virtual machine program ** used to implement an SQL statement. This limit is not currently ** enforced, though that might be added in some future release of ** SQLite.</dd>)^ ** ** [[SQLITE4_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE4_LIMIT_FUNCTION_ARG</dt> ** <dd>The maximum number of arguments on a function.</dd>)^ ** ** [[SQLITE4_LIMIT_ATTACHED]] ^(<dt>SQLITE4_LIMIT_ATTACHED</dt> ** <dd>The maximum number of [ATTACH | attached databases].)^</dd> ** ** [[SQLITE4_LIMIT_LIKE_PATTERN_LENGTH]] ** ^(<dt>SQLITE4_LIMIT_LIKE_PATTERN_LENGTH</dt> ** <dd>The maximum length of the pattern argument to the [LIKE] or ** [GLOB] operators.</dd>)^ ** ** [[SQLITE4_LIMIT_VARIABLE_NUMBER]] ** ^(<dt>SQLITE4_LIMIT_VARIABLE_NUMBER</dt> ** <dd>The maximum index number of any [parameter] in an SQL statement.)^ ** ** [[SQLITE4_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE4_LIMIT_TRIGGER_DEPTH</dt> ** <dd>The maximum depth of recursion for triggers.</dd>)^ ** </dl> */ #define SQLITE4_LIMIT_LENGTH 0 #define SQLITE4_LIMIT_SQL_LENGTH 1 #define SQLITE4_LIMIT_COLUMN 2 #define SQLITE4_LIMIT_EXPR_DEPTH 3 #define SQLITE4_LIMIT_COMPOUND_SELECT 4 #define SQLITE4_LIMIT_VDBE_OP 5 #define SQLITE4_LIMIT_FUNCTION_ARG 6 #define SQLITE4_LIMIT_ATTACHED 7 #define SQLITE4_LIMIT_LIKE_PATTERN_LENGTH 8 #define SQLITE4_LIMIT_VARIABLE_NUMBER 9 #define SQLITE4_LIMIT_TRIGGER_DEPTH 10 /* ** CAPIREF: Compiling An SQL Statement ** KEYWORDS: {SQL statement compiler} ** ** To execute an SQL query, it must first be compiled into a byte-code ** program using one of these routines. ** ** The first argument, "db", is a [database connection] obtained from a ** prior successful call to [sqlite4_open()]. ** The database connection must not have been closed. ** ** The second argument, "zSql", is the statement to be compiled, encoded ** as either UTF-8 or UTF-16. The sqlite4_prepare() ** interface uses UTF-8, and sqlite4_prepare16() ** uses UTF-16. ** ** ^If the nByte argument is less than zero, then zSql is read up to the ** first zero terminator. ^If nByte is non-negative, then it is the maximum ** number of bytes read from zSql. ^When nByte is non-negative, the ** zSql string ends at either the first '\000' or '\u0000' character or ** the nByte-th byte, whichever comes first. If the caller knows ** that the supplied string is nul-terminated, then there is a small ** performance advantage to be gained by passing an nByte parameter that ** is equal to the number of bytes in the input string <i>including</i> ** the nul-terminator bytes as this saves SQLite from having to ** make a copy of the input string. ** ** ^If pzTail is not NULL then *pzTail is made to point to the first byte ** past the end of the first SQL statement in zSql. These routines only ** compile the first statement in zSql, so *pzTail is left pointing to ** what remains uncompiled. ** ** ^*ppStmt is left pointing to a compiled [prepared statement] that can be ** executed using [sqlite4_step()]. ^If there is an error, *ppStmt is set ** to NULL. ^If the input text contains no SQL (if the input is an empty ** string or a comment) then *ppStmt is set to NULL. ** The calling procedure is responsible for deleting the compiled ** SQL statement using [sqlite4_finalize()] after it has finished with it. ** ppStmt may not be NULL. ** ** ^On success, the sqlite4_prepare() family of routines return [SQLITE4_OK]; ** otherwise an [error code] is returned. */ SQLITE4_API int sqlite4_prepare( sqlite4 *db, /* Database handle */ const char *zSql, /* SQL statement, UTF-8 encoded */ int nByte, /* Maximum length of zSql in bytes. */ sqlite4_stmt **ppStmt, /* OUT: Statement handle */ const char **pzTail /* OUT: Pointer to unused portion of zSql */ ); /* ** CAPIREF: Retrieving Statement SQL ** ** ^This interface can be used to retrieve a saved copy of the original ** SQL text used to create a [prepared statement] if that statement was ** compiled using either [sqlite4_prepare()] or [sqlite4_prepare16_v2()]. */ SQLITE4_API const char *sqlite4_sql(sqlite4_stmt *pStmt); /* ** CAPIREF: Determine If An SQL Statement Writes The Database ** ** ^The sqlite4_stmt_readonly(X) interface returns true (non-zero) if ** and only if the [prepared statement] X makes no direct changes to ** the content of the database file. ** ** Note that [application-defined SQL functions] or ** [virtual tables] might change the database indirectly as a side effect. ** ^(For example, if an application defines a function "eval()" that ** calls [sqlite4_exec()], then the following SQL statement would ** change the database file through side-effects: ** ** <blockquote><pre> ** SELECT eval('DELETE FROM t1') FROM t2; ** </pre></blockquote> ** ** But because the [SELECT] statement does not change the database file ** directly, sqlite4_stmt_readonly() would still return true.)^ ** ** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK], ** [SAVEPOINT], and [RELEASE] cause sqlite4_stmt_readonly() to return true, ** since the statements themselves do not actually modify the database but ** rather they control the timing of when other statements modify the ** database. ^The [ATTACH] and [DETACH] statements also cause ** sqlite4_stmt_readonly() to return true since, while those statements ** change the configuration of a database connection, they do not make ** changes to the content of the database files on disk. */ SQLITE4_API int sqlite4_stmt_readonly(sqlite4_stmt *pStmt); /* ** CAPIREF: Determine If A Prepared Statement Has Been Reset ** ** ^The sqlite4_stmt_busy(S) interface returns true (non-zero) if the ** [prepared statement] S has been stepped at least once using ** [sqlite4_step(S)] but has not run to completion and/or has not ** been reset using [sqlite4_reset(S)]. ^The sqlite4_stmt_busy(S) ** interface returns false if S is a NULL pointer. If S is not a ** NULL pointer and is not a pointer to a valid [prepared statement] ** object, then the behavior is undefined and probably undesirable. ** ** This interface can be used in combination [sqlite4_next_stmt()] ** to locate all prepared statements associated with a database ** connection that are in need of being reset. This can be used, ** for example, in diagnostic routines to search for prepared ** statements that are holding a transaction open. */ SQLITE4_API int sqlite4_stmt_busy(sqlite4_stmt*); /* ** CAPIREF: Dynamically Typed Value Object ** KEYWORDS: {protected sqlite4_value} {unprotected sqlite4_value} ** ** SQLite uses the sqlite4_value object to represent all values ** that can be stored in a database table. SQLite uses dynamic typing ** for the values it stores. ^Values stored in sqlite4_value objects ** can be integers, floating point values, strings, BLOBs, or NULL. ** ** An sqlite4_value object may be either "protected" or "unprotected". ** Some interfaces require a protected sqlite4_value. Other interfaces ** will accept either a protected or an unprotected sqlite4_value. ** Every interface that accepts sqlite4_value arguments specifies ** whether or not it requires a protected sqlite4_value. ** ** The terms "protected" and "unprotected" refer to whether or not ** a mutex is held. An internal mutex is held for a protected ** sqlite4_value object but no mutex is held for an unprotected ** sqlite4_value object. If SQLite is compiled to be single-threaded ** (with [SQLITE4_THREADSAFE=0] and with [sqlite4_threadsafe()] returning 0) ** or if SQLite is run in one of reduced mutex modes ** [SQLITE4_CONFIG_SINGLETHREAD] or [SQLITE4_CONFIG_MULTITHREAD] ** then there is no distinction between protected and unprotected ** sqlite4_value objects and they can be used interchangeably. However, ** for maximum code portability it is recommended that applications ** still make the distinction between protected and unprotected ** sqlite4_value objects even when not strictly required. ** ** ^The sqlite4_value objects that are passed as parameters into the ** implementation of [application-defined SQL functions] are protected. ** ^The sqlite4_value object returned by ** [sqlite4_column_value()] is unprotected. ** Unprotected sqlite4_value objects may only be used with ** [sqlite4_result_value()] and [sqlite4_bind_value()]. ** The [sqlite4_value_blob | sqlite4_value_type()] family of ** interfaces require protected sqlite4_value objects. */ typedef struct Mem sqlite4_value; /* ** CAPIREF: SQL Function Context Object ** ** The context in which an SQL function executes is stored in an ** sqlite4_context object. ^A pointer to an sqlite4_context object ** is always first parameter to [application-defined SQL functions]. ** The application-defined SQL function implementation will pass this ** pointer through into calls to [sqlite4_result_int | sqlite4_result()], ** [sqlite4_aggregate_context()], [sqlite4_user_data()], ** [sqlite4_context_db_handle()], [sqlite4_get_auxdata()], ** and/or [sqlite4_set_auxdata()]. */ typedef struct sqlite4_context sqlite4_context; /* ** CAPIREF: Binding Values To Prepared Statements ** KEYWORDS: {host parameter} {host parameters} {host parameter name} ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding} ** ** ^(In the SQL statement text input to [sqlite4_prepare()] and its variants, ** literals may be replaced by a [parameter] that matches one of following ** templates: ** ** <ul> ** <li> ? ** <li> ?NNN ** <li> :VVV ** <li> @VVV ** <li> $VVV ** </ul> ** ** In the templates above, NNN represents an integer literal, ** and VVV represents an alphanumeric identifier.)^ ^The values of these ** parameters (also called "host parameter names" or "SQL parameters") ** can be set using the sqlite4_bind_*() routines defined here. ** ** ^The first argument to the sqlite4_bind_*() routines is always ** a pointer to the [sqlite4_stmt] object returned from ** [sqlite4_prepare()] or its variants. ** ** ^The second argument is the index of the SQL parameter to be set. ** ^The leftmost SQL parameter has an index of 1. ^When the same named ** SQL parameter is used more than once, second and subsequent ** occurrences have the same index as the first occurrence. ** ^The index for named parameters can be looked up using the ** [sqlite4_bind_parameter_index()] API if desired. ^The index ** for "?NNN" parameters is the value of NNN. ** ^The NNN value must be between 1 and the [sqlite4_limit()] ** parameter [SQLITE4_LIMIT_VARIABLE_NUMBER] (default value: 999). ** ** ^The third argument is the value to bind to the parameter. ** ** ^(In those routines that have a fourth argument, its value is the ** number of bytes in the parameter. To be clear: the value is the ** number of <u>bytes</u> in the value, not the number of characters.)^ ** ^If the fourth parameter is negative, the length of the string is ** the number of bytes up to the first zero terminator. ** If a non-negative fourth parameter is provided to sqlite4_bind_text() ** or sqlite4_bind_text16() then that parameter must be the byte offset ** where the NUL terminator would occur assuming the string were NUL ** terminated. If any NUL characters occur at byte offsets less than ** the value of the fourth parameter then the resulting string value will ** contain embedded NULs. The result of expressions involving strings ** with embedded NULs is undefined. ** ** ^The fifth argument to sqlite4_bind_blob(), sqlite4_bind_text(), and ** sqlite4_bind_text16() is a destructor used to dispose of the BLOB or ** string after SQLite has finished with it. ^The destructor is called ** to dispose of the BLOB or string even if the call to sqlite4_bind_blob(), ** sqlite4_bind_text(), or sqlite4_bind_text16() fails. ** ^If the fifth argument is ** the special value [SQLITE4_STATIC], then SQLite assumes that the ** information is in static, unmanaged space and does not need to be freed. ** ^If the fifth argument has the value [SQLITE4_TRANSIENT], then ** SQLite makes its own private copy of the data immediately, before ** the sqlite4_bind_*() routine returns. ** ** ^The sqlite4_bind_zeroblob() routine binds a BLOB of length N that ** is filled with zeroes. ^A zeroblob uses a fixed amount of memory ** (just an integer to hold its size) while it is being processed. ** Zeroblobs are intended to serve as placeholders for BLOBs whose ** content is later written using ** [sqlite4_blob_open | incremental BLOB I/O] routines. ** ^A negative value for the zeroblob results in a zero-length BLOB. ** ** ^If any of the sqlite4_bind_*() routines are called with a NULL pointer ** for the [prepared statement] or with a prepared statement for which ** [sqlite4_step()] has been called more recently than [sqlite4_reset()], ** then the call will return [SQLITE4_MISUSE]. If any sqlite4_bind_() ** routine is passed a [prepared statement] that has been finalized, the ** result is undefined and probably harmful. ** ** ^Bindings are not cleared by the [sqlite4_reset()] routine. ** ^Unbound parameters are interpreted as NULL. ** ** ^The sqlite4_bind_* routines return [SQLITE4_OK] on success or an ** [error code] if anything goes wrong. ** ^[SQLITE4_RANGE] is returned if the parameter ** index is out of range. ^[SQLITE4_NOMEM] is returned if malloc() fails. ** ** See also: [sqlite4_bind_parameter_count()], ** [sqlite4_bind_parameter_name()], and [sqlite4_bind_parameter_index()]. */ SQLITE4_API int sqlite4_bind_blob(sqlite4_stmt*, int, const void*, int n, void(*)(void*)); SQLITE4_API int sqlite4_bind_double(sqlite4_stmt*, int, double); SQLITE4_API int sqlite4_bind_int(sqlite4_stmt*, int, int); SQLITE4_API int sqlite4_bind_int64(sqlite4_stmt*, int, sqlite4_int64); SQLITE4_API int sqlite4_bind_null(sqlite4_stmt*, int); SQLITE4_API int sqlite4_bind_text(sqlite4_stmt*, int, const char*, int n, void(*)(void*)); SQLITE4_API int sqlite4_bind_text16(sqlite4_stmt*, int, const void*, int, void(*)(void*)); SQLITE4_API int sqlite4_bind_value(sqlite4_stmt*, int, const sqlite4_value*); SQLITE4_API int sqlite4_bind_zeroblob(sqlite4_stmt*, int, int n); /* ** CAPIREF: Number Of SQL Parameters ** ** ^This routine can be used to find the number of [SQL parameters] ** in a [prepared statement]. SQL parameters are tokens of the ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as ** placeholders for values that are [sqlite4_bind_blob | bound] ** to the parameters at a later time. ** ** ^(This routine actually returns the index of the largest (rightmost) ** parameter. For all forms except ?NNN, this will correspond to the ** number of unique parameters. If parameters of the ?NNN form are used, ** there may be gaps in the list.)^ ** ** See also: [sqlite4_bind_blob|sqlite4_bind()], ** [sqlite4_bind_parameter_name()], and ** [sqlite4_bind_parameter_index()]. */ SQLITE4_API int sqlite4_bind_parameter_count(sqlite4_stmt*); /* ** CAPIREF: Name Of A Host Parameter ** ** ^The sqlite4_bind_parameter_name(P,N) interface returns ** the name of the N-th [SQL parameter] in the [prepared statement] P. ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA" ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA" ** respectively. ** In other words, the initial ":" or "$" or "@" or "?" ** is included as part of the name.)^ ** ^Parameters of the form "?" without a following integer have no name ** and are referred to as "nameless" or "anonymous parameters". ** ** ^The first host parameter has an index of 1, not 0. ** ** ^If the value N is out of range or if the N-th parameter is ** nameless, then NULL is returned. ^The returned string is ** always in UTF-8 encoding even if the named parameter was ** originally specified as UTF-16 in [sqlite4_prepare16()] or ** [sqlite4_prepare16_v2()]. ** ** See also: [sqlite4_bind_blob|sqlite4_bind()], ** [sqlite4_bind_parameter_count()], and ** [sqlite4_bind_parameter_index()]. */ SQLITE4_API const char *sqlite4_bind_parameter_name(sqlite4_stmt*, int); /* ** CAPIREF: Index Of A Parameter With A Given Name ** ** ^Return the index of an SQL parameter given its name. ^The ** index value returned is suitable for use as the second ** parameter to [sqlite4_bind_blob|sqlite4_bind()]. ^A zero ** is returned if no matching parameter is found. ^The parameter ** name must be given in UTF-8 even if the original statement ** was prepared from UTF-16 text using [sqlite4_prepare16_v2()]. ** ** See also: [sqlite4_bind_blob|sqlite4_bind()], ** [sqlite4_bind_parameter_count()], and ** [sqlite4_bind_parameter_index()]. */ SQLITE4_API int sqlite4_bind_parameter_index(sqlite4_stmt*, const char *zName); /* ** CAPIREF: Reset All Bindings On A Prepared Statement ** ** ^Contrary to the intuition of many, [sqlite4_reset()] does not reset ** the [sqlite4_bind_blob | bindings] on a [prepared statement]. ** ^Use this routine to reset all host parameters to NULL. */ SQLITE4_API int sqlite4_clear_bindings(sqlite4_stmt*); /* ** CAPIREF: Number Of Columns In A Result Set ** ** ^Return the number of columns in the result set returned by the ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL ** statement that does not return data (for example an [UPDATE]). ** ** See also: [sqlite4_data_count()] */ SQLITE4_API int sqlite4_column_count(sqlite4_stmt *pStmt); /* ** CAPIREF: Column Names In A Result Set ** ** ^These routines return the name assigned to a particular column ** in the result set of a [SELECT] statement. ^The sqlite4_column_name() ** interface returns a pointer to a zero-terminated UTF-8 string ** and sqlite4_column_name16() returns a pointer to a zero-terminated ** UTF-16 string. ^The first parameter is the [prepared statement] ** that implements the [SELECT] statement. ^The second parameter is the ** column number. ^The leftmost column is number 0. ** ** ^The returned string pointer is valid until either the [prepared statement] ** is destroyed by [sqlite4_finalize()] or until the statement is automatically ** reprepared by the first call to [sqlite4_step()] for a particular run ** or until the next call to ** sqlite4_column_name() or sqlite4_column_name16() on the same column. ** ** ^If sqlite4_malloc() fails during the processing of either routine ** (for example during a conversion from UTF-8 to UTF-16) then a ** NULL pointer is returned. ** ** ^The name of a result column is the value of the "AS" clause for ** that column, if there is an AS clause. If there is no AS clause ** then the name of the column is unspecified and may change from ** one release of SQLite to the next. */ SQLITE4_API const char *sqlite4_column_name(sqlite4_stmt*, int N); SQLITE4_API const void *sqlite4_column_name16(sqlite4_stmt*, int N); /* ** CAPIREF: Source Of Data In A Query Result ** ** ^These routines provide a means to determine the database, table, and ** table column that is the origin of a particular result column in ** [SELECT] statement. ** ^The name of the database or table or column can be returned as ** either a UTF-8 or UTF-16 string. ^The _database_ routines return ** the database name, the _table_ routines return the table name, and ** the origin_ routines return the column name. ** ^The returned string is valid until the [prepared statement] is destroyed ** using [sqlite4_finalize()] or until the statement is automatically ** reprepared by the first call to [sqlite4_step()] for a particular run ** or until the same information is requested ** again in a different encoding. ** ** ^The names returned are the original un-aliased names of the ** database, table, and column. ** ** ^The first argument to these interfaces is a [prepared statement]. ** ^These functions return information about the Nth result column returned by ** the statement, where N is the second function argument. ** ^The left-most column is column 0 for these routines. ** ** ^If the Nth column returned by the statement is an expression or ** subquery and is not a column value, then all of these functions return ** NULL. ^These routine might also return NULL if a memory allocation error ** occurs. ^Otherwise, they return the name of the attached database, table, ** or column that query result column was extracted from. ** ** ^As with all other SQLite APIs, those whose names end with "16" return ** UTF-16 encoded strings and the other functions return UTF-8. ** ** ^These APIs are only available if the library was compiled with the ** [SQLITE4_ENABLE_COLUMN_METADATA] C-preprocessor symbol. ** ** If two or more threads call one or more of these routines against the same ** prepared statement and column at the same time then the results are ** undefined. ** ** If two or more threads call one or more ** [sqlite4_column_database_name | column metadata interfaces] ** for the same [prepared statement] and result column ** at the same time then the results are undefined. */ SQLITE4_API const char *sqlite4_column_database_name(sqlite4_stmt*,int); SQLITE4_API const void *sqlite4_column_database_name16(sqlite4_stmt*,int); SQLITE4_API const char *sqlite4_column_table_name(sqlite4_stmt*,int); SQLITE4_API const void *sqlite4_column_table_name16(sqlite4_stmt*,int); SQLITE4_API const char *sqlite4_column_origin_name(sqlite4_stmt*,int); SQLITE4_API const void *sqlite4_column_origin_name16(sqlite4_stmt*,int); /* ** CAPIREF: Declared Datatype Of A Query Result ** ** ^(The first parameter is a [prepared statement]. ** If this statement is a [SELECT] statement and the Nth column of the ** returned result set of that [SELECT] is a table column (not an ** expression or subquery) then the declared type of the table ** column is returned.)^ ^If the Nth column of the result set is an ** expression or subquery, then a NULL pointer is returned. ** ^The returned string is always UTF-8 encoded. ** ** ^(For example, given the database schema: ** ** CREATE TABLE t1(c1 VARIANT); ** ** and the following statement to be compiled: ** ** SELECT c1 + 1, c1 FROM t1; ** ** this routine would return the string "VARIANT" for the second result ** column (i==1), and a NULL pointer for the first result column (i==0).)^ ** ** ^SQLite uses dynamic run-time typing. ^So just because a column ** is declared to contain a particular type does not mean that the ** data stored in that column is of the declared type. SQLite is ** strongly typed, but the typing is dynamic not static. ^Type ** is associated with individual values, not with the containers ** used to hold those values. */ SQLITE4_API const char *sqlite4_column_decltype(sqlite4_stmt*,int); SQLITE4_API const void *sqlite4_column_decltype16(sqlite4_stmt*,int); /* ** CAPIREF: Evaluate An SQL Statement ** ** After a [prepared statement] has been prepared using [sqlite4_prepare()], ** this function must be called one or more times to evaluate the statement. ** ** ^This routine can return any of the other [result codes] or ** [extended result codes]. ** ** ^[SQLITE4_BUSY] means that the database engine was unable to acquire the ** database locks it needs to do its job. ^If the statement is a [COMMIT] ** or occurs outside of an explicit transaction, then you can retry the ** statement. If the statement is not a [COMMIT] and occurs within an ** explicit transaction then you should rollback the transaction before ** continuing. ** ** ^[SQLITE4_DONE] means that the statement has finished executing ** successfully. sqlite4_step() should not be called again on this virtual ** machine without first calling [sqlite4_reset()] to reset the virtual ** machine back to its initial state. ** ** ^If the SQL statement being executed returns any data, then [SQLITE4_ROW] ** is returned each time a new row of data is ready for processing by the ** caller. The values may be accessed using the [column access functions]. ** sqlite4_step() is called again to retrieve the next row of data. ** ** ^[SQLITE4_ERROR] means that a run-time error (such as a constraint ** violation) has occurred. sqlite4_step() should not be called again on ** the VM. More information may be found by calling [sqlite4_errmsg()]. ** ** [SQLITE4_MISUSE] means that the this routine was called inappropriately. ** Perhaps it was called on a [prepared statement] that has ** already been [sqlite4_finalize | finalized] or on one that had ** previously returned [SQLITE4_ERROR] or [SQLITE4_DONE]. Or it could ** be the case that the same database connection is being used by two or ** more threads at the same moment in time. */ SQLITE4_API int sqlite4_step(sqlite4_stmt*); /* ** CAPIREF: Number of columns in a result set ** ** ^The sqlite4_data_count(P) interface returns the number of columns in the ** current row of the result set of [prepared statement] P. ** ^If prepared statement P does not have results ready to return ** (via calls to the [sqlite4_column_int | sqlite4_column_*()] of ** interfaces) then sqlite4_data_count(P) returns 0. ** ^The sqlite4_data_count(P) routine also returns 0 if P is a NULL pointer. ** ^The sqlite4_data_count(P) routine returns 0 if the previous call to ** [sqlite4_step](P) returned [SQLITE4_DONE]. ^The sqlite4_data_count(P) ** will return non-zero if previous call to [sqlite4_step](P) returned ** [SQLITE4_ROW], except in the case of the [PRAGMA incremental_vacuum] ** where it always returns zero since each step of that multi-step ** pragma returns 0 columns of data. ** ** See also: [sqlite4_column_count()] */ SQLITE4_API int sqlite4_data_count(sqlite4_stmt *pStmt); /* ** CAPIREF: Fundamental Datatypes ** KEYWORDS: SQLITE4_TEXT ** ** ^(Every value in SQLite has one of five fundamental datatypes: ** ** <ul> ** <li> 64-bit signed integer ** <li> 64-bit IEEE floating point number ** <li> string ** <li> BLOB ** <li> NULL ** </ul>)^ ** ** These constants are codes for each of those types. */ #define SQLITE4_INTEGER 1 #define SQLITE4_FLOAT 2 #define SQLITE4_TEXT 3 #define SQLITE4_BLOB 4 #define SQLITE4_NULL 5 /* ** CAPIREF: Result Values From A Query ** KEYWORDS: {column access functions} ** ** These routines form the "result set" interface. ** ** ^These routines return information about a single column of the current ** result row of a query. ^In every case the first argument is a pointer ** to the [prepared statement] that is being evaluated (the [sqlite4_stmt*] ** that was returned from [sqlite4_prepare()]. ** and the second argument is the index of the column for which information ** should be returned. ^The leftmost column of the result set has the index 0. ** ^The number of columns in the result can be determined using ** [sqlite4_column_count()]. ** ** If the SQL statement does not currently point to a valid row, or if the ** column index is out of range, the result is undefined. ** These routines may only be called when the most recent call to ** [sqlite4_step()] has returned [SQLITE4_ROW] and neither ** [sqlite4_reset()] nor [sqlite4_finalize()] have been called subsequently. ** If any of these routines are called after [sqlite4_reset()] or ** [sqlite4_finalize()] or after [sqlite4_step()] has returned ** something other than [SQLITE4_ROW], the results are undefined. ** If [sqlite4_step()] or [sqlite4_reset()] or [sqlite4_finalize()] ** are called from a different thread while any of these routines ** are pending, then the results are undefined. ** ** ^The sqlite4_column_type() routine returns the ** [SQLITE4_INTEGER | datatype code] for the initial data type ** of the result column. ^The returned value is one of [SQLITE4_INTEGER], ** [SQLITE4_FLOAT], [SQLITE4_TEXT], [SQLITE4_BLOB], or [SQLITE4_NULL]. The value ** returned by sqlite4_column_type() is only meaningful if no type ** conversions have occurred as described below. After a type conversion, ** the value returned by sqlite4_column_type() is undefined. Future ** versions of SQLite may change the behavior of sqlite4_column_type() ** following a type conversion. ** ** ^If the result is a BLOB or UTF-8 string then the sqlite4_column_bytes() ** routine returns the number of bytes in that BLOB or string. ** ^If the result is a UTF-16 string, then sqlite4_column_bytes() converts ** the string to UTF-8 and then returns the number of bytes. ** ^If the result is a numeric value then sqlite4_column_bytes() uses ** [sqlite4_snprintf()] to convert that value to a UTF-8 string and returns ** the number of bytes in that string. ** ^If the result is NULL, then sqlite4_column_bytes() returns zero. ** ** ^If the result is a BLOB or UTF-16 string then the sqlite4_column_bytes16() ** routine returns the number of bytes in that BLOB or string. ** ^If the result is a UTF-8 string, then sqlite4_column_bytes16() converts ** the string to UTF-16 and then returns the number of bytes. ** ^If the result is a numeric value then sqlite4_column_bytes16() uses ** [sqlite4_snprintf()] to convert that value to a UTF-16 string and returns ** the number of bytes in that string. ** ^If the result is NULL, then sqlite4_column_bytes16() returns zero. ** ** ^The values returned by [sqlite4_column_bytes()] and ** [sqlite4_column_bytes16()] do not include the zero terminators at the end ** of the string. ^For clarity: the values returned by ** [sqlite4_column_bytes()] and [sqlite4_column_bytes16()] are the number of ** bytes in the string, not the number of characters. ** ** ^Strings returned by sqlite4_column_text() and sqlite4_column_text16(), ** even empty strings, are always zero-terminated. ^The return ** value from sqlite4_column_blob() for a zero-length BLOB is a NULL pointer. ** ** ^The object returned by [sqlite4_column_value()] is an ** [unprotected sqlite4_value] object. An unprotected sqlite4_value object ** may only be used with [sqlite4_bind_value()] and [sqlite4_result_value()]. ** If the [unprotected sqlite4_value] object returned by ** [sqlite4_column_value()] is used in any other way, including calls ** to routines like [sqlite4_value_int()], [sqlite4_value_text()], ** or [sqlite4_value_bytes()], then the behavior is undefined. ** ** These routines attempt to convert the value where appropriate. ^For ** example, if the internal representation is FLOAT and a text result ** is requested, [sqlite4_snprintf()] is used internally to perform the ** conversion automatically. ^(The following table details the conversions ** that are applied: ** ** <blockquote> ** <table border="1"> ** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion ** ** <tr><td> NULL <td> INTEGER <td> Result is 0 ** <tr><td> NULL <td> FLOAT <td> Result is 0.0 ** <tr><td> NULL <td> TEXT <td> Result is NULL pointer ** <tr><td> NULL <td> BLOB <td> Result is NULL pointer ** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float ** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer ** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT ** <tr><td> FLOAT <td> INTEGER <td> Convert from float to integer ** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float ** <tr><td> FLOAT <td> BLOB <td> Same as FLOAT->TEXT ** <tr><td> TEXT <td> INTEGER <td> Use atoi() ** <tr><td> TEXT <td> FLOAT <td> Use atof() ** <tr><td> TEXT <td> BLOB <td> No change ** <tr><td> BLOB <td> INTEGER <td> Convert to TEXT then use atoi() ** <tr><td> BLOB <td> FLOAT <td> Convert to TEXT then use atof() ** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed ** </table> ** </blockquote>)^ ** ** The table above makes reference to standard C library functions atoi() ** and atof(). SQLite does not really use these functions. It has its ** own equivalent internal routines. The atoi() and atof() names are ** used in the table for brevity and because they are familiar to most ** C programmers. ** ** Note that when type conversions occur, pointers returned by prior ** calls to sqlite4_column_blob(), sqlite4_column_text(), and/or ** sqlite4_column_text16() may be invalidated. ** Type conversions and pointer invalidations might occur ** in the following cases: ** ** <ul> ** <li> The initial content is a BLOB and sqlite4_column_text() or ** sqlite4_column_text16() is called. A zero-terminator might ** need to be added to the string.</li> ** <li> The initial content is UTF-8 text and sqlite4_column_bytes16() or ** sqlite4_column_text16() is called. The content must be converted ** to UTF-16.</li> ** <li> The initial content is UTF-16 text and sqlite4_column_bytes() or ** sqlite4_column_text() is called. The content must be converted ** to UTF-8.</li> ** </ul> ** ** ^Conversions between UTF-16be and UTF-16le are always done in place and do ** not invalidate a prior pointer, though of course the content of the buffer ** that the prior pointer references will have been modified. Other kinds ** of conversion are done in place when it is possible, but sometimes they ** are not possible and in those cases prior pointers are invalidated. ** ** The safest and easiest to remember policy is to invoke these routines ** in one of the following ways: ** ** <ul> ** <li>sqlite4_column_text() followed by sqlite4_column_bytes()</li> ** <li>sqlite4_column_blob() followed by sqlite4_column_bytes()</li> ** <li>sqlite4_column_text16() followed by sqlite4_column_bytes16()</li> ** </ul> ** ** In other words, you should call sqlite4_column_text(), ** sqlite4_column_blob(), or sqlite4_column_text16() first to force the result ** into the desired format, then invoke sqlite4_column_bytes() or ** sqlite4_column_bytes16() to find the size of the result. Do not mix calls ** to sqlite4_column_text() or sqlite4_column_blob() with calls to ** sqlite4_column_bytes16(), and do not mix calls to sqlite4_column_text16() ** with calls to sqlite4_column_bytes(). ** ** ^The pointers returned are valid until a type conversion occurs as ** described above, or until [sqlite4_step()] or [sqlite4_reset()] or ** [sqlite4_finalize()] is called. ^The memory space used to hold strings ** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned ** [sqlite4_column_blob()], [sqlite4_column_text()], etc. into ** [sqlite4_free()]. ** ** ^(If a memory allocation error occurs during the evaluation of any ** of these routines, a default value is returned. The default value ** is either the integer 0, the floating point number 0.0, or a NULL ** pointer. Subsequent calls to [sqlite4_errcode()] will return ** [SQLITE4_NOMEM].)^ */ SQLITE4_API const void *sqlite4_column_blob(sqlite4_stmt*, int iCol); SQLITE4_API int sqlite4_column_bytes(sqlite4_stmt*, int iCol); SQLITE4_API int sqlite4_column_bytes16(sqlite4_stmt*, int iCol); SQLITE4_API double sqlite4_column_double(sqlite4_stmt*, int iCol); SQLITE4_API int sqlite4_column_int(sqlite4_stmt*, int iCol); SQLITE4_API sqlite4_int64 sqlite4_column_int64(sqlite4_stmt*, int iCol); SQLITE4_API const unsigned char *sqlite4_column_text(sqlite4_stmt*, int iCol); SQLITE4_API const void *sqlite4_column_text16(sqlite4_stmt*, int iCol); SQLITE4_API int sqlite4_column_type(sqlite4_stmt*, int iCol); SQLITE4_API sqlite4_value *sqlite4_column_value(sqlite4_stmt*, int iCol); /* ** CAPIREF: Destroy A Prepared Statement Object ** ** ^The sqlite4_finalize() function is called to delete a [prepared statement]. ** ^If the most recent evaluation of the statement encountered no errors ** or if the statement is never been evaluated, then sqlite4_finalize() returns ** SQLITE4_OK. ^If the most recent evaluation of statement S failed, then ** sqlite4_finalize(S) returns the appropriate [error code] or ** [extended error code]. ** ** ^The sqlite4_finalize(S) routine can be called at any point during ** the life cycle of [prepared statement] S: ** before statement S is ever evaluated, after ** one or more calls to [sqlite4_reset()], or after any call ** to [sqlite4_step()] regardless of whether or not the statement has ** completed execution. ** ** ^Invoking sqlite4_finalize() on a NULL pointer is a harmless no-op. ** ** The application must finalize every [prepared statement] in order to avoid ** resource leaks. It is a grievous error for the application to try to use ** a prepared statement after it has been finalized. Any use of a prepared ** statement after it has been finalized can result in undefined and ** undesirable behavior such as segfaults and heap corruption. */ SQLITE4_API int sqlite4_finalize(sqlite4_stmt *pStmt); /* ** CAPIREF: Reset A Prepared Statement Object ** ** The sqlite4_reset() function is called to reset a [prepared statement] ** object back to its initial state, ready to be re-executed. ** ^Any SQL statement variables that had values bound to them using ** the [sqlite4_bind_blob | sqlite4_bind_*() API] retain their values. ** Use [sqlite4_clear_bindings()] to reset the bindings. ** ** ^The [sqlite4_reset(S)] interface resets the [prepared statement] S ** back to the beginning of its program. ** ** ^If the most recent call to [sqlite4_step(S)] for the ** [prepared statement] S returned [SQLITE4_ROW] or [SQLITE4_DONE], ** or if [sqlite4_step(S)] has never before been called on S, ** then [sqlite4_reset(S)] returns [SQLITE4_OK]. ** ** ^If the most recent call to [sqlite4_step(S)] for the ** [prepared statement] S indicated an error, then ** [sqlite4_reset(S)] returns an appropriate [error code]. ** ** ^The [sqlite4_reset(S)] interface does not change the values ** of any [sqlite4_bind_blob|bindings] on the [prepared statement] S. */ SQLITE4_API int sqlite4_reset(sqlite4_stmt *pStmt); /* ** CAPIREF: Create Or Redefine SQL Functions ** KEYWORDS: {function creation routines} ** KEYWORDS: {application-defined SQL function} ** KEYWORDS: {application-defined SQL functions} ** ** ^These functions (collectively known as "function creation routines") ** are used to add SQL functions or aggregates or to redefine the behavior ** of existing SQL functions or aggregates. The only differences between ** these routines are the text encoding expected for ** the second parameter (the name of the function being created) ** and the presence or absence of a destructor callback for ** the application data pointer. ** ** ^The first parameter is the [database connection] to which the SQL ** function is to be added. ^If an application uses more than one database ** connection then application-defined SQL functions must be added ** to each database connection separately. ** ** ^The second parameter is the name of the SQL function to be created or ** redefined. ^The length of the name is limited to 255 bytes in a UTF-8 ** representation, exclusive of the zero-terminator. ^Note that the name ** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes. ** ^Any attempt to create a function with a longer name ** will result in [SQLITE4_MISUSE] being returned. ** ** ^The third parameter (nArg) ** is the number of arguments that the SQL function or ** aggregate takes. ^If this parameter is -1, then the SQL function or ** aggregate may take any number of arguments between 0 and the limit ** set by [sqlite4_limit]([SQLITE4_LIMIT_FUNCTION_ARG]). If the third ** parameter is less than -1 or greater than 127 then the behavior is ** undefined. ** ** ^The fourth parameter, eTextRep, specifies what ** [SQLITE4_UTF8 | text encoding] this SQL function prefers for ** its parameters. Every SQL function implementation must be able to work ** with UTF-8, UTF-16le, or UTF-16be. But some implementations may be ** more efficient with one encoding than another. ^An application may ** invoke sqlite4_create_function() or sqlite4_create_function16() multiple ** times with the same function but with different values of eTextRep. ** ^When multiple implementations of the same function are available, SQLite ** will pick the one that involves the least amount of data conversion. ** If there is only a single implementation which does not care what text ** encoding is used, then the fourth argument should be [SQLITE4_ANY]. ** ** ^(The fifth parameter is an arbitrary pointer. The implementation of the ** function can gain access to this pointer using [sqlite4_user_data()].)^ ** ** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are ** pointers to C-language functions that implement the SQL function or ** aggregate. ^A scalar SQL function requires an implementation of the xFunc ** callback only; NULL pointers must be passed as the xStep and xFinal ** parameters. ^An aggregate SQL function requires an implementation of xStep ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing ** SQL function or aggregate, pass NULL pointers for all three function ** callbacks. ** ** ^(If the ninth parameter to sqlite4_create_function_v2() is not NULL, ** then it is destructor for the application data pointer. ** The destructor is invoked when the function is deleted, either by being ** overloaded or when the database connection closes.)^ ** ^The destructor is also invoked if the call to ** sqlite4_create_function_v2() fails. ** ^When the destructor callback of the tenth parameter is invoked, it ** is passed a single argument which is a copy of the application data ** pointer which was the fifth parameter to sqlite4_create_function_v2(). ** ** ^It is permitted to register multiple implementations of the same ** functions with the same name but with either differing numbers of ** arguments or differing preferred text encodings. ^SQLite will use ** the implementation that most closely matches the way in which the ** SQL function is used. ^A function implementation with a non-negative ** nArg parameter is a better match than a function implementation with ** a negative nArg. ^A function where the preferred text encoding ** matches the database encoding is a better ** match than a function where the encoding is different. ** ^A function where the encoding difference is between UTF16le and UTF16be ** is a closer match than a function where the encoding difference is ** between UTF8 and UTF16. ** ** ^Built-in functions may be overloaded by new application-defined functions. ** ** ^An application-defined function is permitted to call other ** SQLite interfaces. However, such calls must not ** close the database connection nor finalize or reset the prepared ** statement in which the function is running. */ SQLITE4_API int sqlite4_create_function( sqlite4 *db, const char *zFunctionName, int nArg, int eTextRep, void *pApp, void (*xFunc)(sqlite4_context*,int,sqlite4_value**), void (*xStep)(sqlite4_context*,int,sqlite4_value**), void (*xFinal)(sqlite4_context*) ); SQLITE4_API int sqlite4_create_function16( sqlite4 *db, const void *zFunctionName, int nArg, int eTextRep, void *pApp, void (*xFunc)(sqlite4_context*,int,sqlite4_value**), void (*xStep)(sqlite4_context*,int,sqlite4_value**), void (*xFinal)(sqlite4_context*) ); SQLITE4_API int sqlite4_create_function_v2( sqlite4 *db, const char *zFunctionName, int nArg, int eTextRep, void *pApp, void (*xFunc)(sqlite4_context*,int,sqlite4_value**), void (*xStep)(sqlite4_context*,int,sqlite4_value**), void (*xFinal)(sqlite4_context*), void(*xDestroy)(void*) ); /* ** CAPIREF: Text Encodings ** ** These constant define integer codes that represent the various ** text encodings supported by SQLite. */ #define SQLITE4_UTF8 1 #define SQLITE4_UTF16LE 2 #define SQLITE4_UTF16BE 3 #define SQLITE4_UTF16 4 /* Use native byte order */ #define SQLITE4_ANY 5 /* sqlite4_create_function only */ #define SQLITE4_UTF16_ALIGNED 8 /* sqlite4_create_collation only */ /* ** CAPIREF: Deprecated Functions ** DEPRECATED ** ** These functions are [deprecated]. In order to maintain ** backwards compatibility with older code, these functions continue ** to be supported. However, new applications should avoid ** the use of these functions. To help encourage people to avoid ** using these functions, we are not going to tell you what they do. */ #ifndef SQLITE4_OMIT_DEPRECATED SQLITE4_API SQLITE4_DEPRECATED int sqlite4_aggregate_count(sqlite4_context*); SQLITE4_API SQLITE4_DEPRECATED int sqlite4_expired(sqlite4_stmt*); SQLITE4_API SQLITE4_DEPRECATED int sqlite4_transfer_bindings(sqlite4_stmt*, sqlite4_stmt*); SQLITE4_API SQLITE4_DEPRECATED int sqlite4_global_recover(void); #endif /* ** CAPIREF: Obtaining SQL Function Parameter Values ** ** The C-language implementation of SQL functions and aggregates uses ** this set of interface routines to access the parameter values on ** the function or aggregate. ** ** The xFunc (for scalar functions) or xStep (for aggregates) parameters ** to [sqlite4_create_function()] and [sqlite4_create_function16()] ** define callbacks that implement the SQL functions and aggregates. ** The 3rd parameter to these callbacks is an array of pointers to ** [protected sqlite4_value] objects. There is one [sqlite4_value] object for ** each parameter to the SQL function. These routines are used to ** extract values from the [sqlite4_value] objects. ** ** These routines work only with [protected sqlite4_value] objects. ** Any attempt to use these routines on an [unprotected sqlite4_value] ** object results in undefined behavior. ** ** ^These routines work just like the corresponding [column access functions] ** except that these routines take a single [protected sqlite4_value] object ** pointer instead of a [sqlite4_stmt*] pointer and an integer column number. ** ** ^The sqlite4_value_text16() interface extracts a UTF-16 string ** in the native byte-order of the host machine. ^The ** sqlite4_value_text16be() and sqlite4_value_text16le() interfaces ** extract UTF-16 strings as big-endian and little-endian respectively. ** ** ^(The sqlite4_value_numeric_type() interface attempts to apply ** numeric affinity to the value. This means that an attempt is ** made to convert the value to an integer or floating point. If ** such a conversion is possible without loss of information (in other ** words, if the value is a string that looks like a number) ** then the conversion is performed. Otherwise no conversion occurs. ** The [SQLITE4_INTEGER | datatype] after conversion is returned.)^ ** ** Please pay particular attention to the fact that the pointer returned ** from [sqlite4_value_blob()], [sqlite4_value_text()], or ** [sqlite4_value_text16()] can be invalidated by a subsequent call to ** [sqlite4_value_bytes()], [sqlite4_value_bytes16()], [sqlite4_value_text()], ** or [sqlite4_value_text16()]. ** ** These routines must be called from the same thread as ** the SQL function that supplied the [sqlite4_value*] parameters. */ SQLITE4_API const void *sqlite4_value_blob(sqlite4_value*); SQLITE4_API int sqlite4_value_bytes(sqlite4_value*); SQLITE4_API int sqlite4_value_bytes16(sqlite4_value*); SQLITE4_API double sqlite4_value_double(sqlite4_value*); SQLITE4_API int sqlite4_value_int(sqlite4_value*); SQLITE4_API sqlite4_int64 sqlite4_value_int64(sqlite4_value*); SQLITE4_API const unsigned char *sqlite4_value_text(sqlite4_value*); SQLITE4_API const void *sqlite4_value_text16(sqlite4_value*); SQLITE4_API const void *sqlite4_value_text16le(sqlite4_value*); SQLITE4_API const void *sqlite4_value_text16be(sqlite4_value*); SQLITE4_API int sqlite4_value_type(sqlite4_value*); SQLITE4_API int sqlite4_value_numeric_type(sqlite4_value*); /* ** CAPIREF: Obtain Aggregate Function Context ** ** Implementations of aggregate SQL functions use this ** routine to allocate memory for storing their state. ** ** ^The first time the sqlite4_aggregate_context(C,N) routine is called ** for a particular aggregate function, SQLite ** allocates N of memory, zeroes out that memory, and returns a pointer ** to the new memory. ^On second and subsequent calls to ** sqlite4_aggregate_context() for the same aggregate function instance, ** the same buffer is returned. Sqlite3_aggregate_context() is normally ** called once for each invocation of the xStep callback and then one ** last time when the xFinal callback is invoked. ^(When no rows match ** an aggregate query, the xStep() callback of the aggregate function ** implementation is never called and xFinal() is called exactly once. ** In those cases, sqlite4_aggregate_context() might be called for the ** first time from within xFinal().)^ ** ** ^The sqlite4_aggregate_context(C,N) routine returns a NULL pointer if N is ** less than or equal to zero or if a memory allocate error occurs. ** ** ^(The amount of space allocated by sqlite4_aggregate_context(C,N) is ** determined by the N parameter on first successful call. Changing the ** value of N in subsequent call to sqlite4_aggregate_context() within ** the same aggregate function instance will not resize the memory ** allocation.)^ ** ** ^SQLite automatically frees the memory allocated by ** sqlite4_aggregate_context() when the aggregate query concludes. ** ** The first parameter must be a copy of the ** [sqlite4_context | SQL function context] that is the first parameter ** to the xStep or xFinal callback routine that implements the aggregate ** function. ** ** This routine must be called from the same thread in which ** the aggregate SQL function is running. */ SQLITE4_API void *sqlite4_aggregate_context(sqlite4_context*, int nBytes); /* ** CAPIREF: User Data For Functions ** ** ^The sqlite4_user_data() interface returns a copy of ** the pointer that was the pUserData parameter (the 5th parameter) ** of the [sqlite4_create_function()] ** and [sqlite4_create_function16()] routines that originally ** registered the application defined function. ** ** This routine must be called from the same thread in which ** the application-defined function is running. */ SQLITE4_API void *sqlite4_user_data(sqlite4_context*); /* ** CAPIREF: Database Connection For Functions ** ** ^The sqlite4_context_db_handle() interface returns a copy of ** the pointer to the [database connection] (the 1st parameter) ** of the [sqlite4_create_function()] ** and [sqlite4_create_function16()] routines that originally ** registered the application defined function. */ SQLITE4_API sqlite4 *sqlite4_context_db_handle(sqlite4_context*); SQLITE4_API sqlite4_env *sqlite4_context_env(sqlite4_context*); /* ** CAPIREF: Function Auxiliary Data ** ** The following two functions may be used by scalar SQL functions to ** associate metadata with argument values. If the same value is passed to ** multiple invocations of the same SQL function during query execution, under ** some circumstances the associated metadata may be preserved. This may ** be used, for example, to add a regular-expression matching scalar ** function. The compiled version of the regular expression is stored as ** metadata associated with the SQL value passed as the regular expression ** pattern. The compiled regular expression can be reused on multiple ** invocations of the same function so that the original pattern string ** does not need to be recompiled on each invocation. ** ** ^The sqlite4_get_auxdata() interface returns a pointer to the metadata ** associated by the sqlite4_set_auxdata() function with the Nth argument ** value to the application-defined function. ^If no metadata has been ever ** been set for the Nth argument of the function, or if the corresponding ** function parameter has changed since the meta-data was set, ** then sqlite4_get_auxdata() returns a NULL pointer. ** ** ^The sqlite4_set_auxdata() interface saves the metadata ** pointed to by its 3rd parameter as the metadata for the N-th ** argument of the application-defined function. Subsequent ** calls to sqlite4_get_auxdata() might return this data, if it has ** not been destroyed. ** ^If it is not NULL, SQLite will invoke the destructor ** function given by the 4th parameter to sqlite4_set_auxdata() on ** the metadata when the corresponding function parameter changes ** or when the SQL statement completes, whichever comes first. ** ** SQLite is free to call the destructor and drop metadata on any ** parameter of any function at any time. ^The only guarantee is that ** the destructor will be called before the metadata is dropped. ** ** ^(In practice, metadata is preserved between function calls for ** expressions that are constant at compile time. This includes literal ** values and [parameters].)^ ** ** These routines must be called from the same thread in which ** the SQL function is running. */ SQLITE4_API void *sqlite4_get_auxdata(sqlite4_context*, int N); SQLITE4_API void sqlite4_set_auxdata(sqlite4_context*, int N, void*, void (*)(void*)); /* ** CAPIREF: Constants Defining Special Destructor Behavior ** ** These are special values for the destructor that is passed in as the ** final argument to routines like [sqlite4_result_blob()]. ^If the destructor ** argument is SQLITE4_STATIC, it means that the content pointer is constant ** and will never change. It does not need to be destroyed. ^The ** SQLITE4_TRANSIENT value means that the content will likely change in ** the near future and that SQLite should make its own private copy of ** the content before returning. ** ** The typedef is necessary to work around problems in certain ** C++ compilers. See ticket #2191. */ typedef void (*sqlite4_destructor_type)(void*); SQLITE4_API void sqlite4_dynamic(void*); #define SQLITE4_STATIC ((sqlite4_destructor_type)0) #define SQLITE4_TRANSIENT ((sqlite4_destructor_type)-1) #define SQLITE4_DYNAMIC (sqlite4_dynamic) /* ** CAPIREF: Setting The Result Of An SQL Function ** ** These routines are used by the xFunc or xFinal callbacks that ** implement SQL functions and aggregates. See ** [sqlite4_create_function()] and [sqlite4_create_function16()] ** for additional information. ** ** These functions work very much like the [parameter binding] family of ** functions used to bind values to host parameters in prepared statements. ** Refer to the [SQL parameter] documentation for additional information. ** ** ^The sqlite4_result_blob() interface sets the result from ** an application-defined function to be the BLOB whose content is pointed ** to by the second parameter and which is N bytes long where N is the ** third parameter. ** ** ^The sqlite4_result_zeroblob() interfaces set the result of ** the application-defined function to be a BLOB containing all zero ** bytes and N bytes in size, where N is the value of the 2nd parameter. ** ** ^The sqlite4_result_double() interface sets the result from ** an application-defined function to be a floating point value specified ** by its 2nd argument. ** ** ^The sqlite4_result_error() and sqlite4_result_error16() functions ** cause the implemented SQL function to throw an exception. ** ^SQLite uses the string pointed to by the ** 2nd parameter of sqlite4_result_error() or sqlite4_result_error16() ** as the text of an error message. ^SQLite interprets the error ** message string from sqlite4_result_error() as UTF-8. ^SQLite ** interprets the string from sqlite4_result_error16() as UTF-16 in native ** byte order. ^If the third parameter to sqlite4_result_error() ** or sqlite4_result_error16() is negative then SQLite takes as the error ** message all text up through the first zero character. ** ^If the third parameter to sqlite4_result_error() or ** sqlite4_result_error16() is non-negative then SQLite takes that many ** bytes (not characters) from the 2nd parameter as the error message. ** ^The sqlite4_result_error() and sqlite4_result_error16() ** routines make a private copy of the error message text before ** they return. Hence, the calling function can deallocate or ** modify the text after they return without harm. ** ^The sqlite4_result_error_code() function changes the error code ** returned by SQLite as a result of an error in a function. ^By default, ** the error code is SQLITE4_ERROR. ^A subsequent call to sqlite4_result_error() ** or sqlite4_result_error16() resets the error code to SQLITE4_ERROR. ** ** ^The sqlite4_result_toobig() interface causes SQLite to throw an error ** indicating that a string or BLOB is too long to represent. ** ** ^The sqlite4_result_nomem() interface causes SQLite to throw an error ** indicating that a memory allocation failed. ** ** ^The sqlite4_result_int() interface sets the return value ** of the application-defined function to be the 32-bit signed integer ** value given in the 2nd argument. ** ^The sqlite4_result_int64() interface sets the return value ** of the application-defined function to be the 64-bit signed integer ** value given in the 2nd argument. ** ** ^The sqlite4_result_null() interface sets the return value ** of the application-defined function to be NULL. ** ** ^The sqlite4_result_text(), sqlite4_result_text16(), ** sqlite4_result_text16le(), and sqlite4_result_text16be() interfaces ** set the return value of the application-defined function to be ** a text string which is represented as UTF-8, UTF-16 native byte order, ** UTF-16 little endian, or UTF-16 big endian, respectively. ** ^SQLite takes the text result from the application from ** the 2nd parameter of the sqlite4_result_text* interfaces. ** ^If the 3rd parameter to the sqlite4_result_text* interfaces ** is negative, then SQLite takes result text from the 2nd parameter ** through the first zero character. ** ^If the 3rd parameter to the sqlite4_result_text* interfaces ** is non-negative, then as many bytes (not characters) of the text ** pointed to by the 2nd parameter are taken as the application-defined ** function result. If the 3rd parameter is non-negative, then it ** must be the byte offset into the string where the NUL terminator would ** appear if the string where NUL terminated. If any NUL characters occur ** in the string at a byte offset that is less than the value of the 3rd ** parameter, then the resulting string will contain embedded NULs and the ** result of expressions operating on strings with embedded NULs is undefined. ** ^If the 4th parameter to the sqlite4_result_text* interfaces ** or sqlite4_result_blob is a non-NULL pointer, then SQLite calls that ** function as the destructor on the text or BLOB result when it has ** finished using that result. ** ^If the 4th parameter to the sqlite4_result_text* interfaces or to ** sqlite4_result_blob is the special constant SQLITE4_STATIC, then SQLite ** assumes that the text or BLOB result is in constant space and does not ** copy the content of the parameter nor call a destructor on the content ** when it has finished using that result. ** ^If the 4th parameter to the sqlite4_result_text* interfaces ** or sqlite4_result_blob is the special constant SQLITE4_TRANSIENT ** then SQLite makes a copy of the result into space obtained from ** from [sqlite4_malloc()] before it returns. ** ** ^The sqlite4_result_value() interface sets the result of ** the application-defined function to be a copy the ** [unprotected sqlite4_value] object specified by the 2nd parameter. ^The ** sqlite4_result_value() interface makes a copy of the [sqlite4_value] ** so that the [sqlite4_value] specified in the parameter may change or ** be deallocated after sqlite4_result_value() returns without harm. ** ^A [protected sqlite4_value] object may always be used where an ** [unprotected sqlite4_value] object is required, so either ** kind of [sqlite4_value] object can be used with this interface. ** ** If these routines are called from within the different thread ** than the one containing the application-defined function that received ** the [sqlite4_context] pointer, the results are undefined. */ SQLITE4_API void sqlite4_result_blob(sqlite4_context*, const void*, int, void(*)(void*)); SQLITE4_API void sqlite4_result_double(sqlite4_context*, double); SQLITE4_API void sqlite4_result_error(sqlite4_context*, const char*, int); SQLITE4_API void sqlite4_result_error16(sqlite4_context*, const void*, int); SQLITE4_API void sqlite4_result_error_toobig(sqlite4_context*); SQLITE4_API void sqlite4_result_error_nomem(sqlite4_context*); SQLITE4_API void sqlite4_result_error_code(sqlite4_context*, int); SQLITE4_API void sqlite4_result_int(sqlite4_context*, int); SQLITE4_API void sqlite4_result_int64(sqlite4_context*, sqlite4_int64); SQLITE4_API void sqlite4_result_null(sqlite4_context*); SQLITE4_API void sqlite4_result_text(sqlite4_context*, const char*, int, void(*)(void*)); SQLITE4_API void sqlite4_result_text16(sqlite4_context*, const void*, int, void(*)(void*)); SQLITE4_API void sqlite4_result_text16le(sqlite4_context*, const void*, int,void(*)(void*)); SQLITE4_API void sqlite4_result_text16be(sqlite4_context*, const void*, int,void(*)(void*)); SQLITE4_API void sqlite4_result_value(sqlite4_context*, sqlite4_value*); SQLITE4_API void sqlite4_result_zeroblob(sqlite4_context*, int n); /* ** CAPIREF: Define New Collating Sequences ** ** ^This function adds, removes, or modifies a [collation] associated ** with the [database connection] specified as the first argument. ** ** ^The name of the collation is a UTF-8 string. ** ^Collation names that compare equal according to [sqlite4_strnicmp()] are ** considered to be the same name. ** ** ^(The third argument (eTextRep) must be one of the constants: ** <ul> ** <li> [SQLITE4_UTF8], ** <li> [SQLITE4_UTF16LE], ** <li> [SQLITE4_UTF16BE], ** <li> [SQLITE4_UTF16], or ** <li> [SQLITE4_UTF16_ALIGNED]. ** </ul>)^ ** ^The eTextRep argument determines the encoding of strings passed ** to the collating function callback, xCallback. ** ^The [SQLITE4_UTF16] and [SQLITE4_UTF16_ALIGNED] values for eTextRep ** force strings to be UTF16 with native byte order. ** ^The [SQLITE4_UTF16_ALIGNED] value for eTextRep forces strings to begin ** on an even byte address. ** ** ^The fourth argument, pArg, is an application data pointer that is passed ** through as the first argument to the collating function callback. ** ** ^The fifth argument, xCallback, is a pointer to the comparision function. ** ^The sixth argument, xMakeKey, is a pointer to a function that generates ** a sort key. ** ^Multiple functions can be registered using the same name but ** with different eTextRep parameters and SQLite will use whichever ** function requires the least amount of data transformation. ** ^If the xCallback argument is NULL then the collating function is ** deleted. ^When all collating functions having the same name are deleted, ** that collation is no longer usable. ** ** ^The collating function callback is invoked with a copy of the pArg ** application data pointer and with two strings in the encoding specified ** by the eTextRep argument. The collating function must return an ** integer that is negative, zero, or positive ** if the first string is less than, equal to, or greater than the second, ** respectively. A collating function must always return the same answer ** given the same inputs. If two or more collating functions are registered ** to the same collation name (using different eTextRep values) then all ** must give an equivalent answer when invoked with equivalent strings. ** The collating function must obey the following properties for all ** strings A, B, and C: ** ** <ol> ** <li> If A==B then B==A. ** <li> If A==B and B==C then A==C. ** <li> If A<B THEN B>A. ** <li> If A<B and B<C then A<C. ** </ol> ** ** If a collating function fails any of the above constraints and that ** collating function is registered and used, then the behavior of SQLite ** is undefined. ** ** ^Collating functions are deleted when they are overridden by later ** calls to the collation creation functions or when the ** [database connection] is closed using [sqlite4_close()]. ** ** ^The xDestroy callback is <u>not</u> called if the ** sqlite4_create_collation() function fails. Applications that invoke ** sqlite4_create_collation() with a non-NULL xDestroy argument should ** check the return code and dispose of the application data pointer ** themselves rather than expecting SQLite to deal with it for them. ** This is different from every other SQLite interface. The inconsistency ** is unfortunate but cannot be changed without breaking backwards ** compatibility. ** ** See also: [sqlite4_collation_needed()] and [sqlite4_collation_needed16()]. */ SQLITE4_API int sqlite4_create_collation( sqlite4*, const char *zName, int eTextRep, void *pArg, int(*xCompare)(void*,int,const void*,int,const void*), int(*xMakeKey)(void*,int,const void*,int,void*), void(*xDestroy)(void*) ); /* ** CAPIREF: Collation Needed Callbacks ** ** ^To avoid having to register all collation sequences before a database ** can be used, a single callback function may be registered with the ** [database connection] to be invoked whenever an undefined collation ** sequence is required. ** ** ^If the function is registered using the sqlite4_collation_needed() API, ** then it is passed the names of undefined collation sequences as strings ** encoded in UTF-8. ^If sqlite4_collation_needed16() is used, ** the names are passed as UTF-16 in machine native byte order. ** ^A call to either function replaces the existing collation-needed callback. ** ** ^(When the callback is invoked, the first argument passed is a copy ** of the second argument to sqlite4_collation_needed() or ** sqlite4_collation_needed16(). The second argument is the database ** connection. The third argument is one of [SQLITE4_UTF8], [SQLITE4_UTF16BE], ** or [SQLITE4_UTF16LE], indicating the most desirable form of the collation ** sequence function required. The fourth parameter is the name of the ** required collation sequence.)^ ** ** The callback function should register the desired collation using ** [sqlite4_create_collation()], [sqlite4_create_collation16()], or ** [sqlite4_create_collation_v2()]. */ SQLITE4_API int sqlite4_collation_needed( sqlite4*, void*, void(*)(void*,sqlite4*,int eTextRep,const char*) ); SQLITE4_API int sqlite4_collation_needed16( sqlite4*, void*, void(*)(void*,sqlite4*,int eTextRep,const void*) ); /* ** CAPIREF: Suspend Execution For A Short Time ** ** The sqlite4_sleep() function causes the current thread to suspend execution ** for at least a number of milliseconds specified in its parameter. ** ** If the operating system does not support sleep requests with ** millisecond time resolution, then the time will be rounded up to ** the nearest second. The number of milliseconds of sleep actually ** requested from the operating system is returned. ** ** ^SQLite implements this interface by calling the xSleep() ** method of the default [sqlite4_vfs] object. If the xSleep() method ** of the default VFS is not implemented correctly, or not implemented at ** all, then the behavior of sqlite4_sleep() may deviate from the description ** in the previous paragraphs. */ SQLITE4_API int sqlite4_sleep(int); /* ** CAPIREF: Test For Auto-Commit Mode ** KEYWORDS: {autocommit mode} ** ** ^The sqlite4_get_autocommit() interface returns non-zero or ** zero if the given database connection is or is not in autocommit mode, ** respectively. ^Autocommit mode is on by default. ** ^Autocommit mode is disabled by a [BEGIN] statement. ** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK]. ** ** If certain kinds of errors occur on a statement within a multi-statement ** transaction (errors including [SQLITE4_FULL], [SQLITE4_IOERR], ** [SQLITE4_NOMEM], [SQLITE4_BUSY], and [SQLITE4_INTERRUPT]) then the ** transaction might be rolled back automatically. The only way to ** find out whether SQLite automatically rolled back the transaction after ** an error is to use this function. ** ** If another thread changes the autocommit status of the database ** connection while this routine is running, then the return value ** is undefined. */ SQLITE4_API int sqlite4_get_autocommit(sqlite4*); /* ** CAPIREF: Find The Database Handle Of A Prepared Statement ** ** ^The sqlite4_db_handle interface returns the [database connection] handle ** to which a [prepared statement] belongs. ^The [database connection] ** returned by sqlite4_db_handle is the same [database connection] ** that was the first argument ** to the [sqlite4_prepare()] call (or its variants) that was used to ** create the statement in the first place. */ SQLITE4_API sqlite4 *sqlite4_db_handle(sqlite4_stmt*); /* ** CAPIREF: Return The Filename For A Database Connection ** ** ^The sqlite4_db_filename(D,N) interface returns a pointer to a filename ** associated with database N of connection D. ^The main database file ** has the name "main". If there is no attached database N on the database ** connection D, or if database N is a temporary or in-memory database, then ** a NULL pointer is returned. ** ** ^The filename returned by this function is the output of the ** xFullPathname method of the [VFS]. ^In other words, the filename ** will be an absolute pathname, even if the filename used ** to open the database originally was a URI or relative pathname. */ SQLITE4_API const char *sqlite4_db_filename(sqlite4 *db, const char *zDbName); /* ** CAPIREF: Find the next prepared statement ** ** ^This interface returns a pointer to the next [prepared statement] after ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL ** then this interface returns a pointer to the first prepared statement ** associated with the database connection pDb. ^If no prepared statement ** satisfies the conditions of this routine, it returns NULL. ** ** The [database connection] pointer D in a call to ** [sqlite4_next_stmt(D,S)] must refer to an open database ** connection and in particular must not be a NULL pointer. */ SQLITE4_API sqlite4_stmt *sqlite4_next_stmt(sqlite4 *pDb, sqlite4_stmt *pStmt); /* ** CAPIREF: Free Memory Used By A Database Connection ** ** ^The sqlite4_db_release_memory(D) interface attempts to free as much heap ** memory as possible from database connection D. */ SQLITE4_API int sqlite4_db_release_memory(sqlite4*); /* ** CAPIREF: Extract Metadata About A Column Of A Table ** ** ^This routine returns metadata about a specific column of a specific ** database table accessible using the [database connection] handle ** passed as the first function argument. ** ** ^The column is identified by the second, third and fourth parameters to ** this function. ^The second parameter is either the name of the database ** (i.e. "main", "temp", or an attached database) containing the specified ** table or NULL. ^If it is NULL, then all attached databases are searched ** for the table using the same algorithm used by the database engine to ** resolve unqualified table references. ** ** ^The third and fourth parameters to this function are the table and column ** name of the desired column, respectively. Neither of these parameters ** may be NULL. ** ** ^Metadata is returned by writing to the memory locations passed as the 5th ** and subsequent parameters to this function. ^Any of these arguments may be ** NULL, in which case the corresponding element of metadata is omitted. ** ** ^(<blockquote> ** <table border="1"> ** <tr><th> Parameter <th> Output<br>Type <th> Description ** ** <tr><td> 5th <td> const char* <td> Data type ** <tr><td> 6th <td> const char* <td> Name of default collation sequence ** <tr><td> 7th <td> int <td> True if column has a NOT NULL constraint ** <tr><td> 8th <td> int <td> True if column is part of the PRIMARY KEY ** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT] ** </table> ** </blockquote>)^ ** ** ^The memory pointed to by the character pointers returned for the ** declaration type and collation sequence is valid only until the next ** call to any SQLite API function. ** ** ^If the specified table is actually a view, an [error code] is returned. ** ** ^If the specified column is "rowid", "oid" or "_rowid_" and an ** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output ** parameters are set for the explicitly declared column. ^(If there is no ** explicitly declared [INTEGER PRIMARY KEY] column, then the output ** parameters are set as follows: ** ** <pre> ** data type: "INTEGER" ** collation sequence: "BINARY" ** not null: 0 ** primary key: 1 ** auto increment: 0 ** </pre>)^ ** ** ^(This function may load one or more schemas from database files. If an ** error occurs during this process, or if the requested table or column ** cannot be found, an [error code] is returned and an error message left ** in the [database connection] (to be retrieved using sqlite4_errmsg()).)^ ** ** ^This API is only available if the library was compiled with the ** [SQLITE4_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined. */ SQLITE4_API int sqlite4_table_column_metadata( sqlite4 *db, /* Connection handle */ const char *zDbName, /* Database name or NULL */ const char *zTableName, /* Table name */ const char *zColumnName, /* Column name */ char const **pzDataType, /* OUTPUT: Declared data type */ char const **pzCollSeq, /* OUTPUT: Collation sequence name */ int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */ int *pPrimaryKey, /* OUTPUT: True if column part of PK */ int *pAutoinc /* OUTPUT: True if column is auto-increment */ ); /* ** CAPIREF: Load An Extension ** ** ^This interface loads an SQLite extension library from the named file. ** ** ^The sqlite4_load_extension() interface attempts to load an ** SQLite extension library contained in the file zFile. ** ** ^The entry point is zProc. ** ^zProc may be 0, in which case the name of the entry point ** defaults to "sqlite4_extension_init". ** ^The sqlite4_load_extension() interface returns ** [SQLITE4_OK] on success and [SQLITE4_ERROR] if something goes wrong. ** ^If an error occurs and pzErrMsg is not 0, then the ** [sqlite4_load_extension()] interface shall attempt to ** fill *pzErrMsg with error message text stored in memory ** obtained from [sqlite4_malloc()]. The calling function ** should free this memory by calling [sqlite4_free()]. ** ** ^Extension loading must be enabled using ** [sqlite4_enable_load_extension()] prior to calling this API, ** otherwise an error will be returned. ** ** See also the [load_extension() SQL function]. */ SQLITE4_API int sqlite4_load_extension( sqlite4 *db, /* Load the extension into this database connection */ const char *zFile, /* Name of the shared library containing extension */ const char *zProc, /* Entry point. Derived from zFile if 0 */ char **pzErrMsg /* Put error message here if not 0 */ ); /* ** CAPIREF: Enable Or Disable Extension Loading ** ** ^So as not to open security holes in older applications that are ** unprepared to deal with extension loading, and as a means of disabling ** extension loading while evaluating user-entered SQL, the following API ** is provided to turn the [sqlite4_load_extension()] mechanism on and off. ** ** ^Extension loading is off by default. See ticket #1863. ** ^Call the sqlite4_enable_load_extension() routine with onoff==1 ** to turn extension loading on and call it with onoff==0 to turn ** it back off again. */ SQLITE4_API int sqlite4_enable_load_extension(sqlite4 *db, int onoff); /* ** The interface to the virtual-table mechanism is currently considered ** to be experimental. The interface might change in incompatible ways. ** If this is a problem for you, do not use the interface at this time. ** ** When the virtual-table mechanism stabilizes, we will declare the ** interface fixed, support it indefinitely, and remove this comment. */ /* ** Structures used by the virtual table interface */ typedef struct sqlite4_vtab sqlite4_vtab; typedef struct sqlite4_index_info sqlite4_index_info; typedef struct sqlite4_vtab_cursor sqlite4_vtab_cursor; typedef struct sqlite4_module sqlite4_module; /* ** CAPIREF: Virtual Table Object ** KEYWORDS: sqlite4_module {virtual table module} ** ** This structure, sometimes called a "virtual table module", ** defines the implementation of a [virtual tables]. ** This structure consists mostly of methods for the module. ** ** ^A virtual table module is created by filling in a persistent ** instance of this structure and passing a pointer to that instance ** to [sqlite4_create_module()] or [sqlite4_create_module_v2()]. ** ^The registration remains valid until it is replaced by a different ** module or until the [database connection] closes. The content ** of this structure must not change while it is registered with ** any database connection. */ struct sqlite4_module { int iVersion; int (*xCreate)(sqlite4*, void *pAux, int argc, const char *const*argv, sqlite4_vtab **ppVTab, char**); int (*xConnect)(sqlite4*, void *pAux, int argc, const char *const*argv, sqlite4_vtab **ppVTab, char**); int (*xBestIndex)(sqlite4_vtab *pVTab, sqlite4_index_info*); int (*xDisconnect)(sqlite4_vtab *pVTab); int (*xDestroy)(sqlite4_vtab *pVTab); int (*xOpen)(sqlite4_vtab *pVTab, sqlite4_vtab_cursor **ppCursor); int (*xClose)(sqlite4_vtab_cursor*); int (*xFilter)(sqlite4_vtab_cursor*, int idxNum, const char *idxStr, int argc, sqlite4_value **argv); int (*xNext)(sqlite4_vtab_cursor*); int (*xEof)(sqlite4_vtab_cursor*); int (*xColumn)(sqlite4_vtab_cursor*, sqlite4_context*, int); int (*xRowid)(sqlite4_vtab_cursor*, sqlite4_int64 *pRowid); int (*xUpdate)(sqlite4_vtab *, int, sqlite4_value **, sqlite4_int64 *); int (*xBegin)(sqlite4_vtab *pVTab); int (*xSync)(sqlite4_vtab *pVTab); int (*xCommit)(sqlite4_vtab *pVTab); int (*xRollback)(sqlite4_vtab *pVTab); int (*xFindFunction)(sqlite4_vtab *pVtab, int nArg, const char *zName, void (**pxFunc)(sqlite4_context*,int,sqlite4_value**), void **ppArg); int (*xRename)(sqlite4_vtab *pVtab, const char *zNew); /* The methods above are in version 1 of the sqlite_module object. Those ** below are for version 2 and greater. */ int (*xSavepoint)(sqlite4_vtab *pVTab, int); int (*xRelease)(sqlite4_vtab *pVTab, int); int (*xRollbackTo)(sqlite4_vtab *pVTab, int); }; /* ** CAPIREF: Virtual Table Indexing Information ** KEYWORDS: sqlite4_index_info ** ** The sqlite4_index_info structure and its substructures is used as part ** of the [virtual table] interface to ** pass information into and receive the reply from the [xBestIndex] ** method of a [virtual table module]. The fields under **Inputs** are the ** inputs to xBestIndex and are read-only. xBestIndex inserts its ** results into the **Outputs** fields. ** ** ^(The aConstraint[] array records WHERE clause constraints of the form: ** ** <blockquote>column OP expr</blockquote> ** ** where OP is =, <, <=, >, or >=.)^ ^(The particular operator is ** stored in aConstraint[].op using one of the ** [SQLITE4_INDEX_CONSTRAINT_EQ | SQLITE4_INDEX_CONSTRAINT_ values].)^ ** ^(The index of the column is stored in ** aConstraint[].iColumn.)^ ^(aConstraint[].usable is TRUE if the ** expr on the right-hand side can be evaluated (and thus the constraint ** is usable) and false if it cannot.)^ ** ** ^The optimizer automatically inverts terms of the form "expr OP column" ** and makes other simplifications to the WHERE clause in an attempt to ** get as many WHERE clause terms into the form shown above as possible. ** ^The aConstraint[] array only reports WHERE clause terms that are ** relevant to the particular virtual table being queried. ** ** ^Information about the ORDER BY clause is stored in aOrderBy[]. ** ^Each term of aOrderBy records a column of the ORDER BY clause. ** ** The [xBestIndex] method must fill aConstraintUsage[] with information ** about what parameters to pass to xFilter. ^If argvIndex>0 then ** the right-hand side of the corresponding aConstraint[] is evaluated ** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit ** is true, then the constraint is assumed to be fully handled by the ** virtual table and is not checked again by SQLite.)^ ** ** ^The idxNum and idxPtr values are recorded and passed into the ** [xFilter] method. ** ^[sqlite4_free()] is used to free idxPtr if and only if ** needToFreeIdxPtr is true. ** ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in ** the correct order to satisfy the ORDER BY clause so that no separate ** sorting step is required. ** ** ^The estimatedCost value is an estimate of the cost of doing the ** particular lookup. A full scan of a table with N entries should have ** a cost of N. A binary search of a table of N entries should have a ** cost of approximately log(N). */ struct sqlite4_index_info { /* Inputs */ int nConstraint; /* Number of entries in aConstraint */ struct sqlite4_index_constraint { int iColumn; /* Column on left-hand side of constraint */ unsigned char op; /* Constraint operator */ unsigned char usable; /* True if this constraint is usable */ int iTermOffset; /* Used internally - xBestIndex should ignore */ } *aConstraint; /* Table of WHERE clause constraints */ int nOrderBy; /* Number of terms in the ORDER BY clause */ struct sqlite4_index_orderby { int iColumn; /* Column number */ unsigned char desc; /* True for DESC. False for ASC. */ } *aOrderBy; /* The ORDER BY clause */ /* Outputs */ struct sqlite4_index_constraint_usage { int argvIndex; /* if >0, constraint is part of argv to xFilter */ unsigned char omit; /* Do not code a test for this constraint */ } *aConstraintUsage; int idxNum; /* Number used to identify the index */ char *idxStr; /* String, possibly obtained from sqlite4_malloc */ int needToFreeIdxStr; /* Free idxStr using sqlite4_free() if true */ int orderByConsumed; /* True if output is already ordered */ double estimatedCost; /* Estimated cost of using this index */ }; /* ** CAPIREF: Virtual Table Constraint Operator Codes ** ** These macros defined the allowed values for the ** [sqlite4_index_info].aConstraint[].op field. Each value represents ** an operator that is part of a constraint term in the wHERE clause of ** a query that uses a [virtual table]. */ #define SQLITE4_INDEX_CONSTRAINT_EQ 2 #define SQLITE4_INDEX_CONSTRAINT_GT 4 #define SQLITE4_INDEX_CONSTRAINT_LE 8 #define SQLITE4_INDEX_CONSTRAINT_LT 16 #define SQLITE4_INDEX_CONSTRAINT_GE 32 #define SQLITE4_INDEX_CONSTRAINT_MATCH 64 /* ** CAPIREF: Register A Virtual Table Implementation ** ** ^These routines are used to register a new [virtual table module] name. ** ^Module names must be registered before ** creating a new [virtual table] using the module and before using a ** preexisting [virtual table] for the module. ** ** ^The module name is registered on the [database connection] specified ** by the first parameter. ^The name of the module is given by the ** second parameter. ^The third parameter is a pointer to ** the implementation of the [virtual table module]. ^The fourth ** parameter is an arbitrary client data pointer that is passed through ** into the [xCreate] and [xConnect] methods of the virtual table module ** when a new virtual table is be being created or reinitialized. ** ** ^The sqlite4_create_module_v2() interface has a fifth parameter which ** is a pointer to a destructor for the pClientData. ^SQLite will ** invoke the destructor function (if it is not NULL) when SQLite ** no longer needs the pClientData pointer. ^The destructor will also ** be invoked if the call to sqlite4_create_module_v2() fails. ** ^The sqlite4_create_module() ** interface is equivalent to sqlite4_create_module_v2() with a NULL ** destructor. */ SQLITE4_API int sqlite4_create_module( sqlite4 *db, /* SQLite connection to register module with */ const char *zName, /* Name of the module */ const sqlite4_module *p, /* Methods for the module */ void *pClientData /* Client data for xCreate/xConnect */ ); SQLITE4_API int sqlite4_create_module_v2( sqlite4 *db, /* SQLite connection to register module with */ const char *zName, /* Name of the module */ const sqlite4_module *p, /* Methods for the module */ void *pClientData, /* Client data for xCreate/xConnect */ void(*xDestroy)(void*) /* Module destructor function */ ); /* ** CAPIREF: Virtual Table Instance Object ** KEYWORDS: sqlite4_vtab ** ** Every [virtual table module] implementation uses a subclass ** of this object to describe a particular instance ** of the [virtual table]. Each subclass will ** be tailored to the specific needs of the module implementation. ** The purpose of this superclass is to define certain fields that are ** common to all module implementations. ** ** ^Virtual tables methods can set an error message by assigning a ** string obtained from [sqlite4_mprintf()] to zErrMsg. The method should ** take care that any prior string is freed by a call to [sqlite4_free()] ** prior to assigning a new string to zErrMsg. ^After the error message ** is delivered up to the client application, the string will be automatically ** freed by sqlite4_free() and the zErrMsg field will be zeroed. */ struct sqlite4_vtab { const sqlite4_module *pModule; /* The module for this virtual table */ int nRef; /* NO LONGER USED */ char *zErrMsg; /* Error message from sqlite4_mprintf() */ /* Virtual table implementations will typically add additional fields */ }; /* ** CAPIREF: Virtual Table Cursor Object ** KEYWORDS: sqlite4_vtab_cursor {virtual table cursor} ** ** Every [virtual table module] implementation uses a subclass of the ** following structure to describe cursors that point into the ** [virtual table] and are used ** to loop through the virtual table. Cursors are created using the ** [sqlite4_module.xOpen | xOpen] method of the module and are destroyed ** by the [sqlite4_module.xClose | xClose] method. Cursors are used ** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods ** of the module. Each module implementation will define ** the content of a cursor structure to suit its own needs. ** ** This superclass exists in order to define fields of the cursor that ** are common to all implementations. */ struct sqlite4_vtab_cursor { sqlite4_vtab *pVtab; /* Virtual table of this cursor */ /* Virtual table implementations will typically add additional fields */ }; /* ** CAPIREF: Declare The Schema Of A Virtual Table ** ** ^The [xCreate] and [xConnect] methods of a ** [virtual table module] call this interface ** to declare the format (the names and datatypes of the columns) of ** the virtual tables they implement. */ SQLITE4_API int sqlite4_declare_vtab(sqlite4*, const char *zSQL); /* ** CAPIREF: Overload A Function For A Virtual Table ** ** ^(Virtual tables can provide alternative implementations of functions ** using the [xFindFunction] method of the [virtual table module]. ** But global versions of those functions ** must exist in order to be overloaded.)^ ** ** ^(This API makes sure a global version of a function with a particular ** name and number of parameters exists. If no such function exists ** before this API is called, a new function is created.)^ ^The implementation ** of the new function always causes an exception to be thrown. So ** the new function is not good for anything by itself. Its only ** purpose is to be a placeholder function that can be overloaded ** by a [virtual table]. */ SQLITE4_API int sqlite4_overload_function(sqlite4*, const char *zFuncName, int nArg); /* ** CAPIREF: Mutexes ** ** The SQLite core uses these routines for thread ** synchronization. Though they are intended for internal ** use by SQLite, code that links against SQLite is ** permitted to use any of these routines. ** ** The SQLite source code contains multiple implementations ** of these mutex routines. An appropriate implementation ** is selected automatically at compile-time. ^(The following ** implementations are available in the SQLite core: ** ** <ul> ** <li> SQLITE4_MUTEX_PTHREADS ** <li> SQLITE4_MUTEX_W32 ** <li> SQLITE4_MUTEX_NOOP ** </ul>)^ ** ** ^The SQLITE4_MUTEX_NOOP implementation is a set of routines ** that does no real locking and is appropriate for use in ** a single-threaded application. ^The SQLITE4_MUTEX_PTHREADS ** and SQLITE4_MUTEX_W32 implementations ** are appropriate for use on Unix and Windows. ** ** ^(If SQLite is compiled with the SQLITE4_MUTEX_APPDEF preprocessor ** macro defined (with "-DSQLITE4_MUTEX_APPDEF=1"), then no mutex ** implementation is included with the library. In this case the ** application must supply a custom mutex implementation using the ** [SQLITE4_CONFIG_MUTEX] option of the sqlite4_env_config() function ** before calling sqlite4_initialize() or any other public sqlite4_ ** function that calls sqlite4_initialize().)^ ** ** ^The sqlite4_mutex_alloc() routine allocates a new ** mutex and returns a pointer to it. ^If it returns NULL ** that means that a mutex could not be allocated. ^SQLite ** will unwind its stack and return an error. ^(The argument ** to sqlite4_mutex_alloc() is one of these integer constants: ** ** <ul> ** <li> SQLITE4_MUTEX_FAST ** <li> SQLITE4_MUTEX_RECURSIVE ** </ul>)^ ** ** ^The new mutex is recursive when SQLITE4_MUTEX_RECURSIVE ** is used but not necessarily so when SQLITE4_MUTEX_FAST is used. ** The mutex implementation does not need to make a distinction ** between SQLITE4_MUTEX_RECURSIVE and SQLITE4_MUTEX_FAST if it does ** not want to. ^SQLite will only request a recursive mutex in ** cases where it really needs one. ^If a faster non-recursive mutex ** implementation is available on the host platform, the mutex subsystem ** might return such a mutex in response to SQLITE4_MUTEX_FAST. ** ** ^The sqlite4_mutex_free() routine deallocates a previously ** allocated mutex. ** ** ^The sqlite4_mutex_enter() and sqlite4_mutex_try() routines attempt ** to enter a mutex. ^If another thread is already within the mutex, ** sqlite4_mutex_enter() will block and sqlite4_mutex_try() will return ** SQLITE4_BUSY. ^The sqlite4_mutex_try() interface returns [SQLITE4_OK] ** upon successful entry. ^(Mutexes created using ** SQLITE4_MUTEX_RECURSIVE can be entered multiple times by the same thread. ** In such cases the, ** mutex must be exited an equal number of times before another thread ** can enter.)^ ^(If the same thread tries to enter any other ** kind of mutex more than once, the behavior is undefined. ** SQLite will never exhibit ** such behavior in its own use of mutexes.)^ ** ** ^(Some systems (for example, Windows 95) do not support the operation ** implemented by sqlite4_mutex_try(). On those systems, sqlite4_mutex_try() ** will always return SQLITE4_BUSY. The SQLite core only ever uses ** sqlite4_mutex_try() as an optimization so this is acceptable behavior.)^ ** ** ^The sqlite4_mutex_leave() routine exits a mutex that was ** previously entered by the same thread. ^(The behavior ** is undefined if the mutex is not currently entered by the ** calling thread or is not currently allocated. SQLite will ** never do either.)^ ** ** ^If the argument to sqlite4_mutex_enter(), sqlite4_mutex_try(), or ** sqlite4_mutex_leave() is a NULL pointer, then all three routines ** behave as no-ops. ** ** See also: [sqlite4_mutex_held()] and [sqlite4_mutex_notheld()]. */ SQLITE4_API sqlite4_mutex *sqlite4_mutex_alloc(sqlite4_env*, int); SQLITE4_API void sqlite4_mutex_free(sqlite4_mutex*); SQLITE4_API void sqlite4_mutex_enter(sqlite4_mutex*); SQLITE4_API int sqlite4_mutex_try(sqlite4_mutex*); SQLITE4_API void sqlite4_mutex_leave(sqlite4_mutex*); /* ** CAPIREF: Mutex Methods Object ** ** An instance of this structure defines the low-level routines ** used to allocate and use mutexes. ** ** Usually, the default mutex implementations provided by SQLite are ** sufficient, however the user has the option of substituting a custom ** implementation for specialized deployments or systems for which SQLite ** does not provide a suitable implementation. In this case, the user ** creates and populates an instance of this structure to pass ** to sqlite4_env_config() along with the [SQLITE4_CONFIG_MUTEX] option. ** Additionally, an instance of this structure can be used as an ** output variable when querying the system for the current mutex ** implementation, using the [SQLITE4_CONFIG_GETMUTEX] option. ** ** ^The xMutexInit method defined by this structure is invoked as ** part of system initialization by the sqlite4_initialize() function. ** ^The xMutexInit routine is called by SQLite exactly once for each ** effective call to [sqlite4_initialize()]. ** ** ^The xMutexEnd method defined by this structure is invoked as ** part of system shutdown by the sqlite4_shutdown() function. The ** implementation of this method is expected to release all outstanding ** resources obtained by the mutex methods implementation, especially ** those obtained by the xMutexInit method. ^The xMutexEnd() ** interface is invoked exactly once for each call to [sqlite4_shutdown()]. ** ** ^(The remaining seven methods defined by this structure (xMutexAlloc, ** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and ** xMutexNotheld) implement the following interfaces (respectively): ** ** <ul> ** <li> [sqlite4_mutex_alloc()] </li> ** <li> [sqlite4_mutex_free()] </li> ** <li> [sqlite4_mutex_enter()] </li> ** <li> [sqlite4_mutex_try()] </li> ** <li> [sqlite4_mutex_leave()] </li> ** <li> [sqlite4_mutex_held()] </li> ** <li> [sqlite4_mutex_notheld()] </li> ** </ul>)^ ** ** The only difference is that the public sqlite4_XXX functions enumerated ** above silently ignore any invocations that pass a NULL pointer instead ** of a valid mutex handle. The implementations of the methods defined ** by this structure are not required to handle this case, the results ** of passing a NULL pointer instead of a valid mutex handle are undefined ** (i.e. it is acceptable to provide an implementation that segfaults if ** it is passed a NULL pointer). ** ** The xMutexInit() method must be threadsafe. ^It must be harmless to ** invoke xMutexInit() multiple times within the same process and without ** intervening calls to xMutexEnd(). Second and subsequent calls to ** xMutexInit() must be no-ops. ** ** ^xMutexInit() must not use SQLite memory allocation ([sqlite4_malloc()] ** and its associates). ^Similarly, xMutexAlloc() must not use SQLite memory ** allocation for a static mutex. ^However xMutexAlloc() may use SQLite ** memory allocation for a fast or recursive mutex. ** ** ^SQLite will invoke the xMutexEnd() method when [sqlite4_shutdown()] is ** called, but only if the prior call to xMutexInit returned SQLITE4_OK. ** If xMutexInit fails in any way, it is expected to clean up after itself ** prior to returning. */ typedef struct sqlite4_mutex_methods sqlite4_mutex_methods; struct sqlite4_mutex_methods { int (*xMutexInit)(void*); int (*xMutexEnd)(void*); sqlite4_mutex *(*xMutexAlloc)(void*,int); void (*xMutexFree)(sqlite4_mutex *); void (*xMutexEnter)(sqlite4_mutex *); int (*xMutexTry)(sqlite4_mutex *); void (*xMutexLeave)(sqlite4_mutex *); int (*xMutexHeld)(sqlite4_mutex *); int (*xMutexNotheld)(sqlite4_mutex *); void *pMutexEnv; }; /* ** CAPIREF: Mutex Verification Routines ** ** The sqlite4_mutex_held() and sqlite4_mutex_notheld() routines ** are intended for use inside assert() statements. ^The SQLite core ** never uses these routines except inside an assert() and applications ** are advised to follow the lead of the core. ^The SQLite core only ** provides implementations for these routines when it is compiled ** with the SQLITE4_DEBUG flag. ^External mutex implementations ** are only required to provide these routines if SQLITE4_DEBUG is ** defined and if NDEBUG is not defined. ** ** ^These routines should return true if the mutex in their argument ** is held or not held, respectively, by the calling thread. ** ** ^The implementation is not required to provide versions of these ** routines that actually work. If the implementation does not provide working ** versions of these routines, it should at least provide stubs that always ** return true so that one does not get spurious assertion failures. ** ** ^If the argument to sqlite4_mutex_held() is a NULL pointer then ** the routine should return 1. This seems counter-intuitive since ** clearly the mutex cannot be held if it does not exist. But ** the reason the mutex does not exist is because the build is not ** using mutexes. And we do not want the assert() containing the ** call to sqlite4_mutex_held() to fail, so a non-zero return is ** the appropriate thing to do. ^The sqlite4_mutex_notheld() ** interface should also return 1 when given a NULL pointer. */ #ifndef NDEBUG SQLITE4_API int sqlite4_mutex_held(sqlite4_mutex*); SQLITE4_API int sqlite4_mutex_notheld(sqlite4_mutex*); #endif /* ** CAPIREF: Mutex Types ** ** The [sqlite4_mutex_alloc()] interface takes a single argument ** which is one of these integer constants. ** ** The set of static mutexes may change from one SQLite release to the ** next. Applications that override the built-in mutex logic must be ** prepared to accommodate additional static mutexes. */ #define SQLITE4_MUTEX_FAST 0 #define SQLITE4_MUTEX_RECURSIVE 1 /* ** CAPIREF: Retrieve the mutex for a database connection ** ** ^This interface returns a pointer the [sqlite4_mutex] object that ** serializes access to the [database connection] given in the argument ** when the [threading mode] is Serialized. ** ^If the [threading mode] is Single-thread or Multi-thread then this ** routine returns a NULL pointer. */ SQLITE4_API sqlite4_mutex *sqlite4_db_mutex(sqlite4*); /* ** CAPIREF: Low-Level Control Of Database Backends ** ** ^The [sqlite4_kvstore_control()] interface makes a direct call to the ** xControl method of the key-value store associated with the particular ** database identified by the second argument. ^The name of the database ** is "main" for the main database or "temp" for the TEMP database, or the ** name that appears after the AS keyword for databases that were added ** using the [ATTACH] SQL command. ^A NULL pointer can be used in place ** of "main" to refer to the main database file. ** ** ^The third and fourth parameters to this routine are passed directly ** through to the second and third parameters of the ** sqlite4_kv_methods.xControl method. ^The return value of the xControl ** call becomes the return value of this routine. ** ** ^If the second parameter (zDbName) does not match the name of any ** open database file, then SQLITE4_ERROR is returned. ^This error ** code is not remembered and will not be recalled by [sqlite4_errcode()] ** or [sqlite4_errmsg()]. The underlying xControl method might also return ** SQLITE4_ERROR. There is no way to distinguish between an incorrect zDbName ** and an SQLITE4_ERROR return from the underlying xControl method. */ SQLITE4_API int sqlite4_kvstore_control(sqlite4*, const char *zDbName, int op, void*); /* ** <dl> ** <dt>SQLITE4_KVCTRL_LSM_HANDLE</dt><dd> ** ** <dt>SQLITE4_KVCTRL_SYNCHRONOUS</dt><dd> ** This op is used to configure or query the synchronous level of the ** database backend (either OFF, NORMAL or FULL). The fourth parameter passed ** to kvstore_control should be of type (int *). Call the value that the ** parameter points to N. If N is initially 0, 1 or 2, then the database ** backend should attempt to change the synchronous level to OFF, NORMAL ** or FULL, respectively. Regardless of its initial value, N is set to ** the current (possibly updated) synchronous level before returning ( ** 0, 1 or 2). */ #define SQLITE4_KVCTRL_LSM_HANDLE 1 #define SQLITE4_KVCTRL_SYNCHRONOUS 2 #define SQLITE4_KVCTRL_LSM_FLUSH 3 #define SQLITE4_KVCTRL_LSM_MERGE 4 #define SQLITE4_KVCTRL_LSM_CHECKPOINT 5 /* ** CAPIREF: Testing Interface ** ** ^The sqlite4_test_control() interface is used to read out internal ** state of SQLite and to inject faults into SQLite for testing ** purposes. ^The first parameter is an operation code that determines ** the number, meaning, and operation of all subsequent parameters. ** ** This interface is not for use by applications. It exists solely ** for verifying the correct operation of the SQLite library. Depending ** on how the SQLite library is compiled, this interface might not exist. ** ** The details of the operation codes, their meanings, the parameters ** they take, and what they do are all subject to change without notice. ** Unlike most of the SQLite API, this function is not guaranteed to ** operate consistently from one release to the next. */ SQLITE4_API int sqlite4_test_control(int op, ...); /* ** CAPIREF: Testing Interface Operation Codes ** ** These constants are the valid operation code parameters used ** as the first argument to [sqlite4_test_control()]. ** ** These parameters and their meanings are subject to change ** without notice. These values are for testing purposes only. ** Applications should not use any of these parameters or the ** [sqlite4_test_control()] interface. */ #define SQLITE4_TESTCTRL_FIRST 1 #define SQLITE4_TESTCTRL_FAULT_INSTALL 2 #define SQLITE4_TESTCTRL_ASSERT 3 #define SQLITE4_TESTCTRL_ALWAYS 4 #define SQLITE4_TESTCTRL_RESERVE 5 #define SQLITE4_TESTCTRL_OPTIMIZATIONS 6 #define SQLITE4_TESTCTRL_ISKEYWORD 7 #define SQLITE4_TESTCTRL_LOCALTIME_FAULT 8 #define SQLITE4_TESTCTRL_EXPLAIN_STMT 9 #define SQLITE4_TESTCTRL_LAST 9 /* ** CAPIREF: SQLite Runtime Status ** ** ^This interface is used to retrieve runtime status information ** about the performance of SQLite, and optionally to reset various ** highwater marks. ^The first argument is an integer code for ** the specific parameter to measure. ^(Recognized integer codes ** are of the form [status parameters | SQLITE4_STATUS_...].)^ ** ^The current value of the parameter is returned into *pCurrent. ** ^The highest recorded value is returned in *pHighwater. ^If the ** resetFlag is true, then the highest record value is reset after ** *pHighwater is written. ^(Some parameters do not record the highest ** value. For those parameters ** nothing is written into *pHighwater and the resetFlag is ignored.)^ ** ^(Other parameters record only the highwater mark and not the current ** value. For these latter parameters nothing is written into *pCurrent.)^ ** ** ^The sqlite4_status() routine returns SQLITE4_OK on success and a ** non-zero [error code] on failure. ** ** This routine is threadsafe but is not atomic. This routine can be ** called while other threads are running the same or different SQLite ** interfaces. However the values returned in *pCurrent and ** *pHighwater reflect the status of SQLite at different points in time ** and it is possible that another thread might change the parameter ** in between the times when *pCurrent and *pHighwater are written. ** ** See also: [sqlite4_db_status()] */ SQLITE4_API int sqlite4_env_status( sqlite4_env *pEnv, int op, sqlite4_uint64 *pCurrent, sqlite4_uint64 *pHighwater, int resetFlag ); /* ** CAPIREF: Status Parameters ** KEYWORDS: {status parameters} ** ** These integer constants designate various run-time status parameters ** that can be returned by [sqlite4_status()]. ** ** <dl> ** [[SQLITE4_STATUS_MEMORY_USED]] ^(<dt>SQLITE4_STATUS_MEMORY_USED</dt> ** <dd>This parameter is the current amount of memory checked out ** using [sqlite4_malloc()], either directly or indirectly. The ** figure includes calls made to [sqlite4_malloc()] by the application ** and internal memory usage by the SQLite library. Scratch memory ** controlled by [SQLITE4_CONFIG_SCRATCH] and auxiliary page-cache ** memory controlled by [SQLITE4_CONFIG_PAGECACHE] is not included in ** this parameter. The amount returned is the sum of the allocation ** sizes as reported by the xSize method in [sqlite4_mem_methods].</dd>)^ ** ** [[SQLITE4_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE4_STATUS_MALLOC_SIZE</dt> ** <dd>This parameter records the largest memory allocation request ** handed to [sqlite4_malloc()] or [sqlite4_realloc()] (or their ** internal equivalents). Only the value returned in the ** *pHighwater parameter to [sqlite4_status()] is of interest. ** The value written into the *pCurrent parameter is undefined.</dd>)^ ** ** [[SQLITE4_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE4_STATUS_MALLOC_COUNT</dt> ** <dd>This parameter records the number of separate memory allocations ** currently checked out.</dd>)^ ** ** [[SQLITE4_STATUS_PARSER_STACK]] ^(<dt>SQLITE4_STATUS_PARSER_STACK</dt> ** <dd>This parameter records the deepest parser stack. It is only ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^ ** </dl> ** ** New status parameters may be added from time to time. */ #define SQLITE4_ENVSTATUS_MEMORY_USED 0 #define SQLITE4_ENVSTATUS_MALLOC_SIZE 1 #define SQLITE4_ENVSTATUS_MALLOC_COUNT 2 #define SQLITE4_ENVSTATUS_PARSER_STACK 3 /* ** CAPIREF: Database Connection Status ** ** ^This interface is used to retrieve runtime status information ** about a single [database connection]. ^The first argument is the ** database connection object to be interrogated. ^The second argument ** is an integer constant, taken from the set of ** [SQLITE4_DBSTATUS options], that ** determines the parameter to interrogate. The set of ** [SQLITE4_DBSTATUS options] is likely ** to grow in future releases of SQLite. ** ** ^The current value of the requested parameter is written into *pCur ** and the highest instantaneous value is written into *pHiwtr. ^If ** the resetFlg is true, then the highest instantaneous value is ** reset back down to the current value. ** ** ^The sqlite4_db_status() routine returns SQLITE4_OK on success and a ** non-zero [error code] on failure. ** ** See also: [sqlite4_status()] and [sqlite4_stmt_status()]. */ SQLITE4_API int sqlite4_db_status(sqlite4*, int op, int *pCur, int *pHiwtr, int resetFlg); /* ** CAPIREF: Status Parameters for database connections ** KEYWORDS: {SQLITE4_DBSTATUS options} ** ** These constants are the available integer "verbs" that can be passed as ** the second argument to the [sqlite4_db_status()] interface. ** ** New verbs may be added in future releases of SQLite. Existing verbs ** might be discontinued. Applications should check the return code from ** [sqlite4_db_status()] to make sure that the call worked. ** The [sqlite4_db_status()] interface will return a non-zero error code ** if a discontinued or unsupported verb is invoked. ** ** <dl> ** [[SQLITE4_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE4_DBSTATUS_LOOKASIDE_USED</dt> ** <dd>This parameter returns the number of lookaside memory slots currently ** checked out.</dd>)^ ** ** [[SQLITE4_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE4_DBSTATUS_LOOKASIDE_HIT</dt> ** <dd>This parameter returns the number malloc attempts that were ** satisfied using lookaside memory. Only the high-water value is meaningful; ** the current value is always zero.)^ ** ** [[SQLITE4_DBSTATUS_LOOKASIDE_MISS_SIZE]] ** ^(<dt>SQLITE4_DBSTATUS_LOOKASIDE_MISS_SIZE</dt> ** <dd>This parameter returns the number malloc attempts that might have ** been satisfied using lookaside memory but failed due to the amount of ** memory requested being larger than the lookaside slot size. ** Only the high-water value is meaningful; ** the current value is always zero.)^ ** ** [[SQLITE4_DBSTATUS_LOOKASIDE_MISS_FULL]] ** ^(<dt>SQLITE4_DBSTATUS_LOOKASIDE_MISS_FULL</dt> ** <dd>This parameter returns the number malloc attempts that might have ** been satisfied using lookaside memory but failed due to all lookaside ** memory already being in use. ** Only the high-water value is meaningful; ** the current value is always zero.)^ ** ** [[SQLITE4_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE4_DBSTATUS_CACHE_USED</dt> ** <dd>This parameter returns the approximate number of of bytes of heap ** memory used by all pager caches associated with the database connection.)^ ** ^The highwater mark associated with SQLITE4_DBSTATUS_CACHE_USED is always 0. ** ** [[SQLITE4_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE4_DBSTATUS_SCHEMA_USED</dt> ** <dd>This parameter returns the approximate number of of bytes of heap ** memory used to store the schema for all databases associated ** with the connection - main, temp, and any [ATTACH]-ed databases.)^ ** ^The full amount of memory used by the schemas is reported, even if the ** schema memory is shared with other database connections due to ** [shared cache mode] being enabled. ** ^The highwater mark associated with SQLITE4_DBSTATUS_SCHEMA_USED is always 0. ** ** [[SQLITE4_DBSTATUS_STMT_USED]] ^(<dt>SQLITE4_DBSTATUS_STMT_USED</dt> ** <dd>This parameter returns the approximate number of of bytes of heap ** and lookaside memory used by all prepared statements associated with ** the database connection.)^ ** ^The highwater mark associated with SQLITE4_DBSTATUS_STMT_USED is always 0. ** </dd> ** ** [[SQLITE4_DBSTATUS_CACHE_HIT]] ^(<dt>SQLITE4_DBSTATUS_CACHE_HIT</dt> ** <dd>This parameter returns the number of pager cache hits that have ** occurred.)^ ^The highwater mark associated with SQLITE4_DBSTATUS_CACHE_HIT ** is always 0. ** </dd> ** ** [[SQLITE4_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE4_DBSTATUS_CACHE_MISS</dt> ** <dd>This parameter returns the number of pager cache misses that have ** occurred.)^ ^The highwater mark associated with SQLITE4_DBSTATUS_CACHE_MISS ** is always 0. ** </dd> ** </dl> */ #define SQLITE4_DBSTATUS_LOOKASIDE_USED 0 #define SQLITE4_DBSTATUS_CACHE_USED 1 #define SQLITE4_DBSTATUS_SCHEMA_USED 2 #define SQLITE4_DBSTATUS_STMT_USED 3 #define SQLITE4_DBSTATUS_LOOKASIDE_HIT 4 #define SQLITE4_DBSTATUS_LOOKASIDE_MISS_SIZE 5 #define SQLITE4_DBSTATUS_LOOKASIDE_MISS_FULL 6 #define SQLITE4_DBSTATUS_CACHE_HIT 7 #define SQLITE4_DBSTATUS_CACHE_MISS 8 #define SQLITE4_DBSTATUS_MAX 8 /* Largest defined DBSTATUS */ /* ** CAPIREF: Prepared Statement Status ** ** ^(Each prepared statement maintains various ** [SQLITE4_STMTSTATUS counters] that measure the number ** of times it has performed specific operations.)^ These counters can ** be used to monitor the performance characteristics of the prepared ** statements. For example, if the number of table steps greatly exceeds ** the number of table searches or result rows, that would tend to indicate ** that the prepared statement is using a full table scan rather than ** an index. ** ** ^(This interface is used to retrieve and reset counter values from ** a [prepared statement]. The first argument is the prepared statement ** object to be interrogated. The second argument ** is an integer code for a specific [SQLITE4_STMTSTATUS counter] ** to be interrogated.)^ ** ^The current value of the requested counter is returned. ** ^If the resetFlg is true, then the counter is reset to zero after this ** interface call returns. ** ** See also: [sqlite4_status()] and [sqlite4_db_status()]. */ SQLITE4_API int sqlite4_stmt_status(sqlite4_stmt*, int op,int resetFlg); /* ** CAPIREF: Status Parameters for prepared statements ** KEYWORDS: {SQLITE4_STMTSTATUS counter} {SQLITE4_STMTSTATUS counters} ** ** These preprocessor macros define integer codes that name counter ** values associated with the [sqlite4_stmt_status()] interface. ** The meanings of the various counters are as follows: ** ** <dl> ** [[SQLITE4_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE4_STMTSTATUS_FULLSCAN_STEP</dt> ** <dd>^This is the number of times that SQLite has stepped forward in ** a table as part of a full table scan. Large numbers for this counter ** may indicate opportunities for performance improvement through ** careful use of indices.</dd> ** ** [[SQLITE4_STMTSTATUS_SORT]] <dt>SQLITE4_STMTSTATUS_SORT</dt> ** <dd>^This is the number of sort operations that have occurred. ** A non-zero value in this counter may indicate an opportunity to ** improvement performance through careful use of indices.</dd> ** ** [[SQLITE4_STMTSTATUS_AUTOINDEX]] <dt>SQLITE4_STMTSTATUS_AUTOINDEX</dt> ** <dd>^This is the number of rows inserted into transient indices that ** were created automatically in order to help joins run faster. ** A non-zero value in this counter may indicate an opportunity to ** improvement performance by adding permanent indices that do not ** need to be reinitialized each time the statement is run.</dd> ** </dl> */ #define SQLITE4_STMTSTATUS_FULLSCAN_STEP 1 #define SQLITE4_STMTSTATUS_SORT 2 #define SQLITE4_STMTSTATUS_AUTOINDEX 3 /* ** CAPIREF: Unlock Notification ** ** ^When running in shared-cache mode, a database operation may fail with ** an [SQLITE4_LOCKED] error if the required locks on the shared-cache or ** individual tables within the shared-cache cannot be obtained. See ** [SQLite Shared-Cache Mode] for a description of shared-cache locking. ** ^This API may be used to register a callback that SQLite will invoke ** when the connection currently holding the required lock relinquishes it. ** ^This API is only available if the library was compiled with the ** [SQLITE4_ENABLE_UNLOCK_NOTIFY] C-preprocessor symbol defined. ** ** See Also: [Using the SQLite Unlock Notification Feature]. ** ** ^Shared-cache locks are released when a database connection concludes ** its current transaction, either by committing it or rolling it back. ** ** ^When a connection (known as the blocked connection) fails to obtain a ** shared-cache lock and SQLITE4_LOCKED is returned to the caller, the ** identity of the database connection (the blocking connection) that ** has locked the required resource is stored internally. ^After an ** application receives an SQLITE4_LOCKED error, it may call the ** sqlite4_unlock_notify() method with the blocked connection handle as ** the first argument to register for a callback that will be invoked ** when the blocking connections current transaction is concluded. ^The ** callback is invoked from within the [sqlite4_step] or [sqlite4_close] ** call that concludes the blocking connections transaction. ** ** ^(If sqlite4_unlock_notify() is called in a multi-threaded application, ** there is a chance that the blocking connection will have already ** concluded its transaction by the time sqlite4_unlock_notify() is invoked. ** If this happens, then the specified callback is invoked immediately, ** from within the call to sqlite4_unlock_notify().)^ ** ** ^If the blocked connection is attempting to obtain a write-lock on a ** shared-cache table, and more than one other connection currently holds ** a read-lock on the same table, then SQLite arbitrarily selects one of ** the other connections to use as the blocking connection. ** ** ^(There may be at most one unlock-notify callback registered by a ** blocked connection. If sqlite4_unlock_notify() is called when the ** blocked connection already has a registered unlock-notify callback, ** then the new callback replaces the old.)^ ^If sqlite4_unlock_notify() is ** called with a NULL pointer as its second argument, then any existing ** unlock-notify callback is canceled. ^The blocked connections ** unlock-notify callback may also be canceled by closing the blocked ** connection using [sqlite4_close()]. ** ** The unlock-notify callback is not reentrant. If an application invokes ** any sqlite4_xxx API functions from within an unlock-notify callback, a ** crash or deadlock may be the result. ** ** ^Unless deadlock is detected (see below), sqlite4_unlock_notify() always ** returns SQLITE4_OK. ** ** <b>Callback Invocation Details</b> ** ** When an unlock-notify callback is registered, the application provides a ** single void* pointer that is passed to the callback when it is invoked. ** However, the signature of the callback function allows SQLite to pass ** it an array of void* context pointers. The first argument passed to ** an unlock-notify callback is a pointer to an array of void* pointers, ** and the second is the number of entries in the array. ** ** When a blocking connections transaction is concluded, there may be ** more than one blocked connection that has registered for an unlock-notify ** callback. ^If two or more such blocked connections have specified the ** same callback function, then instead of invoking the callback function ** multiple times, it is invoked once with the set of void* context pointers ** specified by the blocked connections bundled together into an array. ** This gives the application an opportunity to prioritize any actions ** related to the set of unblocked database connections. ** ** <b>Deadlock Detection</b> ** ** Assuming that after registering for an unlock-notify callback a ** database waits for the callback to be issued before taking any further ** action (a reasonable assumption), then using this API may cause the ** application to deadlock. For example, if connection X is waiting for ** connection Y's transaction to be concluded, and similarly connection ** Y is waiting on connection X's transaction, then neither connection ** will proceed and the system may remain deadlocked indefinitely. ** ** To avoid this scenario, the sqlite4_unlock_notify() performs deadlock ** detection. ^If a given call to sqlite4_unlock_notify() would put the ** system in a deadlocked state, then SQLITE4_LOCKED is returned and no ** unlock-notify callback is registered. The system is said to be in ** a deadlocked state if connection A has registered for an unlock-notify ** callback on the conclusion of connection B's transaction, and connection ** B has itself registered for an unlock-notify callback when connection ** A's transaction is concluded. ^Indirect deadlock is also detected, so ** the system is also considered to be deadlocked if connection B has ** registered for an unlock-notify callback on the conclusion of connection ** C's transaction, where connection C is waiting on connection A. ^Any ** number of levels of indirection are allowed. ** ** <b>The "DROP TABLE" Exception</b> ** ** When a call to [sqlite4_step()] returns SQLITE4_LOCKED, it is almost ** always appropriate to call sqlite4_unlock_notify(). There is however, ** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement, ** SQLite checks if there are any currently executing SELECT statements ** that belong to the same connection. If there are, SQLITE4_LOCKED is ** returned. In this case there is no "blocking connection", so invoking ** sqlite4_unlock_notify() results in the unlock-notify callback being ** invoked immediately. If the application then re-attempts the "DROP TABLE" ** or "DROP INDEX" query, an infinite loop might be the result. ** ** One way around this problem is to check the extended error code returned ** by an sqlite4_step() call. ^(If there is a blocking connection, then the ** extended error code is set to SQLITE4_LOCKED_SHAREDCACHE. Otherwise, in ** the special "DROP TABLE/INDEX" case, the extended error code is just ** SQLITE4_LOCKED.)^ */ SQLITE4_API int sqlite4_unlock_notify( sqlite4 *pBlocked, /* Waiting connection */ void (*xNotify)(void **apArg, int nArg), /* Callback function to invoke */ void *pNotifyArg /* Argument to pass to xNotify */ ); /* ** CAPIREF: String Comparison ** ** ^The [sqlite4_strnicmp()] API allows applications and extensions to ** compare the contents of two buffers containing UTF-8 strings in a ** case-independent fashion, using the same definition of case independence ** that SQLite uses internally when comparing identifiers. */ SQLITE4_API int sqlite4_strnicmp(const char *, const char *, int); /* ** CAPIREF: Error Logging Interface ** ** ^The [sqlite4_log()] interface writes a message into the error log ** established by the [SQLITE4_CONFIG_LOG] option to [sqlite4_env_config()]. ** ^If logging is enabled, the zFormat string and subsequent arguments are ** used with [sqlite4_snprintf()] to generate the final output string. ** ** The sqlite4_log() interface is intended for use by extensions such as ** virtual tables, collating functions, and SQL functions. While there is ** nothing to prevent an application from calling sqlite4_log(), doing so ** is considered bad form. ** ** The zFormat string must not be NULL. ** ** To avoid deadlocks and other threading problems, the sqlite4_log() routine ** will not use dynamically allocated memory. The log message is stored in ** a fixed-length buffer on the stack. If the log message is longer than ** a few hundred characters, it will be truncated to the length of the ** buffer. */ SQLITE4_API void sqlite4_log(sqlite4_env*, int iErrCode, const char *zFormat, ...); /* ** CAPIREF: Virtual Table Interface Configuration ** ** This function may be called by either the [xConnect] or [xCreate] method ** of a [virtual table] implementation to configure ** various facets of the virtual table interface. ** ** If this interface is invoked outside the context of an xConnect or ** xCreate virtual table method then the behavior is undefined. ** ** At present, there is only one option that may be configured using ** this function. (See [SQLITE4_VTAB_CONSTRAINT_SUPPORT].) Further options ** may be added in the future. */ SQLITE4_API int sqlite4_vtab_config(sqlite4*, int op, ...); /* ** CAPIREF: Virtual Table Configuration Options ** ** These macros define the various options to the ** [sqlite4_vtab_config()] interface that [virtual table] implementations ** can use to customize and optimize their behavior. ** ** <dl> ** <dt>SQLITE4_VTAB_CONSTRAINT_SUPPORT ** <dd>Calls of the form ** [sqlite4_vtab_config](db,SQLITE4_VTAB_CONSTRAINT_SUPPORT,X) are supported, ** where X is an integer. If X is zero, then the [virtual table] whose ** [xCreate] or [xConnect] method invoked [sqlite4_vtab_config()] does not ** support constraints. In this configuration (which is the default) if ** a call to the [xUpdate] method returns [SQLITE4_CONSTRAINT], then the entire ** statement is rolled back as if [ON CONFLICT | OR ABORT] had been ** specified as part of the users SQL statement, regardless of the actual ** ON CONFLICT mode specified. ** ** If X is non-zero, then the virtual table implementation guarantees ** that if [xUpdate] returns [SQLITE4_CONSTRAINT], it will do so before ** any modifications to internal or persistent data structures have been made. ** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite ** is able to roll back a statement or database transaction, and abandon ** or continue processing the current SQL statement as appropriate. ** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns ** [SQLITE4_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode ** had been ABORT. ** ** Virtual table implementations that are required to handle OR REPLACE ** must do so within the [xUpdate] method. If a call to the ** [sqlite4_vtab_on_conflict()] function indicates that the current ON ** CONFLICT policy is REPLACE, the virtual table implementation should ** silently replace the appropriate rows within the xUpdate callback and ** return SQLITE4_OK. Or, if this is not possible, it may return ** SQLITE4_CONSTRAINT, in which case SQLite falls back to OR ABORT ** constraint handling. ** </dl> */ #define SQLITE4_VTAB_CONSTRAINT_SUPPORT 1 /* ** CAPIREF: Determine The Virtual Table Conflict Policy ** ** This function may only be called from within a call to the [xUpdate] method ** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The ** value returned is one of [SQLITE4_ROLLBACK], [SQLITE4_IGNORE], [SQLITE4_FAIL], ** [SQLITE4_ABORT], or [SQLITE4_REPLACE], according to the [ON CONFLICT] mode ** of the SQL statement that triggered the call to the [xUpdate] method of the ** [virtual table]. */ SQLITE4_API int sqlite4_vtab_on_conflict(sqlite4 *); /* ** CAPIREF: Conflict resolution modes ** ** These constants are returned by [sqlite4_vtab_on_conflict()] to ** inform a [virtual table] implementation what the [ON CONFLICT] mode ** is for the SQL statement being evaluated. ** ** Note that the [SQLITE4_IGNORE] constant is also used as a potential ** return value from the [sqlite4_set_authorizer()] callback and that ** [SQLITE4_ABORT] is also a [result code]. */ #define SQLITE4_ROLLBACK 1 /* #define SQLITE4_IGNORE 2 // Also used by sqlite4_authorizer() callback */ #define SQLITE4_FAIL 3 /* #define SQLITE4_ABORT 4 // Also an error code */ #define SQLITE4_REPLACE 5 /* ** CAPI4REF: Length of a key-value storage key or data field ** ** The length of the key or data for a key-value storage entry is ** stored in a variable of this type. */ typedef int sqlite4_kvsize; /* ** CAPI4REF: Key-Value Storage Engine Object ** ** An instance of a subclass of the following object defines a ** connection to a storage engine. */ typedef struct sqlite4_kvstore sqlite4_kvstore; struct sqlite4_kvstore { const struct sqlite4_kv_methods *pStoreVfunc; /* Methods */ sqlite4_env *pEnv; /* Runtime environment for kvstore */ int iTransLevel; /* Current transaction level */ unsigned kvId; /* Unique ID used for tracing */ unsigned fTrace; /* True to enable tracing */ char zKVName[12]; /* Used for debugging */ /* Subclasses will typically append additional fields */ }; /* ** CAPI4REF: Key-Value Storage Engine Cursor Object ** ** An instance of a subclass of the following object defines a cursor ** used to scan through a key-value storage engine. */ typedef struct sqlite4_kvcursor sqlite4_kvcursor; struct sqlite4_kvcursor { sqlite4_kvstore *pStore; /* The owner of this cursor */ const struct sqlite4_kv_methods *pStoreVfunc; /* Methods */ sqlite4_env *pEnv; /* Runtime environment */ int iTransLevel; /* Current transaction level */ unsigned curId; /* Unique ID for tracing */ unsigned fTrace; /* True to enable tracing */ /* Subclasses will typically add additional fields */ }; /* ** CAPI4REF: Key-value storage engine virtual method table ** ** A Key-Value storage engine is defined by an instance of the following ** object. */ struct sqlite4_kv_methods { int iVersion; int szSelf; int (*xReplace)( sqlite4_kvstore*, const unsigned char *pKey, sqlite4_kvsize nKey, const unsigned char *pData, sqlite4_kvsize nData); int (*xOpenCursor)(sqlite4_kvstore*, sqlite4_kvcursor**); int (*xSeek)(sqlite4_kvcursor*, const unsigned char *pKey, sqlite4_kvsize nKey, int dir); int (*xNext)(sqlite4_kvcursor*); int (*xPrev)(sqlite4_kvcursor*); int (*xDelete)(sqlite4_kvcursor*); int (*xKey)(sqlite4_kvcursor*, const unsigned char **ppKey, sqlite4_kvsize *pnKey); int (*xData)(sqlite4_kvcursor*, sqlite4_kvsize ofst, sqlite4_kvsize n, const unsigned char **ppData, sqlite4_kvsize *pnData); int (*xReset)(sqlite4_kvcursor*); int (*xCloseCursor)(sqlite4_kvcursor*); int (*xBegin)(sqlite4_kvstore*, int); int (*xCommitPhaseOne)(sqlite4_kvstore*, int); int (*xCommitPhaseTwo)(sqlite4_kvstore*, int); int (*xRollback)(sqlite4_kvstore*, int); int (*xRevert)(sqlite4_kvstore*, int); int (*xClose)(sqlite4_kvstore*); int (*xControl)(sqlite4_kvstore*, int, void*); }; typedef struct sqlite4_kv_methods sqlite4_kv_methods; /* ** CAPI4REF: Key-value storage engine open flags ** ** Allowed values to the flags parameter of an sqlite4_kvstore object ** factory. ** ** The flags parameter to the sqlite4_kvstore factory (the fourth parameter) ** is an OR-ed combination of these values and the ** [SQLITE4_OPEN_READONLY | SQLITE4_OPEN_xxxxx] flags that appear as ** arguments to [sqlite4_open()]. */ #define SQLITE4_KVOPEN_TEMPORARY 0x00010000 /* A temporary database */ #define SQLITE4_KVOPEN_NO_TRANSACTIONS 0x00020000 /* No transactions needed */ /* ** CAPI4REF: Representation Of Numbers ** ** Every number in SQLite is represented in memory by an instance of ** the following object. */ typedef struct sqlite4_num sqlite4_num; struct sqlite4_num { unsigned char sign; /* Sign of the overall value */ unsigned char approx; /* True if the value is approximate */ unsigned short e; /* The exponent. */ sqlite4_uint64 m; /* The significant */ }; /* ** CAPI4REF: Operations On SQLite Number Objects */ SQLITE4_API sqlite4_num sqlite4_num_add(sqlite4_num, sqlite4_num); SQLITE4_API sqlite4_num sqlite4_num_sub(sqlite4_num, sqlite4_num); SQLITE4_API sqlite4_num sqlite4_num_mul(sqlite4_num, sqlite4_num); SQLITE4_API sqlite4_num sqlite4_num_div(sqlite4_num, sqlite4_num); SQLITE4_API int sqlite4_num_isinf(sqlite4_num); SQLITE4_API int sqlite4_num_isnan(sqlite4_num); SQLITE4_API sqlite4_num sqlite4_num_round(sqlite4_num, int iDigit); SQLITE4_API int sqlite4_num_compare(sqlite4_num, sqlite4_num); SQLITE4_API sqlite4_num sqlite4_num_from_text(const char*, int n, unsigned flags); SQLITE4_API sqlite4_num sqlite4_num_from_int64(sqlite4_int64); SQLITE4_API sqlite4_num sqlite4_num_from_double(double); SQLITE4_API int sqlite4_num_to_int32(sqlite4_num, int*); SQLITE4_API int sqlite4_num_to_int64(sqlite4_num, sqlite4_int64*); SQLITE4_API double sqlite4_num_to_double(sqlite4_num); SQLITE4_API int sqlite4_num_to_text(sqlite4_num, char*); /* ** CAPI4REF: Flags For Text-To-Numeric Conversion */ #define SQLITE4_PREFIX_ONLY 0x10 #define SQLITE4_IGNORE_WHITESPACE 0x20 /* ** Undo the hack that converts floating point types to integer for ** builds on processors without floating point support. */ #ifdef SQLITE4_OMIT_FLOATING_POINT # undef double #endif #ifdef __cplusplus } /* End of the 'extern "C"' block */ #endif #endif /* ** 2010 August 30 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* */ #ifndef _SQLITE3RTREE_H_ #define _SQLITE3RTREE_H_ #ifdef __cplusplus extern "C" { #endif typedef struct sqlite4_rtree_geometry sqlite4_rtree_geometry; /* ** Register a geometry callback named zGeom that can be used as part of an ** R-Tree geometry query as follows: ** ** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...) */ SQLITE4_API int sqlite4_rtree_geometry_callback( sqlite4 *db, const char *zGeom, int (*xGeom)(sqlite4_rtree_geometry *, int nCoord, double *aCoord, int *pRes), void *pContext ); /* ** A pointer to a structure of the following type is passed as the first ** argument to callbacks registered using rtree_geometry_callback(). */ struct sqlite4_rtree_geometry { void *pContext; /* Copy of pContext passed to s_r_g_c() */ int nParam; /* Size of array aParam[] */ double *aParam; /* Parameters passed to SQL geom function */ void *pUser; /* Callback implementation user data */ void (*xDelUser)(void *); /* Called by SQLite to clean up pUser */ }; #ifdef __cplusplus } /* end of the 'extern "C"' block */ #endif #endif /* ifndef _SQLITE3RTREE_H_ */ |
Changes to src/stash.c.
︙ | ︙ | |||
80 81 82 83 84 85 86 | blob_reset(&sql); db_prepare(&ins, "INSERT INTO stashfile(stashid, rid, isAdded, isRemoved, isExec, isLink," "origname, newname, delta)" "VALUES(%d,:rid,:isadd,:isrm,:isexe,:islink,:orig,:new,:content)", stashid ); | | | 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | blob_reset(&sql); db_prepare(&ins, "INSERT INTO stashfile(stashid, rid, isAdded, isRemoved, isExec, isLink," "origname, newname, delta)" "VALUES(%d,:rid,:isadd,:isrm,:isexe,:islink,:orig,:new,:content)", stashid ); while( db_step(&q)==SQLITE4_ROW ){ int deleted = db_column_int(&q, 0); int rid = db_column_int(&q, 3); const char *zName = db_column_text(&q, 4); const char *zOrig = db_column_text(&q, 5); char *zPath = mprintf("%s%s", g.zLocalRoot, zName); Blob content; int isNewLink = file_wd_islink(zPath); |
︙ | ︙ | |||
183 184 185 186 187 188 189 | static void stash_apply(int stashid, int nConflict){ Stmt q; db_prepare(&q, "SELECT rid, isRemoved, isExec, isLink, origname, newname, delta" " FROM stashfile WHERE stashid=%d", stashid ); | | | 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | static void stash_apply(int stashid, int nConflict){ Stmt q; db_prepare(&q, "SELECT rid, isRemoved, isExec, isLink, origname, newname, delta" " FROM stashfile WHERE stashid=%d", stashid ); while( db_step(&q)==SQLITE4_ROW ){ int rid = db_column_int(&q, 0); int isRemoved = db_column_int(&q, 1); int isExec = db_column_int(&q, 2); int isLink = db_column_int(&q, 3); const char *zOrig = db_column_text(&q, 4); const char *zNew = db_column_text(&q, 5); char *zOPath = mprintf("%s%s", g.zLocalRoot, zOrig); |
︙ | ︙ | |||
274 275 276 277 278 279 280 | Blob empty; blob_zero(&empty); db_prepare(&q, "SELECT rid, isRemoved, isExec, isLink, origname, newname, delta" " FROM stashfile WHERE stashid=%d", stashid ); | | | 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | Blob empty; blob_zero(&empty); db_prepare(&q, "SELECT rid, isRemoved, isExec, isLink, origname, newname, delta" " FROM stashfile WHERE stashid=%d", stashid ); while( db_step(&q)==SQLITE4_ROW ){ int rid = db_column_int(&q, 0); int isRemoved = db_column_int(&q, 1); int isLink = db_column_int(&q, 3); const char *zOrig = db_column_text(&q, 4); const char *zNew = db_column_text(&q, 5); char *zOPath = mprintf("%s%s", g.zLocalRoot, zOrig); Blob delta; |
︙ | ︙ | |||
430 431 432 433 434 435 436 | if( g.argc>=2 ){ int nFile = db_int(0, "SELECT count(*) FROM stashfile WHERE stashid=%d", stashid); char **newArgv = fossil_malloc( sizeof(char*)*(nFile+2) ); int i = 2; Stmt q; db_prepare(&q,"SELECT origname FROM stashfile WHERE stashid=%d", stashid); | | | 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 | if( g.argc>=2 ){ int nFile = db_int(0, "SELECT count(*) FROM stashfile WHERE stashid=%d", stashid); char **newArgv = fossil_malloc( sizeof(char*)*(nFile+2) ); int i = 2; Stmt q; db_prepare(&q,"SELECT origname FROM stashfile WHERE stashid=%d", stashid); while( db_step(&q)==SQLITE4_ROW ){ newArgv[i++] = mprintf("%s%s", g.zLocalRoot, db_column_text(&q, 0)); } db_finalize(&q); newArgv[0] = g.argv[0]; g.argv = newArgv; g.argc = nFile+2; if( nFile==0 ) return; |
︙ | ︙ | |||
459 460 461 462 463 464 465 | " comment, datetime(ctime) FROM stash" " ORDER BY ctime DESC" ); if( fDetail ){ db_prepare(&q2, "SELECT isAdded, isRemoved, origname, newname" " FROM stashfile WHERE stashid=$id"); } | | | | 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 | " comment, datetime(ctime) FROM stash" " ORDER BY ctime DESC" ); if( fDetail ){ db_prepare(&q2, "SELECT isAdded, isRemoved, origname, newname" " FROM stashfile WHERE stashid=$id"); } while( db_step(&q)==SQLITE4_ROW ){ int stashid = db_column_int(&q, 0); const char *zCom; n++; fossil_print("%5d: [%.14s] on %s\n", stashid, db_column_text(&q, 1), db_column_text(&q, 3) ); zCom = db_column_text(&q, 2); if( zCom && zCom[0] ){ fossil_print(" "); comment_print(zCom, 7, 79); } if( fDetail ){ db_bind_int(&q2, "$id", stashid); while( db_step(&q2)==SQLITE4_ROW ){ int isAdded = db_column_int(&q2, 0); int isRemoved = db_column_int(&q2, 1); const char *zOrig = db_column_text(&q2, 2); const char *zNew = db_column_text(&q2, 3); if( isAdded ){ fossil_print(" ADD %s\n", zNew); }else if( isRemoved ){ |
︙ | ︙ |
Changes to src/stat.c.
︙ | ︙ | |||
22 23 24 25 26 27 28 | #include "config.h" #include "stat.h" /* ** For a sufficiently large integer, provide an alternative ** representation as MB or GB or TB. */ | | | | | | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #include "config.h" #include "stat.h" /* ** For a sufficiently large integer, provide an alternative ** representation as MB or GB or TB. */ static void bigSizeName(int nOut, char *zOut, sqlite4_int64 v){ if( v<100000 ){ sqlite4_snprintf(zOut, nOut, "%lld bytes", v); }else if( v<1000000000 ){ sqlite4_snprintf(zOut, nOut, "%lld bytes (%.1fMB)", v, (double)v/1000000.0); }else{ sqlite4_snprintf(zOut, nOut, "%lld bytes (%.1fGB)", v, (double)v/1000000000.0); } } /* ** WEBPAGE: stat ** |
︙ | ︙ | |||
118 119 120 121 122 123 124 | @ </td></tr> @ <tr><th>Project ID:</th><td>%h(db_get("project-code",""))</td></tr> @ <tr><th>Server ID:</th><td>%h(db_get("server-code",""))</td></tr> @ <tr><th>Fossil Version:</th><td> @ %h(RELEASE_VERSION) %h(MANIFEST_DATE) %h(MANIFEST_VERSION) @ (%h(COMPILER_NAME)) @ </td></tr> | | | | 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | @ </td></tr> @ <tr><th>Project ID:</th><td>%h(db_get("project-code",""))</td></tr> @ <tr><th>Server ID:</th><td>%h(db_get("server-code",""))</td></tr> @ <tr><th>Fossil Version:</th><td> @ %h(RELEASE_VERSION) %h(MANIFEST_DATE) %h(MANIFEST_VERSION) @ (%h(COMPILER_NAME)) @ </td></tr> @ <tr><th>SQLite Version:</th><td>%.19s(SQLITE4_SOURCE_ID) @ [%.10s(&SQLITE4_SOURCE_ID[20])] (%s(SQLITE4_VERSION))</td></tr> @ <tr><th>Database Stats:</th><td> zDb = db_name("repository"); @ %d(db_int(0, "PRAGMA %s.page_count", zDb)) pages, @ %d(db_int(0, "PRAGMA %s.page_size", zDb)) bytes/page, @ %d(db_int(0, "PRAGMA %s.freelist_count", zDb)) free pages, @ %s(db_text(0, "PRAGMA %s.encoding", zDb)), @ %s(db_text(0, "PRAGMA %s.journal_mode", zDb)) mode @ </td></tr> @ </table> style_footer(); } |
Changes to src/tag.c.
︙ | ︙ | |||
79 80 81 82 83 84 85 | if( tagid==TAG_BGCOLOR ){ db_prepare(&eventupdate, "UPDATE event SET bgcolor=%Q WHERE objid=:rid", zValue ); } while( (pid = pqueuex_extract(&queue, 0))!=0 ){ db_bind_int(&s, ":pid", pid); | | | 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | if( tagid==TAG_BGCOLOR ){ db_prepare(&eventupdate, "UPDATE event SET bgcolor=%Q WHERE objid=:rid", zValue ); } while( (pid = pqueuex_extract(&queue, 0))!=0 ){ db_bind_int(&s, ":pid", pid); while( db_step(&s)==SQLITE4_ROW ){ int doit = db_column_int(&s, 2); if( doit ){ int cid = db_column_int(&s, 0); double mtime = db_column_double(&s, 1); pqueuex_insert(&queue, cid, mtime, 0); db_bind_int(&ins, ":rid", cid); db_step(&ins); |
︙ | ︙ | |||
118 119 120 121 122 123 124 | void tag_propagate_all(int pid){ Stmt q; db_prepare(&q, "SELECT tagid, tagtype, mtime, value, origid FROM tagxref" " WHERE rid=%d", pid ); | | | 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | void tag_propagate_all(int pid){ Stmt q; db_prepare(&q, "SELECT tagid, tagtype, mtime, value, origid FROM tagxref" " WHERE rid=%d", pid ); while( db_step(&q)==SQLITE4_ROW ){ int tagid = db_column_int(&q, 0); int tagtype = db_column_int(&q, 1); double mtime = db_column_double(&q, 2); const char *zValue = db_column_text(&q, 3); int origid = db_column_int(&q, 4); if( tagtype==1 ) tagtype = 0; tag_propagate(pid, tagid, tagtype, origid, zValue, mtime); |
︙ | ︙ | |||
173 174 175 176 177 178 179 | " AND rid=%d" " AND mtime>=:mtime", tagid, rid ); db_bind_double(&s, ":mtime", mtime); rc = db_step(&s); db_finalize(&s); | | | 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | " AND rid=%d" " AND mtime>=:mtime", tagid, rid ); db_bind_double(&s, ":mtime", mtime); rc = db_step(&s); db_finalize(&s); if( rc==SQLITE4_ROW ){ /* Another entry that is more recent already exists. Do nothing */ return tagid; } db_prepare(&s, "REPLACE INTO tagxref(tagid,tagtype,srcId,origid,value,mtime,rid)" " VALUES(%d,%d,%d,%d,%Q,:mtime,%d)", tagid, tagtype, srcId, rid, zValue, rid |
︙ | ︙ | |||
438 439 440 441 442 443 444 | db_prepare(&q, "SELECT blob.uuid FROM tagxref, blob" " WHERE tagid=(SELECT tagid FROM tag WHERE tagname=%Q)" " AND tagxref.tagtype>0" " AND blob.rid=tagxref.rid", g.argv[3] ); | | | 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 | db_prepare(&q, "SELECT blob.uuid FROM tagxref, blob" " WHERE tagid=(SELECT tagid FROM tag WHERE tagname=%Q)" " AND tagxref.tagtype>0" " AND blob.rid=tagxref.rid", g.argv[3] ); while( db_step(&q)==SQLITE4_ROW ){ fossil_print("%s\n", db_column_text(&q, 0)); } db_finalize(&q); }else{ int tagid = db_int(0, "SELECT tagid FROM tag WHERE tagname='sym-%q'", g.argv[3]); if( tagid>0 ){ |
︙ | ︙ | |||
472 473 474 475 476 477 478 | db_prepare(&q, "SELECT tagname FROM tag" " WHERE EXISTS(SELECT 1 FROM tagxref" " WHERE tagid=tag.tagid" " AND tagtype>0)" " ORDER BY tagname" ); | | | | 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 | db_prepare(&q, "SELECT tagname FROM tag" " WHERE EXISTS(SELECT 1 FROM tagxref" " WHERE tagid=tag.tagid" " AND tagtype>0)" " ORDER BY tagname" ); while( db_step(&q)==SQLITE4_ROW ){ const char *zName = db_column_text(&q, 0); if( fRaw ){ fossil_print("%s\n", zName); }else if( strncmp(zName, "sym-", 4)==0 ){ fossil_print("%s\n", &zName[4]); } } db_finalize(&q); }else if( g.argc==4 ){ int rid = name_to_rid(g.argv[3]); db_prepare(&q, "SELECT tagname, value FROM tagxref, tag" " WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid" " AND tagtype>%d" " ORDER BY tagname", rid, fRaw ? -1 : 0 ); while( db_step(&q)==SQLITE4_ROW ){ const char *zName = db_column_text(&q, 0); const char *zValue = db_column_text(&q, 1); if( fRaw==0 ){ if( strncmp(zName, "sym-", 4)!=0 ) continue; zName += 4; } if( zValue && zValue[0] ){ |
︙ | ︙ | |||
544 545 546 547 548 549 550 | " WHERE EXISTS(SELECT 1 FROM tagxref" " WHERE tagid=tag.tagid" " AND tagtype=1)" " AND tagname GLOB 'sym-*'" " ORDER BY tagname" ); @ <ul> | | | 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 | " WHERE EXISTS(SELECT 1 FROM tagxref" " WHERE tagid=tag.tagid" " AND tagtype=1)" " AND tagname GLOB 'sym-*'" " ORDER BY tagname" ); @ <ul> while( db_step(&q)==SQLITE4_ROW ){ const char *zName = db_column_text(&q, 0); if( g.perm.Hyperlink ){ @ <li>%z(xhref("class='taglink'","%R/timeline?t=%T",zName)) @ %h(zName)</a></li> }else{ @ <li><span class="tagDsp">%h(zName)</span></li> } |
︙ | ︙ |
Changes to src/tar.c.
︙ | ︙ | |||
42 43 44 45 46 47 48 | /* ** Begin the process of generating a tarball. ** ** Initialize the GZIP compressor and the table of directory names. */ | | | 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | /* ** Begin the process of generating a tarball. ** ** Initialize the GZIP compressor and the table of directory names. */ static void tar_begin(sqlite4_int64 mTime){ assert( tball.aHdr==0 ); tball.aHdr = fossil_malloc(512+512); memset(tball.aHdr, 0, 512+512); tball.zSpaces = (char*)&tball.aHdr[512]; /* zPrevDir init */ tball.zPrevDir = NULL; tball.nPrevDirAlloc = 0; |
︙ | ︙ | |||
262 263 264 265 266 267 268 | char cType ){ unsigned int cksum = 0; int i; memset(&tball.aHdr[148], ' ', 8); tball.aHdr[156] = cType; for(i=0; i<512; i++) cksum += tball.aHdr[i]; | | | | | | | 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | char cType ){ unsigned int cksum = 0; int i; memset(&tball.aHdr[148], ' ', 8); tball.aHdr[156] = cType; for(i=0; i<512; i++) cksum += tball.aHdr[i]; sqlite4_snprintf((char*)&tball.aHdr[148], 8, "%07o", cksum); tball.aHdr[155] = 0; gzip_step((char*)tball.aHdr, 512); } /* ** Build a header for a file or directory and write that header ** into the growing tarball. */ static void tar_add_header( const char *zName, /* Name of the object */ int nName, /* Number of characters in zName */ int iMode, /* Mode. 0644 or 0755 */ unsigned int mTime, /* File modification time */ int iSize, /* Size of the object in bytes */ char cType /* Type of object: '0'==file. '2'==symlink. '5'==directory */ ){ /* set mode and modification time */ sqlite4_snprintf((char*)&tball.aHdr[100], 8, "%07o", iMode); sqlite4_snprintf((char*)&tball.aHdr[136], 12, "%011o", mTime); /* see if we need to output a Pax Interchange Header */ if( !is_iso646_name(zName, nName) || !tar_split_path(zName, nName, (char*)tball.aHdr, (char*)&tball.aHdr[345]) ){ int lastPage; /* add a file name for interoperability with older programs */ approximate_split_path(zName, nName, (char*)tball.aHdr, (char*)&tball.aHdr[345], 1); /* generate the Pax Interchange path header */ blob_reset(&tball.pax); add_pax_header("path", zName, nName); /* set the header length, and write the header */ sqlite4_snprintf((char*)&tball.aHdr[124], 8, "%011o", blob_size(&tball.pax)); cksum_and_write_header('x'); /* write the Pax Interchange data */ gzip_step(blob_buffer(&tball.pax), blob_size(&tball.pax)); lastPage = blob_size(&tball.pax) % 512; if( lastPage!=0 ){ gzip_step(tball.zSpaces, 512 - lastPage); } /* generate an approximate path for the regular header */ approximate_split_path(zName, nName, (char*)tball.aHdr, (char*)&tball.aHdr[345], 0); } /* set the size */ sqlite4_snprintf((char*)&tball.aHdr[124], 12, "%011o", iSize); /* write the regular header */ cksum_and_write_header(cType); } /* |
︙ | ︙ | |||
337 338 339 340 341 342 343 | ){ int i; for(i=nName-1; i>0 && zName[i]!='/'; i--){} if( i<=0 ) return; if( i < tball.nPrevDirAlloc && tball.zPrevDir[i]==0 && memcmp(tball.zPrevDir, zName, i)==0 ) return; db_multi_exec("INSERT OR IGNORE INTO dir VALUES('%#q')", i, zName); | | | 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | ){ int i; for(i=nName-1; i>0 && zName[i]!='/'; i--){} if( i<=0 ) return; if( i < tball.nPrevDirAlloc && tball.zPrevDir[i]==0 && memcmp(tball.zPrevDir, zName, i)==0 ) return; db_multi_exec("INSERT OR IGNORE INTO dir VALUES('%#q')", i, zName); if( sqlite4_changes(g.db)==0 ) return; tar_add_directory_of(zName, i-1, mTime); tar_add_header(zName, i, 0755, mTime, 0, '5'); if( i >= tball.nPrevDirAlloc ){ int nsize = tball.nPrevDirAlloc * 2; if(i+1 > nsize) nsize = i+1; tball.zPrevDir = fossil_realloc(tball.zPrevDir, nsize); |
︙ | ︙ | |||
377 378 379 380 381 382 383 | * If we have a symlink, write its destination path (which is stored in * pContent) into header, and set content length to 0 to avoid storing path * as file content in the next step. Since 'linkname' header is limited to * 100 bytes (-1 byte for terminating zero), if path is greater than that, * store symlink as a plain-text file. (Not sure how TAR handles long links.) */ if( mPerm == PERM_LNK && n <= 100 ){ | | | 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | * If we have a symlink, write its destination path (which is stored in * pContent) into header, and set content length to 0 to avoid storing path * as file content in the next step. Since 'linkname' header is limited to * 100 bytes (-1 byte for terminating zero), if path is greater than that, * store symlink as a plain-text file. (Not sure how TAR handles long links.) */ if( mPerm == PERM_LNK && n <= 100 ){ sqlite4_snprintf((char*)&tball.aHdr[157], 100, "%s", blob_str(pContent)); cType = '2'; n = 0; } tar_add_header(zName, nName, ( mPerm==PERM_EXE ) ? 0755 : 0644, mTime, n, cType); if( n ){ |
︙ | ︙ | |||
424 425 426 427 428 429 430 | void test_tarball_cmd(void){ int i; Blob zip; Blob file; if( g.argc<3 ){ usage("ARCHIVE FILE...."); } | | | 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 | void test_tarball_cmd(void){ int i; Blob zip; Blob file; if( g.argc<3 ){ usage("ARCHIVE FILE...."); } sqlite4_open(0, ":memory:", &g.db, SQLITE4_OPEN_READWRITE); tar_begin(0); for(i=3; i<g.argc; i++){ blob_zero(&file); blob_read_from_file(&file, g.argv[i]); tar_add_file(g.argv[i], &file, file_wd_perm(g.argv[i]), file_wd_mtime(g.argv[i])); blob_reset(&file); |
︙ | ︙ |
Changes to src/th.c.
︙ | ︙ | |||
2344 2345 2346 2347 2348 2349 2350 | ** Return TRUE if z is a pure numeric string. Return FALSE if the ** string contains any character which is not part of a number. If ** the string is numeric and contains the '.' character, set *realnum ** to TRUE (otherwise FALSE). ** ** An empty string is considered non-numeric. */ | | | 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 | ** Return TRUE if z is a pure numeric string. Return FALSE if the ** string contains any character which is not part of a number. If ** the string is numeric and contains the '.' character, set *realnum ** to TRUE (otherwise FALSE). ** ** An empty string is considered non-numeric. */ static int sqlite4IsNumber(const char *z, int *realnum){ int incr = 1; if( *z=='-' || *z=='+' ) z += incr; if( !th_isdigit(*(u8*)z) ){ return 0; } z += incr; if( realnum ) *realnum = 0; |
︙ | ︙ | |||
2381 2382 2383 2384 2385 2386 2387 | ** is not, the result is undefined. ** ** This routine is used instead of the library atof() function because ** the library atof() might want to use "," as the decimal point instead ** of "." depending on how locale is set. But that would cause problems ** for SQL. So this routine always uses "." regardless of locale. */ | | | 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 | ** is not, the result is undefined. ** ** This routine is used instead of the library atof() function because ** the library atof() might want to use "," as the decimal point instead ** of "." depending on how locale is set. But that would cause problems ** for SQL. So this routine always uses "." regardless of locale. */ static int sqlite4AtoF(const char *z, double *pResult){ int sign = 1; const char *zBegin = z; LONGDOUBLE_TYPE v1 = 0.0; while( th_isspace(*(u8*)z) ) z++; if( *z=='-' ){ sign = -1; z++; |
︙ | ︙ | |||
2484 2485 2486 2487 2488 2489 2490 | */ int Th_ToDouble( Th_Interp *interp, const char *z, int n, double *pfOut ){ | | | | 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 | */ int Th_ToDouble( Th_Interp *interp, const char *z, int n, double *pfOut ){ if( !sqlite4IsNumber((const char *)z, 0) ){ Th_ErrorMessage(interp, "expected number, got: \"", z, n); return TH_ERROR; } sqlite4AtoF((const char *)z, pfOut); return TH_OK; } /* ** Set the result of the interpreter to the th1 representation of ** the integer iVal and return TH_OK. */ |
︙ | ︙ |
Changes to src/timeline.c.
︙ | ︙ | |||
147 148 149 150 151 152 153 | case 0: r = mx; g = h2, b = mn; break; case 1: r = h2; g = mx, b = mn; break; case 2: r = mn; g = mx, b = h2; break; case 3: r = mn; g = h2, b = mx; break; case 4: r = h2; g = mn, b = mx; break; default: r = mx; g = mn, b = h2; break; } | | | 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | case 0: r = mx; g = h2, b = mn; break; case 1: r = h2; g = mx, b = mn; break; case 2: r = mn; g = mx, b = h2; break; case 3: r = mn; g = h2, b = mx; break; case 4: r = h2; g = mn, b = mx; break; default: r = mx; g = mn, b = h2; break; } sqlite4_snprintf(zColor, 8, "#%02x%02x%02x", r,g,b); return zColor; } /* ** COMMAND: test-hash-color ** ** Usage: %fossil test-hash-color TAG ... |
︙ | ︙ | |||
222 223 224 225 226 227 228 | db_static_prepare(&qbranch, "SELECT value FROM tagxref WHERE tagid=%d AND tagtype>0 AND rid=:rid", TAG_BRANCH ); @ <table id="timelineTable" class="timelineTable"> blob_zero(&comment); | | | 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | db_static_prepare(&qbranch, "SELECT value FROM tagxref WHERE tagid=%d AND tagtype>0 AND rid=:rid", TAG_BRANCH ); @ <table id="timelineTable" class="timelineTable"> blob_zero(&comment); while( db_step(pQuery)==SQLITE4_ROW ){ int rid = db_column_int(pQuery, 0); const char *zUuid = db_column_text(pQuery, 1); int isLeaf = db_column_int(pQuery, 5); const char *zBgClr = db_column_text(pQuery, 6); const char *zDate = db_column_text(pQuery, 2); const char *zType = db_column_text(pQuery, 7); const char *zUser = db_column_text(pQuery, 4); |
︙ | ︙ | |||
261 262 263 264 265 266 267 | @ <tr><td colspan="3"><hr /></td></tr> } prevWasDivider = 1; continue; } prevWasDivider = 0; if( memcmp(zDate, zPrevDate, 10) ){ | | | | 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | @ <tr><td colspan="3"><hr /></td></tr> } prevWasDivider = 1; continue; } prevWasDivider = 0; if( memcmp(zDate, zPrevDate, 10) ){ sqlite4_snprintf(zPrevDate, sizeof(zPrevDate), "%.10s", zDate); @ <tr><td> @ <div class="divider">%s(zPrevDate)</div> @ </td></tr> } memcpy(zTime, &zDate[11], 5); zTime[5] = 0; @ <tr> @ <td class="timelineTime">%s(zTime)</td> @ <td class="timelineGraph"> if( tmFlags & TIMELINE_UCOLOR ) zBgClr = zUser ? hash_color(zUser) : 0; if( zType[0]=='c' && (pGraph || zBgClr==0 || (tmFlags & TIMELINE_BRCOLOR)!=0) ){ db_reset(&qbranch); db_bind_int(&qbranch, ":rid", rid); if( db_step(&qbranch)==SQLITE4_ROW ){ zBr = db_column_text(&qbranch, 0); }else{ zBr = "trunk"; } if( zBgClr==0 || (tmFlags & TIMELINE_BRCOLOR)!=0 ){ if( zBr==0 || strcmp(zBr,"trunk")==0 ){ zBgClr = 0; |
︙ | ︙ | |||
301 302 303 304 305 306 307 | static Stmt qparent; db_static_prepare(&qparent, "SELECT pid FROM plink" " WHERE cid=:rid AND pid NOT IN phantom" " ORDER BY isprim DESC /*sort*/" ); db_bind_int(&qparent, ":rid", rid); | | | 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | static Stmt qparent; db_static_prepare(&qparent, "SELECT pid FROM plink" " WHERE cid=:rid AND pid NOT IN phantom" " ORDER BY isprim DESC /*sort*/" ); db_bind_int(&qparent, ":rid", rid); while( db_step(&qparent)==SQLITE4_ROW && nParent<32 ){ aParent[nParent++] = db_column_int(&qparent, 0); } db_reset(&qparent); gidx = graph_add_row(pGraph, rid, nParent, aParent, zBr, zBgClr, isLeaf); db_reset(&qbranch); @ <div id="m%d(gidx)"></div> } |
︙ | ︙ | |||
416 417 418 419 420 421 422 | " FROM mlink" " WHERE mid=:mid AND (pid!=fid OR pfnid>0)" " ORDER BY 3 /*sort*/" ); fchngQueryInit = 1; } db_bind_int(&fchngQuery, ":mid", rid); | | | 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | " FROM mlink" " WHERE mid=:mid AND (pid!=fid OR pfnid>0)" " ORDER BY 3 /*sort*/" ); fchngQueryInit = 1; } db_bind_int(&fchngQuery, ":mid", rid); while( db_step(&fchngQuery)==SQLITE4_ROW ){ const char *zFilename = db_column_text(&fchngQuery, 2); int isNew = db_column_int(&fchngQuery, 0); int isDel = db_column_int(&fchngQuery, 1); const char *zOldName = db_column_text(&fchngQuery, 5); const char *zOld = db_column_text(&fchngQuery, 4); const char *zNew = db_column_text(&fchngQuery, 3); if( !inUl ){ |
︙ | ︙ | |||
1283 1284 1285 1286 1287 1288 1289 | zPrevDate[0] = 0; if( g.localOpen ){ int rid = db_lget_int("checkout", 0); zCurrentUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid); } | | | | | | | | | | 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 | zPrevDate[0] = 0; if( g.localOpen ){ int rid = db_lget_int("checkout", 0); zCurrentUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid); } while( db_step(q)==SQLITE4_ROW && nLine<=mxLine ){ int rid = db_column_int(q, 0); const char *zId = db_column_text(q, 1); const char *zDate = db_column_text(q, 2); const char *zCom = db_column_text(q, 3); int nChild = db_column_int(q, 4); int nParent = db_column_int(q, 5); char *zFree = 0; int n = 0; char zPrefix[80]; char zUuid[UUID_SIZE+1]; sqlite4_snprintf(zUuid, sizeof(zUuid), "%.10s", zId); if( memcmp(zDate, zPrevDate, 10) ){ fossil_print("=== %.10s ===\n", zDate); memcpy(zPrevDate, zDate, 10); nLine++; } if( zCom==0 ) zCom = ""; fossil_print("%.8s ", &zDate[11]); zPrefix[0] = 0; if( nParent>1 ){ sqlite4_snprintf(zPrefix, sizeof(zPrefix), "*MERGE* "); n = strlen(zPrefix); } if( nChild>1 ){ const char *zBrType; if( count_nonbranch_children(rid)>1 ){ zBrType = "*FORK* "; }else{ zBrType = "*BRANCH* "; } sqlite4_snprintf(zPrefix+n, sizeof(zPrefix)-n, zBrType); n = strlen(zPrefix); } if( fossil_strcmp(zCurrentUuid,zId)==0 ){ sqlite4_snprintf(zPrefix+n, sizeof(zPrefix)-n, "*CURRENT* "); n += strlen(zPrefix); } zFree = sqlite4_mprintf(0, "[%.10s] %s%s", zUuid, zPrefix, zCom); nLine += comment_print(zFree, 9, 79); sqlite4_free(0, zFree); if(showfiles){ if( !fchngQueryInit ){ db_prepare(&fchngQuery, "SELECT (pid==0) AS isnew," " (fid==0) AS isdel," " (SELECT name FROM filename WHERE fnid=mlink.fnid) AS name," " (SELECT uuid FROM blob WHERE rid=fid)," " (SELECT uuid FROM blob WHERE rid=pid)" " FROM mlink" " WHERE mid=:mid AND pid!=fid" " ORDER BY 3 /*sort*/" ); fchngQueryInit = 1; } db_bind_int(&fchngQuery, ":mid", rid); while( db_step(&fchngQuery)==SQLITE4_ROW ){ const char *zFilename = db_column_text(&fchngQuery, 2); int isNew = db_column_int(&fchngQuery, 0); int isDel = db_column_int(&fchngQuery, 1); if( isNew ){ fossil_print(" ADDED %s\n",zFilename); }else if( isDel ){ fossil_print(" DELETED %s\n",zFilename); |
︙ | ︙ | |||
1581 1582 1583 1584 1585 1586 1587 | db_prepare(&q, "SELECT (SELECT uuid FROM blob WHERE rid=p.cid)," " (SELECT uuid FROM blob WHERE rid=c.cid)," " datetime(p.mtime), datetime(c.mtime)" " FROM plink p, plink c" " WHERE p.cid=c.pid AND p.mtime>c.mtime" ); | | | 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 | db_prepare(&q, "SELECT (SELECT uuid FROM blob WHERE rid=p.cid)," " (SELECT uuid FROM blob WHERE rid=c.cid)," " datetime(p.mtime), datetime(c.mtime)" " FROM plink p, plink c" " WHERE p.cid=c.pid AND p.mtime>c.mtime" ); while( db_step(&q)==SQLITE4_ROW ){ if( !showDetail ){ fossil_print("%s\n", db_column_text(&q, 1)); }else{ fossil_print("%.14s -> %.14s %s -> %s\n", db_column_text(&q, 0), db_column_text(&q, 1), db_column_text(&q, 2), |
︙ | ︙ | |||
1611 1612 1613 1614 1615 1616 1617 | @ <ul> db_prepare(&q, "SELECT blob.uuid " " FROM plink p, plink c, blob" " WHERE p.cid=c.pid AND p.mtime>c.mtime" " AND blob.rid=c.cid" ); | | | 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 | @ <ul> db_prepare(&q, "SELECT blob.uuid " " FROM plink p, plink c, blob" " WHERE p.cid=c.pid AND p.mtime>c.mtime" " AND blob.rid=c.cid" ); while( db_step(&q)==SQLITE4_ROW ){ const char *zUuid = db_column_text(&q, 0); @ <li> @ <a href="%s(g.zTop)/timeline?p=%S(zUuid)&d=%S(zUuid)">%S(zUuid)</a> } db_finalize(&q); style_footer(); } |
Changes to src/tkt.c.
︙ | ︙ | |||
47 48 49 50 51 52 53 | ** all the values there to zero. */ static void getAllTicketFields(void){ Stmt q; int i; if( nField>0 ) return; db_prepare(&q, "PRAGMA table_info(ticket)"); | | | 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | ** all the values there to zero. */ static void getAllTicketFields(void){ Stmt q; int i; if( nField>0 ) return; db_prepare(&q, "PRAGMA table_info(ticket)"); while( db_step(&q)==SQLITE4_ROW ){ const char *zField = db_column_text(&q, 1); if( strncmp(zField,"tkt_",4)==0 ) continue; if( nField%10==0 ){ azField = fossil_realloc(azField, sizeof(azField)*3*(nField+10) ); } azField[nField] = mprintf("%s", zField); nField++; |
︙ | ︙ | |||
101 102 103 104 105 106 107 | const char *zName; Stmt q; int i, n, size, j; zName = PD("name","-none-"); db_prepare(&q, "SELECT datetime(tkt_mtime,'localtime') AS tkt_datetime, *" " FROM ticket WHERE tkt_uuid GLOB '%q*'", zName); | | | 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | const char *zName; Stmt q; int i, n, size, j; zName = PD("name","-none-"); db_prepare(&q, "SELECT datetime(tkt_mtime,'localtime') AS tkt_datetime, *" " FROM ticket WHERE tkt_uuid GLOB '%q*'", zName); if( db_step(&q)==SQLITE4_ROW ){ n = db_column_count(&q); for(i=0; i<n; i++){ const char *zVal = db_column_text(&q, i); const char *zName = db_column_name(&q, i); char *zRevealed = 0; if( zVal==0 ){ zVal = ""; |
︙ | ︙ | |||
129 130 131 132 133 134 135 | } }else{ db_finalize(&q); db_prepare(&q, "PRAGMA table_info(ticket)"); if( Th_Fetch("tkt_uuid",&size)==0 ){ Th_Store("tkt_uuid",zName); } | | | 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | } }else{ db_finalize(&q); db_prepare(&q, "PRAGMA table_info(ticket)"); if( Th_Fetch("tkt_uuid",&size)==0 ){ Th_Store("tkt_uuid",zName); } while( db_step(&q)==SQLITE4_ROW ){ const char *zField = db_column_text(&q, 1); if( Th_Fetch(zField, &size)==0 ){ Th_Store(zField, ""); } } if( Th_Fetch("tkt_datetime",&size)==0 ){ Th_Store("tkt_datetime",""); |
︙ | ︙ | |||
218 219 220 221 222 223 224 | int createFlag = 1; fossil_free(zTag); db_multi_exec( "DELETE FROM ticket WHERE tkt_uuid=%Q", zTktUuid ); db_prepare(&q, "SELECT rid FROM tagxref WHERE tagid=%d ORDER BY mtime",tagid); | | | 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | int createFlag = 1; fossil_free(zTag); db_multi_exec( "DELETE FROM ticket WHERE tkt_uuid=%Q", zTktUuid ); db_prepare(&q, "SELECT rid FROM tagxref WHERE tagid=%d ORDER BY mtime",tagid); while( db_step(&q)==SQLITE4_ROW ){ int rid = db_column_int(&q, 0); pTicket = manifest_get(rid, CFTYPE_TICKET); if( pTicket ){ ticket_insert(pTicket, createFlag, rid); manifest_ticket_event(rid, pTicket, createFlag, tagid); manifest_destroy(pTicket); } |
︙ | ︙ | |||
274 275 276 277 278 279 280 | ** Repopulate the ticket table */ void ticket_rebuild(void){ Stmt q; ticket_create_table(1); db_begin_transaction(); db_prepare(&q,"SELECT tagname FROM tag WHERE tagname GLOB 'tkt-*'"); | | | 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | ** Repopulate the ticket table */ void ticket_rebuild(void){ Stmt q; ticket_create_table(1); db_begin_transaction(); db_prepare(&q,"SELECT tagname FROM tag WHERE tagname GLOB 'tkt-*'"); while( db_step(&q)==SQLITE4_ROW ){ const char *zName = db_column_text(&q, 0); int len; zName += 4; len = strlen(zName); if( len<20 || !validate16(zName, len) ) continue; ticket_rebuild_entry(zName); } |
︙ | ︙ | |||
341 342 343 344 345 346 347 | Stmt q; db_prepare(&q, "SELECT datetime(mtime,'localtime'), filename, user" " FROM attachment" " WHERE isLatest AND src!='' AND target=%Q" " ORDER BY mtime DESC", zFullName); | | | 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | Stmt q; db_prepare(&q, "SELECT datetime(mtime,'localtime'), filename, user" " FROM attachment" " WHERE isLatest AND src!='' AND target=%Q" " ORDER BY mtime DESC", zFullName); while( db_step(&q)==SQLITE4_ROW ){ const char *zDate = db_column_text(&q, 0); const char *zFile = db_column_text(&q, 1); const char *zUser = db_column_text(&q, 2); if( cnt==0 ){ @ <hr /><h2>Attachments:</h2> @ <ul> } |
︙ | ︙ | |||
623 624 625 626 627 628 629 | ** be well-formed. If everything is OK, return NULL. If something is ** amiss, then return a pointer to a string (obtained from malloc) that ** describes the problem. */ char *ticket_schema_check(const char *zSchema){ char *zErr = 0; int rc; | | | | | | | | | | | 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 | ** be well-formed. If everything is OK, return NULL. If something is ** amiss, then return a pointer to a string (obtained from malloc) that ** describes the problem. */ char *ticket_schema_check(const char *zSchema){ char *zErr = 0; int rc; sqlite4 *db; rc = sqlite4_open(0, ":memory:", &db, SQLITE4_OPEN_READWRITE); if( rc==SQLITE4_OK ){ rc = sqlite4_exec(db, zSchema, 0, 0, &zErr); if( rc!=SQLITE4_OK ){ sqlite4_close(db); return zErr; } rc = sqlite4_exec(db, "SELECT tkt_id, tkt_uuid, tkt_mtime FROM ticket", 0, 0, 0); sqlite4_close(db); if( rc!=SQLITE4_OK ){ zErr = mprintf("schema fails to define a valid ticket table " "containing all required fields"); return zErr; } } return 0; } |
︙ | ︙ | |||
682 683 684 685 686 687 688 | zTitle = mprintf("Check-Ins Associated With Ticket %h", zUuid); }else{ zTitle = mprintf("Timeline Of Ticket %h", zUuid); } style_header(zTitle); free(zTitle); | | | 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 | zTitle = mprintf("Check-Ins Associated With Ticket %h", zUuid); }else{ zTitle = mprintf("Timeline Of Ticket %h", zUuid); } style_header(zTitle); free(zTitle); sqlite4_snprintf(zGlobPattern, 6, "%s", zUuid); canonical16(zGlobPattern, strlen(zGlobPattern)); tagid = db_int(0, "SELECT tagid FROM tag WHERE tagname GLOB 'tkt-%q*'",zUuid); if( tagid==0 ){ @ No such ticket: %h(zUuid) style_footer(); return; } |
︙ | ︙ | |||
765 766 767 768 769 770 771 | "SELECT datetime(mtime,'localtime'), attachid, uuid, src, filename, user" " FROM attachment, blob" " WHERE target=(SELECT substr(tagname,5) FROM tag WHERE tagid=%d)" " AND blob.rid=attachid" " ORDER BY 1 DESC", tagid, tagid ); | | | 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 | "SELECT datetime(mtime,'localtime'), attachid, uuid, src, filename, user" " FROM attachment, blob" " WHERE target=(SELECT substr(tagname,5) FROM tag WHERE tagid=%d)" " AND blob.rid=attachid" " ORDER BY 1 DESC", tagid, tagid ); while( db_step(&q)==SQLITE4_ROW ){ Manifest *pTicket; char zShort[12]; const char *zDate = db_column_text(&q, 0); int rid = db_column_int(&q, 1); const char *zChngUuid = db_column_text(&q, 2); const char *zFile = db_column_text(&q, 4); memcpy(zShort, zChngUuid, 10); |
︙ | ︙ | |||
1040 1041 1042 1043 1044 1045 1046 | "SELECT datetime(mtime,'localtime'), attachid, uuid, src, filename, user" " FROM attachment, blob" " WHERE target=(SELECT substr(tagname,5) FROM tag WHERE tagid=%d)" " AND blob.rid=attachid" " ORDER BY 1 DESC", tagid, tagid ); | | | 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 | "SELECT datetime(mtime,'localtime'), attachid, uuid, src, filename, user" " FROM attachment, blob" " WHERE target=(SELECT substr(tagname,5) FROM tag WHERE tagid=%d)" " AND blob.rid=attachid" " ORDER BY 1 DESC", tagid, tagid ); while( db_step(&q)==SQLITE4_ROW ){ Manifest *pTicket; char zShort[12]; const char *zDate = db_column_text(&q, 0); int rid = db_column_int(&q, 1); const char *zChngUuid = db_column_text(&q, 2); const char *zFile = db_column_text(&q, 4); memcpy(zShort, zChngUuid, 10); |
︙ | ︙ |
Changes to src/undo.c.
︙ | ︙ | |||
32 33 34 35 36 37 38 | Stmt q; char *zFullname; db_prepare(&q, "SELECT content, existsflag, isExe, isLink FROM undo" " WHERE pathname=%Q AND redoflag=%d", zPathname, redoFlag ); | | | 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | Stmt q; char *zFullname; db_prepare(&q, "SELECT content, existsflag, isExe, isLink FROM undo" " WHERE pathname=%Q AND redoflag=%d", zPathname, redoFlag ); if( db_step(&q)==SQLITE4_ROW ){ int old_exists; int new_exists; int old_exe; int new_exe; int new_link; int old_link; Blob current; |
︙ | ︙ | |||
112 113 114 115 116 117 118 | Stmt q; db_prepare(&q, "SELECT pathname FROM undo" " WHERE redoflag=%d" " ORDER BY rowid", redoFlag ); | | | 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | Stmt q; db_prepare(&q, "SELECT pathname FROM undo" " WHERE redoflag=%d" " ORDER BY rowid", redoFlag ); while( db_step(&q)==SQLITE4_ROW ){ const char *zPathname = db_column_text(&q, 0); undo_one(zPathname, redoFlag); } db_finalize(&q); } /* |
︙ | ︙ | |||
397 398 399 400 401 402 403 | zCmd = undo_available==1 ? "undo" : "redo"; fossil_print("A %s is available for the following command:\n\n" " %s %s\n\n", zCmd, g.argv[0], db_lget("undo_cmdline", "???")); db_prepare(&q, "SELECT existsflag, pathname FROM undo ORDER BY pathname" ); | | | 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 | zCmd = undo_available==1 ? "undo" : "redo"; fossil_print("A %s is available for the following command:\n\n" " %s %s\n\n", zCmd, g.argv[0], db_lget("undo_cmdline", "???")); db_prepare(&q, "SELECT existsflag, pathname FROM undo ORDER BY pathname" ); while( db_step(&q)==SQLITE4_ROW ){ if( nChng==0 ){ fossil_print("The following file changes would occur if the " "command above is %sne:\n\n", zCmd); } nChng++; fossil_print("%s %s\n", db_column_int(&q,0) ? "UPDATE" : "DELETE", |
︙ | ︙ |
Changes to src/update.c.
︙ | ︙ | |||
280 281 282 283 284 285 286 | if( debugFlag ){ db_prepare(&q, "SELECT rowid, fn, fnt, chnged, ridv, ridt, isexe," " islinkv, islinkt FROM fv" ); | | | 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | if( debugFlag ){ db_prepare(&q, "SELECT rowid, fn, fnt, chnged, ridv, ridt, isexe," " islinkv, islinkt FROM fv" ); while( db_step(&q)==SQLITE4_ROW ){ fossil_print("%3d: ridv=%-4d ridt=%-4d chnged=%d isexe=%d" " islinkv=%d islinkt=%d\n", db_column_int(&q, 0), db_column_int(&q, 4), db_column_int(&q, 5), db_column_int(&q, 3), db_column_int(&q, 6), |
︙ | ︙ | |||
343 344 345 346 347 348 349 | db_prepare(&mtimeXfer, "UPDATE vfile SET mtime=(SELECT mtime FROM vfile WHERE id=:idv)" " WHERE id=:idt" ); assert( g.zLocalRoot!=0 ); assert( strlen(g.zLocalRoot)>1 ); assert( g.zLocalRoot[strlen(g.zLocalRoot)-1]=='/' ); | | | 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | db_prepare(&mtimeXfer, "UPDATE vfile SET mtime=(SELECT mtime FROM vfile WHERE id=:idv)" " WHERE id=:idt" ); assert( g.zLocalRoot!=0 ); assert( strlen(g.zLocalRoot)>1 ); assert( g.zLocalRoot[strlen(g.zLocalRoot)-1]=='/' ); while( db_step(&q)==SQLITE4_ROW ){ const char *zName = db_column_text(&q, 0); /* The filename from root */ int idv = db_column_int(&q, 1); /* VFILE entry for current */ int ridv = db_column_int(&q, 2); /* RecordID for current */ int idt = db_column_int(&q, 3); /* VFILE entry for target */ int ridt = db_column_int(&q, 4); /* RecordID for target */ int chnged = db_column_int(&q, 5); /* Current is edited */ const char *zNewName = db_column_text(&q,6);/* New filename */ |
︙ | ︙ | |||
469 470 471 472 473 474 475 | /* Report on conflicts */ if( !nochangeFlag ){ Stmt q; int nMerge = 0; db_prepare(&q, "SELECT uuid, id FROM vmerge JOIN blob ON merge=rid" " WHERE id<=0"); | | | 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 | /* Report on conflicts */ if( !nochangeFlag ){ Stmt q; int nMerge = 0; db_prepare(&q, "SELECT uuid, id FROM vmerge JOIN blob ON merge=rid" " WHERE id<=0"); while( db_step(&q)==SQLITE4_ROW ){ const char *zLabel = "merge"; switch( db_column_int(&q, 1) ){ case -1: zLabel = "cherrypick merge"; break; case -2: zLabel = "backout merge"; break; } fossil_warning("uncommitted %s against %S.", zLabel, db_column_text(&q, 0)); |
︙ | ︙ | |||
693 694 695 696 697 698 699 | } blob_zero(&record); db_prepare(&q, "SELECT name FROM torevert"); if( zRevision==0 ){ int vid = db_lget_int("checkout", 0); zRevision = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", vid); } | | | | 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 | } blob_zero(&record); db_prepare(&q, "SELECT name FROM torevert"); if( zRevision==0 ){ int vid = db_lget_int("checkout", 0); zRevision = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", vid); } while( db_step(&q)==SQLITE4_ROW ){ int isExe = 0; int isLink = 0; char *zFull; zFile = db_column_text(&q, 0); zFull = mprintf("%/%/", g.zLocalRoot, zFile); errCode = historical_version_of_file(zRevision, zFile, &record, &isLink, &isExe,2); if( errCode==2 ){ if( db_int(0, "SELECT rid FROM vfile WHERE pathname=%Q", zFile)==0 ){ fossil_print("UNMANAGE: %s\n", zFile); }else{ undo_save(zFile); file_delete(zFull); fossil_print("DELETE: %s\n", zFile); } db_multi_exec("DELETE FROM vfile WHERE pathname=%Q", zFile); }else{ sqlite4_int64 mtime; undo_save(zFile); if( file_wd_size(zFull)>=0 && (isLink || file_wd_islink(zFull)) ){ file_delete(zFull); } if( isLink ){ symlink_create(blob_str(&record), zFull); }else{ |
︙ | ︙ |
Changes to src/user.c.
︙ | ︙ | |||
224 225 226 227 228 229 230 | }else{ db_set("default-user", g.argv[3], 0); } } }else if( n>=2 && strncmp(g.argv[2],"list",n)==0 ){ Stmt q; db_prepare(&q, "SELECT login, info FROM user ORDER BY login"); | | | 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | }else{ db_set("default-user", g.argv[3], 0); } } }else if( n>=2 && strncmp(g.argv[2],"list",n)==0 ){ Stmt q; db_prepare(&q, "SELECT login, info FROM user ORDER BY login"); while( db_step(&q)==SQLITE4_ROW ){ fossil_print("%-12s %s\n", db_column_text(&q, 0), db_column_text(&q, 1)); } db_finalize(&q); }else if( n>=2 && strncmp(g.argv[2],"password",2)==0 ){ char *zPrompt; int uid; Blob pw; |
︙ | ︙ | |||
328 329 330 331 332 333 334 | if( attempt_user(fossil_getenv("USER")) ) return; db_prepare(&s, "SELECT uid, login FROM user" " WHERE login NOT IN ('anonymous','nobody','reader','developer')" ); | | | | 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | if( attempt_user(fossil_getenv("USER")) ) return; db_prepare(&s, "SELECT uid, login FROM user" " WHERE login NOT IN ('anonymous','nobody','reader','developer')" ); if( db_step(&s)==SQLITE4_ROW ){ g.userUid = db_column_int(&s, 0); g.zLogin = mprintf("%s", db_column_text(&s, 1)); } db_finalize(&s); if( g.userUid==0 ){ db_prepare(&s, "SELECT uid, login FROM user"); if( db_step(&s)==SQLITE4_ROW ){ g.userUid = db_column_int(&s, 0); g.zLogin = mprintf("%s", db_column_text(&s, 1)); } db_finalize(&s); } if( g.userUid==0 ){ |
︙ | ︙ | |||
366 367 368 369 370 371 372 | ** Convert all local password storage to use a SHA1 hash of the password ** rather than cleartext. Passwords that are already stored as the SHA1 ** has are unchanged. */ void user_hash_passwords_cmd(void){ if( g.argc!=3 ) usage("REPOSITORY"); db_open_repository(g.argv[2]); | | | 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | ** Convert all local password storage to use a SHA1 hash of the password ** rather than cleartext. Passwords that are already stored as the SHA1 ** has are unchanged. */ void user_hash_passwords_cmd(void){ if( g.argc!=3 ) usage("REPOSITORY"); db_open_repository(g.argv[2]); sqlite4_create_function(g.db, "shared_secret", 2, SQLITE4_UTF8, 0, sha1_shared_secret_sql_function, 0, 0); db_multi_exec( "UPDATE user SET pw=shared_secret(pw,login), mtime=now()" " WHERE length(pw)>0 AND length(pw)!=40" ); } |
︙ | ︙ | |||
437 438 439 440 441 442 443 | "%s/access_log?o=%d&n=%d&y=%d", g.zTop, skip>=n ? skip-n : 0, n, y); } rc = db_prepare_ignore_error(&q, blob_str(&sql)); @ <center><table border="1" cellpadding="5"> @ <tr><th width="33%%">Date</th><th width="34%%">User</th> @ <th width="33%%">IP Address</th></tr> | | | 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | "%s/access_log?o=%d&n=%d&y=%d", g.zTop, skip>=n ? skip-n : 0, n, y); } rc = db_prepare_ignore_error(&q, blob_str(&sql)); @ <center><table border="1" cellpadding="5"> @ <tr><th width="33%%">Date</th><th width="34%%">User</th> @ <th width="33%%">IP Address</th></tr> while( rc==SQLITE4_OK && db_step(&q)==SQLITE4_ROW ){ const char *zName = db_column_text(&q, 0); const char *zIP = db_column_text(&q, 1); const char *zDate = db_column_text(&q, 2); int bSuccess = db_column_int(&q, 3); cnt++; if( cnt>n ){ style_submenu_element("Older", "Older entries", |
︙ | ︙ |
Changes to src/verify.c.
︙ | ︙ | |||
116 117 118 119 120 121 122 | ** Verify all records in the repository. */ void verify_all_cmd(void){ Stmt q; int cnt = 0; db_must_be_within_tree(); db_prepare(&q, "SELECT rid FROM blob"); | | | 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | ** Verify all records in the repository. */ void verify_all_cmd(void){ Stmt q; int cnt = 0; db_must_be_within_tree(); db_prepare(&q, "SELECT rid FROM blob"); while( db_step(&q)==SQLITE4_ROW ){ int rid = db_column_int(&q, 0); verify_before_commit(rid); cnt++; assert( bag_count(&toVerify)==cnt ); } db_finalize(&q); verify_at_commit(); |
︙ | ︙ |
Changes to src/vfile.c.
︙ | ︙ | |||
32 33 34 35 36 37 38 | ** Find its rid. */ int fast_uuid_to_rid(const char *zUuid){ static Stmt q; int rid; db_static_prepare(&q, "SELECT rid FROM blob WHERE uuid=:uuid"); db_bind_text(&q, ":uuid", zUuid); | | | 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | ** Find its rid. */ int fast_uuid_to_rid(const char *zUuid){ static Stmt q; int rid; db_static_prepare(&q, "SELECT rid FROM blob WHERE uuid=:uuid"); db_bind_text(&q, ":uuid", zUuid); if( db_step(&q)==SQLITE4_ROW ){ rid = db_column_int(&q, 0); }else{ rid = 0; } db_reset(&q); return rid; } |
︙ | ︙ | |||
88 89 90 91 92 93 94 | } db_begin_transaction(); p = manifest_get(vid, CFTYPE_MANIFEST); if( p==0 ) return; db_multi_exec("DELETE FROM vfile WHERE vid=%d", vid); db_prepare(&ins, | | > | | | 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | } db_begin_transaction(); p = manifest_get(vid, CFTYPE_MANIFEST); if( p==0 ) return; db_multi_exec("DELETE FROM vfile WHERE vid=%d", vid); db_prepare(&ins, "INSERT INTO vfile(id,vid,isexe,islink,rid,mrid,pathname) " " VALUES(1+(SELECT coalesce(max(id),0) FROM vfile)," ":vid,:isexe,:islink,:id,:id,:name)"); db_prepare(&ridq, "SELECT rid,size FROM blob WHERE uuid=:uuid"); db_bind_int(&ins, ":vid", vid); manifest_file_rewind(p); while( (pFile = manifest_file_next(p,0))!=0 ){ if( pFile->zUuid==0 || uuid_is_shunned(pFile->zUuid) ) continue; db_bind_text(&ridq, ":uuid", pFile->zUuid); if( db_step(&ridq)==SQLITE4_ROW ){ rid = db_column_int(&ridq, 0); size = db_column_int(&ridq, 0); }else{ rid = 0; size = 0; } db_reset(&ridq); |
︙ | ︙ | |||
158 159 160 161 162 163 164 | int useMtime = useSha1sum==0 && db_get_boolean("mtime-changes", 1); db_begin_transaction(); db_prepare(&q, "SELECT id, %Q || pathname," " vfile.mrid, deleted, chnged, uuid, size, mtime" " FROM vfile LEFT JOIN blob ON vfile.mrid=blob.rid" " WHERE vid=%d ", g.zLocalRoot, vid); | | | 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | int useMtime = useSha1sum==0 && db_get_boolean("mtime-changes", 1); db_begin_transaction(); db_prepare(&q, "SELECT id, %Q || pathname," " vfile.mrid, deleted, chnged, uuid, size, mtime" " FROM vfile LEFT JOIN blob ON vfile.mrid=blob.rid" " WHERE vid=%d ", g.zLocalRoot, vid); while( db_step(&q)==SQLITE4_ROW ){ int id, rid, isDeleted; const char *zName; int chnged = 0; int oldChnged; i64 oldMtime; i64 currentMtime; i64 origSize; |
︙ | ︙ | |||
257 258 259 260 261 262 263 | }else{ assert( vid==0 && id>0 ); db_prepare(&q, "SELECT id, %Q || pathname, mrid, isexe, islink" " FROM vfile" " WHERE id=%d AND mrid>0", g.zLocalRoot, id); } | | | 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | }else{ assert( vid==0 && id>0 ); db_prepare(&q, "SELECT id, %Q || pathname, mrid, isexe, islink" " FROM vfile" " WHERE id=%d AND mrid>0", g.zLocalRoot, id); } while( db_step(&q)==SQLITE4_ROW ){ int id, rid, isExe, isLink; const char *zName; id = db_column_int(&q, 0); zName = db_column_text(&q, 1); rid = db_column_int(&q, 2); isExe = db_column_int(&q, 3); |
︙ | ︙ | |||
322 323 324 325 326 327 328 | /* ** Delete from the disk every file in VFILE vid. */ void vfile_unlink(int vid){ Stmt q; db_prepare(&q, "SELECT %Q || pathname FROM vfile" " WHERE vid=%d AND mrid>0", g.zLocalRoot, vid); | | | 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | /* ** Delete from the disk every file in VFILE vid. */ void vfile_unlink(int vid){ Stmt q; db_prepare(&q, "SELECT %Q || pathname FROM vfile" " WHERE vid=%d AND mrid>0", g.zLocalRoot, vid); while( db_step(&q)==SQLITE4_ROW ){ const char *zName; zName = db_column_text(&q, 0); file_delete(zName); } db_finalize(&q); db_multi_exec("UPDATE vfile SET mtime=NULL WHERE vid=%d AND mrid>0", vid); |
︙ | ︙ | |||
478 479 480 481 482 483 484 | "SELECT %Q || pathname, pathname, origname, is_selected(id), rid" " FROM vfile" " WHERE (NOT deleted OR NOT is_selected(id)) AND vid=%d" " ORDER BY if_selected(id, pathname, origname) /*scan*/", g.zLocalRoot, vid ); md5sum_init(); | | | | | 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 | "SELECT %Q || pathname, pathname, origname, is_selected(id), rid" " FROM vfile" " WHERE (NOT deleted OR NOT is_selected(id)) AND vid=%d" " ORDER BY if_selected(id, pathname, origname) /*scan*/", g.zLocalRoot, vid ); md5sum_init(); while( db_step(&q)==SQLITE4_ROW ){ const char *zFullpath = db_column_text(&q, 0); const char *zName = db_column_text(&q, 1); int isSelected = db_column_int(&q, 3); if( isSelected ){ md5sum_step_text(zName, -1); if( file_wd_islink(zFullpath) ){ /* Instead of file content, use link destination path */ Blob pathBuf; sqlite4_snprintf(zBuf, sizeof(zBuf), " %ld\n", blob_read_link(&pathBuf, zFullpath)); md5sum_step_text(zBuf, -1); md5sum_step_text(blob_str(&pathBuf), -1); blob_reset(&pathBuf); }else{ in = fossil_fopen(zFullpath,"rb"); if( in==0 ){ md5sum_step_text(" 0\n", -1); continue; } fseek(in, 0L, SEEK_END); sqlite4_snprintf(zBuf, sizeof(zBuf), " %ld\n", ftell(in)); fseek(in, 0L, SEEK_SET); md5sum_step_text(zBuf, -1); /*printf("%s %s %s",md5sum_current_state(),zName,zBuf); fflush(stdout);*/ for(;;){ int n; n = fread(zBuf, 1, sizeof(zBuf), in); if( n<=0 ) break; |
︙ | ︙ | |||
524 525 526 527 528 529 530 | Blob file; if( zOrigName ) zName = zOrigName; if( rid>0 ){ md5sum_step_text(zName, -1); blob_zero(&file); content_get(rid, &file); | | | | | | | 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 | Blob file; if( zOrigName ) zName = zOrigName; if( rid>0 ){ md5sum_step_text(zName, -1); blob_zero(&file); content_get(rid, &file); sqlite4_snprintf(zBuf, sizeof(zBuf), " %d\n", blob_size(&file)); md5sum_step_text(zBuf, -1); md5sum_step_blob(&file); blob_reset(&file); } } } db_finalize(&q); md5sum_finish(pOut); } /* ** Write a BLOB into a random filename. Return the name of the file. */ static char *write_blob_to_temp_file(Blob *pBlob){ sqlite4_uint64 r; char *zOut = 0; do{ sqlite4_free(0, zOut); sqlite4_randomness(0, 8, &r); zOut = sqlite4_mprintf(0, "file-%08llx", r); }while( file_size(zOut)>=0 ); blob_write_to_file(pBlob, zOut); return zOut; } /* ** Do a file-by-file comparison of the content of the repository and |
︙ | ︙ | |||
568 569 570 571 572 573 574 | db_prepare(&q, "SELECT %Q || pathname, pathname, rid FROM vfile" " WHERE NOT deleted AND vid=%d AND is_selected(id)" " ORDER BY if_selected(id, pathname, origname) /*scan*/", g.zLocalRoot, vid ); md5sum_init(); | | | 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | db_prepare(&q, "SELECT %Q || pathname, pathname, rid FROM vfile" " WHERE NOT deleted AND vid=%d AND is_selected(id)" " ORDER BY if_selected(id, pathname, origname) /*scan*/", g.zLocalRoot, vid ); md5sum_init(); while( db_step(&q)==SQLITE4_ROW ){ const char *zFullpath = db_column_text(&q, 0); const char *zName = db_column_text(&q, 1); int rid = db_column_int(&q, 2); blob_zero(&disk); if( file_wd_islink(zFullpath) ){ rc = blob_read_link(&disk, zFullpath); |
︙ | ︙ | |||
592 593 594 595 596 597 598 | content_get(rid, &repo); if( blob_size(&repo)!=blob_size(&disk) ){ fossil_print("ERROR: [%s] is %d bytes on disk but %d in the repository\n", zName, blob_size(&disk), blob_size(&repo)); zOut = write_blob_to_temp_file(&repo); fossil_print("NOTICE: Repository version of [%s] stored in [%s]\n", zName, zOut); | | | | 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 | content_get(rid, &repo); if( blob_size(&repo)!=blob_size(&disk) ){ fossil_print("ERROR: [%s] is %d bytes on disk but %d in the repository\n", zName, blob_size(&disk), blob_size(&repo)); zOut = write_blob_to_temp_file(&repo); fossil_print("NOTICE: Repository version of [%s] stored in [%s]\n", zName, zOut); sqlite4_free(0, zOut); blob_reset(&disk); blob_reset(&repo); continue; } if( blob_compare(&repo, &disk) ){ fossil_print( "ERROR: [%s] is different on disk compared to the repository\n", zName); zOut = write_blob_to_temp_file(&repo); fossil_print("NOTICE: Repository version of [%s] stored in [%s]\n", zName, zOut); sqlite4_free(0, zOut); } blob_reset(&disk); blob_reset(&repo); } db_finalize(&q); } |
︙ | ︙ | |||
634 635 636 637 638 639 640 | " FROM vfile" " WHERE (NOT deleted OR NOT is_selected(id))" " AND rid>0 AND vid=%d" " ORDER BY if_selected(id,pathname,origname) /*scan*/", vid); blob_zero(&file); md5sum_init(); | | | | 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 | " FROM vfile" " WHERE (NOT deleted OR NOT is_selected(id))" " AND rid>0 AND vid=%d" " ORDER BY if_selected(id,pathname,origname) /*scan*/", vid); blob_zero(&file); md5sum_init(); while( db_step(&q)==SQLITE4_ROW ){ const char *zName = db_column_text(&q, 0); const char *zOrigName = db_column_text(&q, 1); int rid = db_column_int(&q, 2); int isSelected = db_column_int(&q, 3); if( zOrigName && !isSelected ) zName = zOrigName; md5sum_step_text(zName, -1); content_get(rid, &file); sqlite4_snprintf(zBuf, sizeof(zBuf), " %d\n", blob_size(&file)); md5sum_step_text(zBuf, -1); /*printf("%s %s %s",md5sum_current_state(),zName,zBuf); fflush(stdout);*/ md5sum_step_blob(&file); blob_reset(&file); } db_finalize(&q); md5sum_finish(pOut); |
︙ | ︙ | |||
687 688 689 690 691 692 693 | } manifest_file_rewind(pManifest); while( (pFile = manifest_file_next(pManifest,0))!=0 ){ if( pFile->zUuid==0 ) continue; fid = uuid_to_rid(pFile->zUuid, 0); md5sum_step_text(pFile->zName, -1); content_get(fid, &file); | | | 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 | } manifest_file_rewind(pManifest); while( (pFile = manifest_file_next(pManifest,0))!=0 ){ if( pFile->zUuid==0 ) continue; fid = uuid_to_rid(pFile->zUuid, 0); md5sum_step_text(pFile->zName, -1); content_get(fid, &file); sqlite4_snprintf(zBuf, sizeof(zBuf), " %d\n", blob_size(&file)); md5sum_step_text(zBuf, -1); md5sum_step_blob(&file); blob_reset(&file); } if( pManOut ){ if( pManifest->zRepoCksum ){ blob_append(pManOut, pManifest->zRepoCksum, -1); |
︙ | ︙ |
Changes to src/wiki.c.
︙ | ︙ | |||
211 212 213 214 215 216 217 | db_prepare(&q, "SELECT datetime(mtime,'localtime'), filename, user" " FROM attachment" " WHERE isLatest AND src!='' AND target=%Q" " ORDER BY mtime DESC", zPageName); | | | 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | db_prepare(&q, "SELECT datetime(mtime,'localtime'), filename, user" " FROM attachment" " WHERE isLatest AND src!='' AND target=%Q" " ORDER BY mtime DESC", zPageName); while( db_step(&q)==SQLITE4_ROW ){ const char *zDate = db_column_text(&q, 0); const char *zFile = db_column_text(&q, 1); const char *zUser = db_column_text(&q, 2); if( cnt==0 ){ @ <hr /><h2>Attachments:</h2> @ <ul> } |
︙ | ︙ | |||
666 667 668 669 670 671 672 | if( showAll ){ style_submenu_element("Active", "Only Active Pages", "%s/wcontent", g.zTop); }else{ style_submenu_element("All", "All", "%s/wcontent?all=1", g.zTop); } @ <ul> wiki_prepare_page_list(&q); | | | 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 | if( showAll ){ style_submenu_element("Active", "Only Active Pages", "%s/wcontent", g.zTop); }else{ style_submenu_element("All", "All", "%s/wcontent?all=1", g.zTop); } @ <ul> wiki_prepare_page_list(&q); while( db_step(&q)==SQLITE4_ROW ){ const char *zName = db_column_text(&q, 0); int size = db_column_int(&q, 1); if( size>0 ){ @ <li>%z(href("%R/wiki?name=%T",zName))%h(zName)</a></li> }else if( showAll ){ @ <li>%z(href("%R/wiki?name=%T",zName))<s>%h(zName)</s></a></li> } |
︙ | ︙ | |||
698 699 700 701 702 703 704 | zTitle = PD("title","*"); style_header("Wiki Pages Found"); @ <ul> db_prepare(&q, "SELECT substr(tagname, 6, 1000) FROM tag WHERE tagname like 'wiki-%%%q%%'" " ORDER BY lower(tagname) /*sort*/" , zTitle); | | | 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 | zTitle = PD("title","*"); style_header("Wiki Pages Found"); @ <ul> db_prepare(&q, "SELECT substr(tagname, 6, 1000) FROM tag WHERE tagname like 'wiki-%%%q%%'" " ORDER BY lower(tagname) /*sort*/" , zTitle); while( db_step(&q)==SQLITE4_ROW ){ const char *zName = db_column_text(&q, 0); @ <li>%z(href("%R/wiki?name=%T",zName))%h(zName)</a></li> } db_finalize(&q); @ </ul> style_footer(); } |
︙ | ︙ | |||
967 968 969 970 971 972 973 | }else if( strncmp(g.argv[2],"list",n)==0 ){ Stmt q; db_prepare(&q, "SELECT substr(tagname, 6) FROM tag WHERE tagname GLOB 'wiki-*'" " ORDER BY lower(tagname) /*sort*/" ); | | | 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 | }else if( strncmp(g.argv[2],"list",n)==0 ){ Stmt q; db_prepare(&q, "SELECT substr(tagname, 6) FROM tag WHERE tagname GLOB 'wiki-*'" " ORDER BY lower(tagname) /*sort*/" ); while( db_step(&q)==SQLITE4_ROW ){ const char *zName = db_column_text(&q, 0); fossil_print( "%s\n",zName); } db_finalize(&q); }else { goto wiki_cmd_usage; } return; wiki_cmd_usage: usage("export|create|commit|list ..."); } |
Changes to src/wikiformat.c.
︙ | ︙ | |||
951 952 953 954 955 956 957 | int rc; db_static_prepare(&q, "SELECT 1 FROM blob WHERE uuid>=:u AND +uuid GLOB (:u || '*')" ); db_bind_text(&q, ":u", zUuid); rc = db_step(&q); db_reset(&q); | | | 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 | int rc; db_static_prepare(&q, "SELECT 1 FROM blob WHERE uuid>=:u AND +uuid GLOB (:u || '*')" ); db_bind_text(&q, ":u", zUuid); rc = db_step(&q); db_reset(&q); return rc==SQLITE4_ROW; } /* ** zTarget is guaranteed to be a UUID. It might be the UUID of a ticket. ** If it is, store in *pClosed a true or false depending on whether or not ** the ticket is closed and return true. If zTarget ** is not the UUID of a ticket, return false. |
︙ | ︙ | |||
986 987 988 989 990 991 992 | " WHERE tkt_uuid>=:lwr AND tkt_uuid<:upr", zClosedExpr ); once = 0; } db_bind_text(&q, ":lwr", zLower); db_bind_text(&q, ":upr", zUpper); | | | 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 | " WHERE tkt_uuid>=:lwr AND tkt_uuid<:upr", zClosedExpr ); once = 0; } db_bind_text(&q, ":lwr", zLower); db_bind_text(&q, ":upr", zUpper); if( db_step(&q)==SQLITE4_ROW ){ rc = 1; *pClosed = db_column_int(&q, 0); }else{ rc = 0; } db_reset(&q); return rc; |
︙ | ︙ | |||
1095 1096 1097 1098 1099 1100 1101 | }else if( wiki_name_is_wellformed((const unsigned char *)zTarget) ){ blob_appendf(p->pOut, "<a href=\"%s/wiki?name=%T\">", g.zTop, zTarget); }else{ blob_appendf(p->pOut, "<span class=\"brokenlink\">[%h]</span>", zTarget); zTerm = ""; } assert( strlen(zTerm)<nClose ); | | | 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 | }else if( wiki_name_is_wellformed((const unsigned char *)zTarget) ){ blob_appendf(p->pOut, "<a href=\"%s/wiki?name=%T\">", g.zTop, zTarget); }else{ blob_appendf(p->pOut, "<span class=\"brokenlink\">[%h]</span>", zTarget); zTerm = ""; } assert( strlen(zTerm)<nClose ); sqlite4_snprintf(zClose, nClose, "%s", zTerm); } /* ** Check to see if the given parsed markup is the correct ** </verbatim> tag. */ static int endVerbatim(Renderer *p, ParsedMarkup *pMarkup){ |
︙ | ︙ |
Changes to src/winhttp.c.
︙ | ︙ | |||
70 71 72 73 74 75 76 | int wanted = 0; char *z; char zRequestFName[100]; char zReplyFName[100]; char zCmd[2000]; /* Command-line to process the request */ char zHdr[2000]; /* The HTTP request header */ | | | | 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | int wanted = 0; char *z; char zRequestFName[100]; char zReplyFName[100]; char zCmd[2000]; /* Command-line to process the request */ char zHdr[2000]; /* The HTTP request header */ sqlite4_snprintf(zRequestFName, sizeof(zRequestFName), "%s_in%d.txt", zTempPrefix, p->id); sqlite4_snprintf(zReplayFName, sizeof(zReplyFName), "%s_out%d.txt", zTempPrefix, p->id); amt = 0; while( amt<sizeof(zHdr) ){ got = recv(p->s, &zHdr[amt], sizeof(zHdr)-1-amt, 0); if( got==SOCKET_ERROR ) goto end_request; if( got==0 ){ wanted = 0; |
︙ | ︙ | |||
106 107 108 109 110 111 112 | }else{ break; } wanted -= got; } fclose(out); out = 0; | | | 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | }else{ break; } wanted -= got; } fclose(out); out = 0; sqlite4_snprintf(zCmd, sizeof(zCmd), "\"%s\" http \"%s\" %s %s %s --nossl%s", fossil_nameofexe(), g.zRepositoryName, zRequestFName, zReplyFName, inet_ntoa(p->addr.sin_addr), p->zOptions ); fossil_system(zCmd); in = fossil_fopen(zReplyFName, "rb"); if( in ){ while( (got = fread(zHdr, 1, sizeof(zHdr), in))>0 ){ |
︙ | ︙ |
Changes to src/xfer.c.
︙ | ︙ | |||
55 56 57 58 59 60 61 | */ static int rid_from_uuid(Blob *pUuid, int phantomize, int isPrivate){ static Stmt q; int rid; db_static_prepare(&q, "SELECT rid FROM blob WHERE uuid=:uuid"); db_bind_str(&q, ":uuid", pUuid); | | | 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | */ static int rid_from_uuid(Blob *pUuid, int phantomize, int isPrivate){ static Stmt q; int rid; db_static_prepare(&q, "SELECT rid FROM blob WHERE uuid=:uuid"); db_bind_str(&q, ":uuid", pUuid); if( db_step(&q)==SQLITE4_ROW ){ rid = db_column_int(&q, 0); }else{ rid = 0; } db_reset(&q); if( rid==0 && phantomize ){ rid = content_new(blob_str(pUuid), isPrivate); |
︙ | ︙ | |||
463 464 465 466 467 468 469 | " FROM blob LEFT JOIN delta ON (blob.rid=delta.rid)" " WHERE blob.rid=:rid" " AND blob.size>=0" " AND NOT EXISTS(SELECT 1 FROM shun WHERE shun.uuid=blob.uuid)" ); db_bind_int(&q1, ":rid", rid); rc = db_step(&q1); | | | 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 | " FROM blob LEFT JOIN delta ON (blob.rid=delta.rid)" " WHERE blob.rid=:rid" " AND blob.size>=0" " AND NOT EXISTS(SELECT 1 FROM shun WHERE shun.uuid=blob.uuid)" ); db_bind_int(&q1, ":rid", rid); rc = db_step(&q1); if( rc==SQLITE4_ROW ){ zUuid = db_column_text(&q1, 0); szU = db_column_int(&q1, 1); szC = db_column_bytes(&q1, 2); zContent = db_column_raw(&q1, 2); srcIsPrivate = db_column_int(&q1, 3); zDelta = db_column_text(&q1, 4); if( isPrivate ) blob_append(pXfer->pOut, "private\n", -1); |
︙ | ︙ | |||
512 513 514 515 516 517 518 | Stmt q; db_prepare(&q, "SELECT uuid FROM phantom JOIN blob USING(rid)" " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid) %s", (pXfer->syncPrivate ? "" : " AND NOT EXISTS(SELECT 1 FROM private WHERE rid=blob.rid)") ); | | | 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 | Stmt q; db_prepare(&q, "SELECT uuid FROM phantom JOIN blob USING(rid)" " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid) %s", (pXfer->syncPrivate ? "" : " AND NOT EXISTS(SELECT 1 FROM private WHERE rid=blob.rid)") ); while( db_step(&q)==SQLITE4_ROW && maxReq-- > 0 ){ const char *zUuid = db_column_text(&q, 0); blob_appendf(pXfer->pOut, "gimme %s\n", zUuid); pXfer->nGimmeSent++; } db_finalize(&q); } |
︙ | ︙ | |||
579 580 581 582 583 584 585 | db_prepare(&q, "SELECT pw, cap, uid FROM user" " WHERE login=%Q" " AND login NOT IN ('anonymous','nobody','developer','reader')" " AND length(pw)>0", zLogin ); | | | 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 | db_prepare(&q, "SELECT pw, cap, uid FROM user" " WHERE login=%Q" " AND login NOT IN ('anonymous','nobody','developer','reader')" " AND length(pw)>0", zLogin ); if( db_step(&q)==SQLITE4_ROW ){ int szPw; Blob pw, combined, hash; blob_zero(&pw); db_ephemeral_blob(&q, 0, &pw); szPw = blob_size(&pw); blob_zero(&combined); blob_copy(&combined, pNonce); |
︙ | ︙ | |||
632 633 634 635 636 637 638 | ** This is really just an optimization. If you clear the ** unsent table, all the right files will still get transferred. ** It just might require an extra round trip or two. */ static void send_unsent(Xfer *pXfer){ Stmt q; db_prepare(&q, "SELECT rid FROM unsent EXCEPT SELECT rid FROM private"); | | | 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 | ** This is really just an optimization. If you clear the ** unsent table, all the right files will still get transferred. ** It just might require an extra round trip or two. */ static void send_unsent(Xfer *pXfer){ Stmt q; db_prepare(&q, "SELECT rid FROM unsent EXCEPT SELECT rid FROM private"); while( db_step(&q)==SQLITE4_ROW ){ int rid = db_column_int(&q, 0); send_file(pXfer, rid, 0, 0); } db_finalize(&q); db_multi_exec("DELETE FROM unsent"); } |
︙ | ︙ | |||
674 675 676 677 678 679 680 | blob_zero(&deleteWhere); db_prepare(&q, "SELECT uuid FROM unclustered, blob" " WHERE NOT EXISTS(SELECT 1 FROM phantom" " WHERE rid=unclustered.rid)" " AND unclustered.rid=blob.rid" " AND NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)" " ORDER BY 1"); | | | 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 | blob_zero(&deleteWhere); db_prepare(&q, "SELECT uuid FROM unclustered, blob" " WHERE NOT EXISTS(SELECT 1 FROM phantom" " WHERE rid=unclustered.rid)" " AND unclustered.rid=blob.rid" " AND NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)" " ORDER BY 1"); while( db_step(&q)==SQLITE4_ROW ){ blob_appendf(&cluster, "M %s\n", db_column_text(&q, 0)); nRow++; if( nRow>=800 && nUncl>nRow+100 ){ md5sum_blob(&cluster, &cksum); blob_appendf(&cluster, "Z %b\n", &cksum); blob_reset(&cksum); rid = content_put(&cluster); |
︙ | ︙ | |||
712 713 714 715 716 717 718 | ** Send igot messages for every private artifact */ static int send_private(Xfer *pXfer){ int cnt = 0; Stmt q; if( pXfer->syncPrivate ){ db_prepare(&q, "SELECT uuid FROM private JOIN blob USING(rid)"); | | | 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 | ** Send igot messages for every private artifact */ static int send_private(Xfer *pXfer){ int cnt = 0; Stmt q; if( pXfer->syncPrivate ){ db_prepare(&q, "SELECT uuid FROM private JOIN blob USING(rid)"); while( db_step(&q)==SQLITE4_ROW ){ blob_appendf(pXfer->pOut, "igot %s 1\n", db_column_text(&q,0)); cnt++; } db_finalize(&q); } return cnt; } |
︙ | ︙ | |||
734 735 736 737 738 739 740 | int cnt = 0; db_prepare(&q, "SELECT uuid FROM unclustered JOIN blob USING(rid)" " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)" " AND NOT EXISTS(SELECT 1 FROM phantom WHERE rid=blob.rid)" " AND NOT EXISTS(SELECT 1 FROM private WHERE rid=blob.rid)" ); | | | | 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 | int cnt = 0; db_prepare(&q, "SELECT uuid FROM unclustered JOIN blob USING(rid)" " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)" " AND NOT EXISTS(SELECT 1 FROM phantom WHERE rid=blob.rid)" " AND NOT EXISTS(SELECT 1 FROM private WHERE rid=blob.rid)" ); while( db_step(&q)==SQLITE4_ROW ){ blob_appendf(pXfer->pOut, "igot %s\n", db_column_text(&q, 0)); cnt++; } db_finalize(&q); return cnt; } /* ** Send an igot message for every artifact. */ static void send_all(Xfer *pXfer){ Stmt q; db_prepare(&q, "SELECT uuid FROM blob " " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)" " AND NOT EXISTS(SELECT 1 FROM private WHERE rid=blob.rid)" " AND NOT EXISTS(SELECT 1 FROM phantom WHERE rid=blob.rid)" ); while( db_step(&q)==SQLITE4_ROW ){ blob_appendf(pXfer->pOut, "igot %s\n", db_column_text(&q, 0)); } db_finalize(&q); } /* ** Send a single old-style config card for configuration item zName. |
︙ | ︙ | |||
1476 1477 1478 1479 1480 1481 1482 | /* Process the reply that came back from the server */ while( blob_line(&recv, &xfer.line) ){ if( blob_buffer(&xfer.line)[0]=='#' ){ const char *zLine = blob_buffer(&xfer.line); if( memcmp(zLine, "# timestamp ", 12)==0 ){ char zTime[20]; double rDiff; | | | 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 | /* Process the reply that came back from the server */ while( blob_line(&recv, &xfer.line) ){ if( blob_buffer(&xfer.line)[0]=='#' ){ const char *zLine = blob_buffer(&xfer.line); if( memcmp(zLine, "# timestamp ", 12)==0 ){ char zTime[20]; double rDiff; sqlite4_snprintf(zTime, sizeof(zTime), "%.19s", &zLine[12]); rDiff = db_double(9e99, "SELECT julianday('%q') - %.17g", zTime, rArrivalTime); if( rDiff>9e98 || rDiff<-9e98 ) rDiff = 0.0; if( (rDiff*24.0*3600.0) > 10.0 ){ fossil_warning("*** time skew *** server is fast by %s", db_timespan_name(rDiff)); g.clockSkewSeen = 1; |
︙ | ︙ |
Changes to win/Makefile.PellesCGMake.
︙ | ︙ | |||
78 79 80 81 82 83 84 | # define the special utilities files, needed to generate # the automatically generated source files UTILS=translate.exe mkindex.exe makeheaders.exe UTILS_OBJ=$(UTILS:.exe=.obj) UTILS_SRC=$(foreach uf,$(UTILS),$(SRCDIR)$(uf:.exe=.c)) # define the sqlite files, which need special flags on compile | | | | | 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | # define the special utilities files, needed to generate # the automatically generated source files UTILS=translate.exe mkindex.exe makeheaders.exe UTILS_OBJ=$(UTILS:.exe=.obj) UTILS_SRC=$(foreach uf,$(UTILS),$(SRCDIR)$(uf:.exe=.c)) # define the sqlite files, which need special flags on compile SQLITESRC=sqlite4.c ORIGSQLITESRC=$(foreach sf,$(SQLITESRC),$(SRCDIR)$(sf)) SQLITEOBJ=$(foreach sf,$(SQLITESRC),$(sf:.c=.obj)) SQLITEDEFINES=-DSQLITE4_OMIT_LOAD_EXTENSION=1 -DSQLITE4_THREADSAFE=0 -DSQLITE4_DEFAULT_FILE_FORMAT=4 -Dlocaltime=fossil_localtime -DSQLITE4_ENABLE_LOCKING_STYLE=0 # define the sqlite shell files, which need special flags on compile SQLITESHELLSRC=shell.c ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf)) SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj)) SQLITESHELLDEFINES=-Dmain=sqlite4_shell -DSQLITE4_OMIT_LOAD_EXTENSION=1 # define the th scripting files, which need special flags on compile THSRC=th.c th_lang.c ORIGTHSRC=$(foreach sf,$(THSRC),$(SRCDIR)$(sf)) THOBJ=$(foreach sf,$(THSRC),$(sf:.c=.obj)) # define the zlib files, needed by this compile |
︙ | ︙ | |||
143 144 145 146 147 148 149 | mkindex.exe $(TRANSLATEDSRC) >$@ # extracting version info from manifest VERSION.h: version.exe ..\manifest.uuid ..\manifest ..\VERSION version.exe ..\manifest.uuid ..\manifest ..\VERSION > $@ # generate the simplified headers | | | | 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | mkindex.exe $(TRANSLATEDSRC) >$@ # extracting version info from manifest VERSION.h: version.exe ..\manifest.uuid ..\manifest ..\VERSION version.exe ..\manifest.uuid ..\manifest ..\VERSION > $@ # generate the simplified headers headers: makeheaders.exe page_index.h VERSION.h ../src/sqlite4.h ../src/th.h VERSION.h makeheaders.exe $(foreach ts,$(TRANSLATEDSRC),$(ts):$(ts:_.c=.h)) ../src/sqlite4.h ../src/th.h VERSION.h echo Done >$@ # compile C sources with relevant options $(TRANSLATEDOBJ): %_.obj: %_.c %.h $(CC) $(CCFLAGS) $(INCLUDE) "$<" -Fo"$@" |
︙ | ︙ |
Changes to win/Makefile.dmc.
︙ | ︙ | |||
22 23 24 25 26 27 28 | SSL = CFLAGS = -o BCC = $(DMDIR)\bin\dmc $(CFLAGS) TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL) LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32 | | | | | | | | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | SSL = CFLAGS = -o BCC = $(DMDIR)\bin\dmc $(CFLAGS) TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL) LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32 SQLITE4_OPTIONS = -DSQLITE4_OMIT_LOAD_EXTENSION=1 -DSQLITE4_THREADSAFE=0 -DSQLITE4_DEFAULT_FILE_FORMAT=4 -DSQLITE4_ENABLE_STAT3 -Dlocaltime=fossil_localtime -DSQLITE4_ENABLE_LOCKING_STYLE=0 SRC = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c db_.c delta_.c deltacmd_.c descendants_.c diff_.c diffcmd_.c doc_.c encode_.c event_.c export_.c file_.c finfo_.c glob_.c graph_.c gzip_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c login_.c main_.c manifest_.c md5_.c merge_.c merge3_.c name_.c path_.c pivot_.c popen_.c pqueue_.c printf_.c rebuild_.c report_.c rss_.c schema_.c search_.c setup_.c sha1_.c shun_.c skins_.c sqlcmd_.c stash_.c stat_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c update_.c url_.c user_.c verify_.c vfile_.c wiki_.c wikiformat_.c winhttp_.c xfer_.c xfersetup_.c zip_.c OBJ = $(OBJDIR)\add$O $(OBJDIR)\allrepo$O $(OBJDIR)\attach$O $(OBJDIR)\bag$O $(OBJDIR)\bisect$O $(OBJDIR)\blob$O $(OBJDIR)\branch$O $(OBJDIR)\browse$O $(OBJDIR)\captcha$O $(OBJDIR)\cgi$O $(OBJDIR)\checkin$O $(OBJDIR)\checkout$O $(OBJDIR)\clearsign$O $(OBJDIR)\clone$O $(OBJDIR)\comformat$O $(OBJDIR)\configure$O $(OBJDIR)\content$O $(OBJDIR)\db$O $(OBJDIR)\delta$O $(OBJDIR)\deltacmd$O $(OBJDIR)\descendants$O $(OBJDIR)\diff$O $(OBJDIR)\diffcmd$O $(OBJDIR)\doc$O $(OBJDIR)\encode$O $(OBJDIR)\event$O $(OBJDIR)\export$O $(OBJDIR)\file$O $(OBJDIR)\finfo$O $(OBJDIR)\glob$O $(OBJDIR)\graph$O $(OBJDIR)\gzip$O $(OBJDIR)\http$O $(OBJDIR)\http_socket$O $(OBJDIR)\http_ssl$O $(OBJDIR)\http_transport$O $(OBJDIR)\import$O $(OBJDIR)\info$O $(OBJDIR)\json$O $(OBJDIR)\json_artifact$O $(OBJDIR)\json_branch$O $(OBJDIR)\json_config$O $(OBJDIR)\json_diff$O $(OBJDIR)\json_dir$O $(OBJDIR)\json_finfo$O $(OBJDIR)\json_login$O $(OBJDIR)\json_query$O $(OBJDIR)\json_report$O $(OBJDIR)\json_tag$O $(OBJDIR)\json_timeline$O $(OBJDIR)\json_user$O $(OBJDIR)\json_wiki$O $(OBJDIR)\leaf$O $(OBJDIR)\login$O $(OBJDIR)\main$O $(OBJDIR)\manifest$O $(OBJDIR)\md5$O $(OBJDIR)\merge$O $(OBJDIR)\merge3$O $(OBJDIR)\name$O $(OBJDIR)\path$O $(OBJDIR)\pivot$O $(OBJDIR)\popen$O $(OBJDIR)\pqueue$O $(OBJDIR)\printf$O $(OBJDIR)\rebuild$O $(OBJDIR)\report$O $(OBJDIR)\rss$O $(OBJDIR)\schema$O $(OBJDIR)\search$O $(OBJDIR)\setup$O $(OBJDIR)\sha1$O $(OBJDIR)\shun$O $(OBJDIR)\skins$O $(OBJDIR)\sqlcmd$O $(OBJDIR)\stash$O $(OBJDIR)\stat$O $(OBJDIR)\style$O $(OBJDIR)\sync$O $(OBJDIR)\tag$O $(OBJDIR)\tar$O $(OBJDIR)\th_main$O $(OBJDIR)\timeline$O $(OBJDIR)\tkt$O $(OBJDIR)\tktsetup$O $(OBJDIR)\undo$O $(OBJDIR)\update$O $(OBJDIR)\url$O $(OBJDIR)\user$O $(OBJDIR)\verify$O $(OBJDIR)\vfile$O $(OBJDIR)\wiki$O $(OBJDIR)\wikiformat$O $(OBJDIR)\winhttp$O $(OBJDIR)\xfer$O $(OBJDIR)\xfersetup$O $(OBJDIR)\zip$O $(OBJDIR)\shell$O $(OBJDIR)\sqlite4$O $(OBJDIR)\th$O $(OBJDIR)\th_lang$O RC=$(DMDIR)\bin\rcc RCFLAGS=-32 -w1 -I$(SRCDIR) /D__DMC__ APPNAME = $(OBJDIR)\fossil$(E) all: $(APPNAME) $(APPNAME) : translate$E mkindex$E headers $(OBJ) $(OBJDIR)\link cd $(OBJDIR) $(DMDIR)\bin\link @link $(OBJDIR)\fossil.res: $B\win\fossil.rc $(RC) $(RCFLAGS) -o$@ $** $(OBJDIR)\link: $B\win\Makefile.dmc $(OBJDIR)\fossil.res +echo add allrepo attach bag bisect blob branch browse captcha cgi checkin checkout clearsign clone comformat configure content db delta deltacmd descendants diff diffcmd doc encode event export file finfo glob graph gzip http http_socket http_ssl http_transport import info json json_artifact json_branch json_config json_diff json_dir json_finfo json_login json_query json_report json_tag json_timeline json_user json_wiki leaf login main manifest md5 merge merge3 name path pivot popen pqueue printf rebuild report rss schema search setup sha1 shun skins sqlcmd stash stat style sync tag tar th_main timeline tkt tktsetup undo update url user verify vfile wiki wikiformat winhttp xfer xfersetup zip shell sqlite4 th th_lang > $@ +echo fossil >> $@ +echo fossil >> $@ +echo $(LIBS) >> $@ +echo. >> $@ +echo fossil >> $@ translate$E: $(SRCDIR)\translate.c $(BCC) -o$@ $** makeheaders$E: $(SRCDIR)\makeheaders.c $(BCC) -o$@ $** mkindex$E: $(SRCDIR)\mkindex.c $(BCC) -o$@ $** version$E: $B\src\mkversion.c $(BCC) -o$@ $** $(OBJDIR)\shell$O : $(SRCDIR)\shell.c $(TCC) -o$@ -c -Dmain=sqlite4_shell $(SQLITE4_OPTIONS) $** $(OBJDIR)\sqlite4$O : $(SRCDIR)\sqlite4.c $(TCC) -o$@ -c $(SQLITE4_OPTIONS) $** $(OBJDIR)\th$O : $(SRCDIR)\th.c $(TCC) -o$@ -c $** $(OBJDIR)\th_lang$O : $(SRCDIR)\th_lang.c $(TCC) -o$@ -c $** |
︙ | ︙ | |||
691 692 693 694 695 696 697 | $(OBJDIR)\zip$O : zip_.c zip.h $(TCC) -o$@ -c zip_.c zip_.c : $(SRCDIR)\zip.c +translate$E $** > $@ headers: makeheaders$E page_index.h VERSION.h | | | 691 692 693 694 695 696 697 698 699 | $(OBJDIR)\zip$O : zip_.c zip.h $(TCC) -o$@ -c zip_.c zip_.c : $(SRCDIR)\zip.c +translate$E $** > $@ headers: makeheaders$E page_index.h VERSION.h +makeheaders$E add_.c:add.h allrepo_.c:allrepo.h attach_.c:attach.h bag_.c:bag.h bisect_.c:bisect.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h captcha_.c:captcha.h cgi_.c:cgi.h checkin_.c:checkin.h checkout_.c:checkout.h clearsign_.c:clearsign.h clone_.c:clone.h comformat_.c:comformat.h configure_.c:configure.h content_.c:content.h db_.c:db.h delta_.c:delta.h deltacmd_.c:deltacmd.h descendants_.c:descendants.h diff_.c:diff.h diffcmd_.c:diffcmd.h doc_.c:doc.h encode_.c:encode.h event_.c:event.h export_.c:export.h file_.c:file.h finfo_.c:finfo.h glob_.c:glob.h graph_.c:graph.h gzip_.c:gzip.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h import_.c:import.h info_.c:info.h json_.c:json.h json_artifact_.c:json_artifact.h json_branch_.c:json_branch.h json_config_.c:json_config.h json_diff_.c:json_diff.h json_dir_.c:json_dir.h json_finfo_.c:json_finfo.h json_login_.c:json_login.h json_query_.c:json_query.h json_report_.c:json_report.h json_tag_.c:json_tag.h json_timeline_.c:json_timeline.h json_user_.c:json_user.h json_wiki_.c:json_wiki.h leaf_.c:leaf.h login_.c:login.h main_.c:main.h manifest_.c:manifest.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h name_.c:name.h path_.c:path.h pivot_.c:pivot.h popen_.c:popen.h pqueue_.c:pqueue.h printf_.c:printf.h rebuild_.c:rebuild.h report_.c:report.h rss_.c:rss.h schema_.c:schema.h search_.c:search.h setup_.c:setup.h sha1_.c:sha1.h shun_.c:shun.h skins_.c:skins.h sqlcmd_.c:sqlcmd.h stash_.c:stash.h stat_.c:stat.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h tar_.c:tar.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h update_.c:update.h url_.c:url.h user_.c:user.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winhttp_.c:winhttp.h xfer_.c:xfer.h xfersetup_.c:xfersetup.h zip_.c:zip.h $(SRCDIR)\sqlite4.h $(SRCDIR)\th.h VERSION.h $(SRCDIR)\cson_amalgamation.h @copy /Y nul: headers |
Changes to win/Makefile.mingw.
︙ | ︙ | |||
465 466 467 468 469 470 471 | $(OBJDIR)/wiki.o \ $(OBJDIR)/wikiformat.o \ $(OBJDIR)/winhttp.o \ $(OBJDIR)/xfer.o \ $(OBJDIR)/xfersetup.o \ $(OBJDIR)/zip.o | | | 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | $(OBJDIR)/wiki.o \ $(OBJDIR)/wikiformat.o \ $(OBJDIR)/winhttp.o \ $(OBJDIR)/xfer.o \ $(OBJDIR)/xfersetup.o \ $(OBJDIR)/zip.o APPNAME = fossil4.exe TRANSLATE = $(subst /,\\,$(OBJDIR)/translate.exe) MAKEHEADERS = $(subst /,\\,$(OBJDIR)/makeheaders.exe) MKINDEX = $(subst /,\\,$(OBJDIR)/mkindex.exe) VERSION = $(subst /,\\,$(OBJDIR)/version.exe) all: $(OBJDIR) $(APPNAME) |
︙ | ︙ | |||
505 506 507 508 509 510 511 | # the repository after running the tests. test: $(OBJDIR) $(APPNAME) $(TCLSH) $(SRCDIR)/../test/tester.tcl $(APPNAME) $(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(VERSION) $(VERSION) $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h | | | 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 | # the repository after running the tests. test: $(OBJDIR) $(APPNAME) $(TCLSH) $(SRCDIR)/../test/tester.tcl $(APPNAME) $(OBJDIR)/VERSION.h: $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(VERSION) $(VERSION) $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h EXTRAOBJ = $(OBJDIR)/sqlite4.o $(OBJDIR)/shell.o $(OBJDIR)/th.o $(OBJDIR)/th_lang.o $(OBJDIR)/cson_amalgamation.o ifdef FOSSIL_ENABLE_TCL EXTRAOBJ += $(OBJDIR)/th_tcl.o endif $(APPNAME): $(OBJDIR)/headers $(OBJ) $(EXTRAOBJ) $(OBJDIR)/icon.o $(TCC) -o $(APPNAME) $(OBJ) $(EXTRAOBJ) $(LIB) $(OBJDIR)/icon.o |
︙ | ︙ | |||
534 535 536 537 538 539 540 | setup: $(OBJDIR) $(APPNAME) $(MAKENSIS) ./fossil.nsi $(OBJDIR)/page_index.h: $(TRANS_SRC) $(OBJDIR)/mkindex $(MKINDEX) $(TRANS_SRC) >$@ $(OBJDIR)/headers: $(OBJDIR)/page_index.h $(OBJDIR)/makeheaders $(OBJDIR)/VERSION.h | | | 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 | setup: $(OBJDIR) $(APPNAME) $(MAKENSIS) ./fossil.nsi $(OBJDIR)/page_index.h: $(TRANS_SRC) $(OBJDIR)/mkindex $(MKINDEX) $(TRANS_SRC) >$@ $(OBJDIR)/headers: $(OBJDIR)/page_index.h $(OBJDIR)/makeheaders $(OBJDIR)/VERSION.h $(MAKEHEADERS) $(OBJDIR)/add_.c:$(OBJDIR)/add.h $(OBJDIR)/allrepo_.c:$(OBJDIR)/allrepo.h $(OBJDIR)/attach_.c:$(OBJDIR)/attach.h $(OBJDIR)/bag_.c:$(OBJDIR)/bag.h $(OBJDIR)/bisect_.c:$(OBJDIR)/bisect.h $(OBJDIR)/blob_.c:$(OBJDIR)/blob.h $(OBJDIR)/branch_.c:$(OBJDIR)/branch.h $(OBJDIR)/browse_.c:$(OBJDIR)/browse.h $(OBJDIR)/captcha_.c:$(OBJDIR)/captcha.h $(OBJDIR)/cgi_.c:$(OBJDIR)/cgi.h $(OBJDIR)/checkin_.c:$(OBJDIR)/checkin.h $(OBJDIR)/checkout_.c:$(OBJDIR)/checkout.h $(OBJDIR)/clearsign_.c:$(OBJDIR)/clearsign.h $(OBJDIR)/clone_.c:$(OBJDIR)/clone.h $(OBJDIR)/comformat_.c:$(OBJDIR)/comformat.h $(OBJDIR)/configure_.c:$(OBJDIR)/configure.h $(OBJDIR)/content_.c:$(OBJDIR)/content.h $(OBJDIR)/db_.c:$(OBJDIR)/db.h $(OBJDIR)/delta_.c:$(OBJDIR)/delta.h $(OBJDIR)/deltacmd_.c:$(OBJDIR)/deltacmd.h $(OBJDIR)/descendants_.c:$(OBJDIR)/descendants.h $(OBJDIR)/diff_.c:$(OBJDIR)/diff.h $(OBJDIR)/diffcmd_.c:$(OBJDIR)/diffcmd.h $(OBJDIR)/doc_.c:$(OBJDIR)/doc.h $(OBJDIR)/encode_.c:$(OBJDIR)/encode.h $(OBJDIR)/event_.c:$(OBJDIR)/event.h $(OBJDIR)/export_.c:$(OBJDIR)/export.h $(OBJDIR)/file_.c:$(OBJDIR)/file.h $(OBJDIR)/finfo_.c:$(OBJDIR)/finfo.h $(OBJDIR)/glob_.c:$(OBJDIR)/glob.h $(OBJDIR)/graph_.c:$(OBJDIR)/graph.h $(OBJDIR)/gzip_.c:$(OBJDIR)/gzip.h $(OBJDIR)/http_.c:$(OBJDIR)/http.h $(OBJDIR)/http_socket_.c:$(OBJDIR)/http_socket.h $(OBJDIR)/http_ssl_.c:$(OBJDIR)/http_ssl.h $(OBJDIR)/http_transport_.c:$(OBJDIR)/http_transport.h $(OBJDIR)/import_.c:$(OBJDIR)/import.h $(OBJDIR)/info_.c:$(OBJDIR)/info.h $(OBJDIR)/json_.c:$(OBJDIR)/json.h $(OBJDIR)/json_artifact_.c:$(OBJDIR)/json_artifact.h $(OBJDIR)/json_branch_.c:$(OBJDIR)/json_branch.h $(OBJDIR)/json_config_.c:$(OBJDIR)/json_config.h $(OBJDIR)/json_diff_.c:$(OBJDIR)/json_diff.h $(OBJDIR)/json_dir_.c:$(OBJDIR)/json_dir.h $(OBJDIR)/json_finfo_.c:$(OBJDIR)/json_finfo.h $(OBJDIR)/json_login_.c:$(OBJDIR)/json_login.h $(OBJDIR)/json_query_.c:$(OBJDIR)/json_query.h $(OBJDIR)/json_report_.c:$(OBJDIR)/json_report.h $(OBJDIR)/json_tag_.c:$(OBJDIR)/json_tag.h $(OBJDIR)/json_timeline_.c:$(OBJDIR)/json_timeline.h $(OBJDIR)/json_user_.c:$(OBJDIR)/json_user.h $(OBJDIR)/json_wiki_.c:$(OBJDIR)/json_wiki.h $(OBJDIR)/leaf_.c:$(OBJDIR)/leaf.h $(OBJDIR)/login_.c:$(OBJDIR)/login.h $(OBJDIR)/main_.c:$(OBJDIR)/main.h $(OBJDIR)/manifest_.c:$(OBJDIR)/manifest.h $(OBJDIR)/md5_.c:$(OBJDIR)/md5.h $(OBJDIR)/merge_.c:$(OBJDIR)/merge.h $(OBJDIR)/merge3_.c:$(OBJDIR)/merge3.h $(OBJDIR)/name_.c:$(OBJDIR)/name.h $(OBJDIR)/path_.c:$(OBJDIR)/path.h $(OBJDIR)/pivot_.c:$(OBJDIR)/pivot.h $(OBJDIR)/popen_.c:$(OBJDIR)/popen.h $(OBJDIR)/pqueue_.c:$(OBJDIR)/pqueue.h $(OBJDIR)/printf_.c:$(OBJDIR)/printf.h $(OBJDIR)/rebuild_.c:$(OBJDIR)/rebuild.h $(OBJDIR)/report_.c:$(OBJDIR)/report.h $(OBJDIR)/rss_.c:$(OBJDIR)/rss.h $(OBJDIR)/schema_.c:$(OBJDIR)/schema.h $(OBJDIR)/search_.c:$(OBJDIR)/search.h $(OBJDIR)/setup_.c:$(OBJDIR)/setup.h $(OBJDIR)/sha1_.c:$(OBJDIR)/sha1.h $(OBJDIR)/shun_.c:$(OBJDIR)/shun.h $(OBJDIR)/skins_.c:$(OBJDIR)/skins.h $(OBJDIR)/sqlcmd_.c:$(OBJDIR)/sqlcmd.h $(OBJDIR)/stash_.c:$(OBJDIR)/stash.h $(OBJDIR)/stat_.c:$(OBJDIR)/stat.h $(OBJDIR)/style_.c:$(OBJDIR)/style.h $(OBJDIR)/sync_.c:$(OBJDIR)/sync.h $(OBJDIR)/tag_.c:$(OBJDIR)/tag.h $(OBJDIR)/tar_.c:$(OBJDIR)/tar.h $(OBJDIR)/th_main_.c:$(OBJDIR)/th_main.h $(OBJDIR)/timeline_.c:$(OBJDIR)/timeline.h $(OBJDIR)/tkt_.c:$(OBJDIR)/tkt.h $(OBJDIR)/tktsetup_.c:$(OBJDIR)/tktsetup.h $(OBJDIR)/undo_.c:$(OBJDIR)/undo.h $(OBJDIR)/update_.c:$(OBJDIR)/update.h $(OBJDIR)/url_.c:$(OBJDIR)/url.h $(OBJDIR)/user_.c:$(OBJDIR)/user.h $(OBJDIR)/verify_.c:$(OBJDIR)/verify.h $(OBJDIR)/vfile_.c:$(OBJDIR)/vfile.h $(OBJDIR)/wiki_.c:$(OBJDIR)/wiki.h $(OBJDIR)/wikiformat_.c:$(OBJDIR)/wikiformat.h $(OBJDIR)/winhttp_.c:$(OBJDIR)/winhttp.h $(OBJDIR)/xfer_.c:$(OBJDIR)/xfer.h $(OBJDIR)/xfersetup_.c:$(OBJDIR)/xfersetup.h $(OBJDIR)/zip_.c:$(OBJDIR)/zip.h $(SRCDIR)/sqlite4.h $(SRCDIR)/th.h $(OBJDIR)/VERSION.h echo Done >$(OBJDIR)/headers $(OBJDIR)/headers: Makefile Makefile: $(OBJDIR)/add_.c: $(SRCDIR)/add.c $(OBJDIR)/translate $(TRANSLATE) $(SRCDIR)/add.c >$(OBJDIR)/add_.c |
︙ | ︙ | |||
1218 1219 1220 1221 1222 1223 1224 | $(OBJDIR)/zip_.c: $(SRCDIR)/zip.c $(OBJDIR)/translate $(TRANSLATE) $(SRCDIR)/zip.c >$(OBJDIR)/zip_.c $(OBJDIR)/zip.o: $(OBJDIR)/zip_.c $(OBJDIR)/zip.h $(SRCDIR)/config.h $(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c zip.h: $(OBJDIR)/headers | | | | | | 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 | $(OBJDIR)/zip_.c: $(SRCDIR)/zip.c $(OBJDIR)/translate $(TRANSLATE) $(SRCDIR)/zip.c >$(OBJDIR)/zip_.c $(OBJDIR)/zip.o: $(OBJDIR)/zip_.c $(OBJDIR)/zip.h $(SRCDIR)/config.h $(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c zip.h: $(OBJDIR)/headers $(OBJDIR)/sqlite4.o: $(SRCDIR)/sqlite4.c $(XTCC) -DSQLITE4_OMIT_LOAD_EXTENSION=1 -DSQLITE4_THREADSAFE=0 -DSQLITE4_DEFAULT_FILE_FORMAT=4 -DSQLITE4_ENABLE_STAT3 -Dlocaltime=fossil_localtime -DSQLITE4_ENABLE_LOCKING_STYLE=0 -c $(SRCDIR)/sqlite4.c -o $(OBJDIR)/sqlite4.o $(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c $(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $(OBJDIR)/cson_amalgamation.o -DCSON_FOSSIL_MODE $(OBJDIR)/json.o $(OBJDIR)/json_artifact.o $(OBJDIR)/json_branch.o $(OBJDIR)/json_config.o $(OBJDIR)/json_diff.o $(OBJDIR)/json_dir.o $(OBJDIR)/jsos_finfo.o $(OBJDIR)/json_login.o $(OBJDIR)/json_query.o $(OBJDIR)/json_report.o $(OBJDIR)/json_tag.o $(OBJDIR)/json_timeline.o $(OBJDIR)/json_user.o $(OBJDIR)/json_wiki.o : $(SRCDIR)/json_detail.h $(OBJDIR)/shell.o: $(SRCDIR)/shell.c $(SRCDIR)/sqlite4.h $(XTCC) -Dmain=sqlite4_shell -DSQLITE4_OMIT_LOAD_EXTENSION=1 -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o $(OBJDIR)/th.o: $(SRCDIR)/th.c $(XTCC) -I$(SRCDIR) -c $(SRCDIR)/th.c -o $(OBJDIR)/th.o $(OBJDIR)/th_lang.o: $(SRCDIR)/th_lang.c $(XTCC) -I$(SRCDIR) -c $(SRCDIR)/th_lang.c -o $(OBJDIR)/th_lang.o ifdef FOSSIL_ENABLE_TCL $(OBJDIR)/th_tcl.o: $(SRCDIR)/th_tcl.c $(XTCC) -I$(SRCDIR) -c $(SRCDIR)/th_tcl.c -o $(OBJDIR)/th_tcl.o endif |
Changes to win/Makefile.msc.
︙ | ︙ | |||
36 37 38 39 40 41 42 | CFLAGS = -nologo -MT -O2 BCC = $(CC) $(CFLAGS) TCC = $(CC) -c $(CFLAGS) $(MSCDEF) $(SSL) $(INCL) LIBS = $(ZLIB) ws2_32.lib advapi32.lib $(SSLLIB) LIBDIR = -LIBPATH:$(MSCDIR)\extra\lib -LIBPATH:$(ZLIBDIR) | | | | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | CFLAGS = -nologo -MT -O2 BCC = $(CC) $(CFLAGS) TCC = $(CC) -c $(CFLAGS) $(MSCDEF) $(SSL) $(INCL) LIBS = $(ZLIB) ws2_32.lib advapi32.lib $(SSLLIB) LIBDIR = -LIBPATH:$(MSCDIR)\extra\lib -LIBPATH:$(ZLIBDIR) SQLITE4_OPTIONS = /DSQLITE4_OMIT_LOAD_EXTENSION=1 /DSQLITE4_THREADSAFE=0 /DSQLITE4_DEFAULT_FILE_FORMAT=4 /DSQLITE4_ENABLE_STAT3 /Dlocaltime=fossil_localtime /DSQLITE4_ENABLE_LOCKING_STYLE=0 SRC = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c db_.c delta_.c deltacmd_.c descendants_.c diff_.c diffcmd_.c doc_.c encode_.c event_.c export_.c file_.c finfo_.c glob_.c graph_.c gzip_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c login_.c main_.c manifest_.c md5_.c merge_.c merge3_.c name_.c path_.c pivot_.c popen_.c pqueue_.c printf_.c rebuild_.c report_.c rss_.c schema_.c search_.c setup_.c sha1_.c shun_.c skins_.c sqlcmd_.c stash_.c stat_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c update_.c url_.c user_.c verify_.c vfile_.c wiki_.c wikiformat_.c winhttp_.c xfer_.c xfersetup_.c zip_.c OBJ = $(OX)\add$O $(OX)\allrepo$O $(OX)\attach$O $(OX)\bag$O $(OX)\bisect$O $(OX)\blob$O $(OX)\branch$O $(OX)\browse$O $(OX)\captcha$O $(OX)\cgi$O $(OX)\checkin$O $(OX)\checkout$O $(OX)\clearsign$O $(OX)\clone$O $(OX)\comformat$O $(OX)\configure$O $(OX)\content$O $(OX)\db$O $(OX)\delta$O $(OX)\deltacmd$O $(OX)\descendants$O $(OX)\diff$O $(OX)\diffcmd$O $(OX)\doc$O $(OX)\encode$O $(OX)\event$O $(OX)\export$O $(OX)\file$O $(OX)\finfo$O $(OX)\glob$O $(OX)\graph$O $(OX)\gzip$O $(OX)\http$O $(OX)\http_socket$O $(OX)\http_ssl$O $(OX)\http_transport$O $(OX)\import$O $(OX)\info$O $(OX)\json$O $(OX)\json_artifact$O $(OX)\json_branch$O $(OX)\json_config$O $(OX)\json_diff$O $(OX)\json_dir$O $(OX)\json_finfo$O $(OX)\json_login$O $(OX)\json_query$O $(OX)\json_report$O $(OX)\json_tag$O $(OX)\json_timeline$O $(OX)\json_user$O $(OX)\json_wiki$O $(OX)\leaf$O $(OX)\login$O $(OX)\main$O $(OX)\manifest$O $(OX)\md5$O $(OX)\merge$O $(OX)\merge3$O $(OX)\name$O $(OX)\path$O $(OX)\pivot$O $(OX)\popen$O $(OX)\pqueue$O $(OX)\printf$O $(OX)\rebuild$O $(OX)\report$O $(OX)\rss$O $(OX)\schema$O $(OX)\search$O $(OX)\setup$O $(OX)\sha1$O $(OX)\shun$O $(OX)\skins$O $(OX)\sqlcmd$O $(OX)\stash$O $(OX)\stat$O $(OX)\style$O $(OX)\sync$O $(OX)\tag$O $(OX)\tar$O $(OX)\th_main$O $(OX)\timeline$O $(OX)\tkt$O $(OX)\tktsetup$O $(OX)\undo$O $(OX)\update$O $(OX)\url$O $(OX)\user$O $(OX)\verify$O $(OX)\vfile$O $(OX)\wiki$O $(OX)\wikiformat$O $(OX)\winhttp$O $(OX)\xfer$O $(OX)\xfersetup$O $(OX)\zip$O $(OX)\shell$O $(OX)\sqlite4$O $(OX)\th$O $(OX)\th_lang$O APPNAME = $(OX)\fossil$(E) all: $(OX) $(APPNAME) $(APPNAME) : translate$E mkindex$E headers $(OBJ) $(OX)\linkopts |
︙ | ︙ | |||
128 129 130 131 132 133 134 | echo $(OX)\search.obj >> $@ echo $(OX)\setup.obj >> $@ echo $(OX)\sha1.obj >> $@ echo $(OX)\shell.obj >> $@ echo $(OX)\shun.obj >> $@ echo $(OX)\skins.obj >> $@ echo $(OX)\sqlcmd.obj >> $@ | | | 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | echo $(OX)\search.obj >> $@ echo $(OX)\setup.obj >> $@ echo $(OX)\sha1.obj >> $@ echo $(OX)\shell.obj >> $@ echo $(OX)\shun.obj >> $@ echo $(OX)\skins.obj >> $@ echo $(OX)\sqlcmd.obj >> $@ echo $(OX)\sqlite4.obj >> $@ echo $(OX)\stash.obj >> $@ echo $(OX)\stat.obj >> $@ echo $(OX)\style.obj >> $@ echo $(OX)\sync.obj >> $@ echo $(OX)\tag.obj >> $@ echo $(OX)\tar.obj >> $@ echo $(OX)\th.obj >> $@ |
︙ | ︙ | |||
174 175 176 177 178 179 180 | mkindex$E: $(SRCDIR)\mkindex.c $(BCC) $** mkversion$E: $B\src\mkversion.c $(BCC) $** $(OX)\shell$O : $(SRCDIR)\shell.c | | | | | 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | mkindex$E: $(SRCDIR)\mkindex.c $(BCC) $** mkversion$E: $B\src\mkversion.c $(BCC) $** $(OX)\shell$O : $(SRCDIR)\shell.c $(TCC) /Fo$@ /Dmain=sqlite4_shell $(SQLITE4_OPTIONS) -c $(SRCDIR)\shell.c $(OX)\sqlite4$O : $(SRCDIR)\sqlite4.c $(TCC) /Fo$@ -c $(SQLITE4_OPTIONS) $** $(OX)\th$O : $(SRCDIR)\th.c $(TCC) /Fo$@ -c $** $(OX)\th_lang$O : $(SRCDIR)\th_lang.c $(TCC) /Fo$@ -c $** |
︙ | ︙ | |||
800 801 802 803 804 805 806 | $(OX)\zip$O : zip_.c zip.h $(TCC) /Fo$@ -c zip_.c zip_.c : $(SRCDIR)\zip.c translate$E $** > $@ headers: makeheaders$E page_index.h VERSION.h | | | 800 801 802 803 804 805 806 807 808 | $(OX)\zip$O : zip_.c zip.h $(TCC) /Fo$@ -c zip_.c zip_.c : $(SRCDIR)\zip.c translate$E $** > $@ headers: makeheaders$E page_index.h VERSION.h makeheaders$E add_.c:add.h allrepo_.c:allrepo.h attach_.c:attach.h bag_.c:bag.h bisect_.c:bisect.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h captcha_.c:captcha.h cgi_.c:cgi.h checkin_.c:checkin.h checkout_.c:checkout.h clearsign_.c:clearsign.h clone_.c:clone.h comformat_.c:comformat.h configure_.c:configure.h content_.c:content.h db_.c:db.h delta_.c:delta.h deltacmd_.c:deltacmd.h descendants_.c:descendants.h diff_.c:diff.h diffcmd_.c:diffcmd.h doc_.c:doc.h encode_.c:encode.h event_.c:event.h export_.c:export.h file_.c:file.h finfo_.c:finfo.h glob_.c:glob.h graph_.c:graph.h gzip_.c:gzip.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h import_.c:import.h info_.c:info.h json_.c:json.h json_artifact_.c:json_artifact.h json_branch_.c:json_branch.h json_config_.c:json_config.h json_diff_.c:json_diff.h json_dir_.c:json_dir.h json_finfo_.c:json_finfo.h json_login_.c:json_login.h json_query_.c:json_query.h json_report_.c:json_report.h json_tag_.c:json_tag.h json_timeline_.c:json_timeline.h json_user_.c:json_user.h json_wiki_.c:json_wiki.h leaf_.c:leaf.h login_.c:login.h main_.c:main.h manifest_.c:manifest.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h name_.c:name.h path_.c:path.h pivot_.c:pivot.h popen_.c:popen.h pqueue_.c:pqueue.h printf_.c:printf.h rebuild_.c:rebuild.h report_.c:report.h rss_.c:rss.h schema_.c:schema.h search_.c:search.h setup_.c:setup.h sha1_.c:sha1.h shun_.c:shun.h skins_.c:skins.h sqlcmd_.c:sqlcmd.h stash_.c:stash.h stat_.c:stat.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h tar_.c:tar.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h update_.c:update.h url_.c:url.h user_.c:user.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winhttp_.c:winhttp.h xfer_.c:xfer.h xfersetup_.c:xfersetup.h zip_.c:zip.h $(SRCDIR)\sqlite4.h $(SRCDIR)\th.h VERSION.h $(SRCDIR)\cson_amalgamation.h @copy /Y nul: headers |