]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Improvements to the QRF README.md file to help clarify how to use it.
authordrh <>
Wed, 26 Nov 2025 22:58:26 +0000 (22:58 +0000)
committerdrh <>
Wed, 26 Nov 2025 22:58:26 +0000 (22:58 +0000)
FossilOrigin-Name: ff589e9e0da99e2248bc7a8bff37e1deb7cbdf8285c18467acd89b65c67401d3

ext/qrf/README.md
manifest
manifest.uuid

index 34b0409def3fe66944d266c8423b4a6dcecf075c..397c0820768c97aaafd5a925a1f5020c858078a1 100644 (file)
@@ -19,10 +19,10 @@ that can be incorporated and reused by other applications.
 
 ## 1.0 Overview Of Operation
 
-Suppose `pStmt` is a pointer to an SQLite prepared statement
-(a pointer to an `sqlite3_stmt` object) that has been reset and
-bound and is ready to run.  Then to format the output from this
-prepared statement, use code similar to the following:
+Suppose variable `sqlite3_stmt *pStmt` is a pointer to an SQLite
+prepared statement that has been reset and bound and is ready to run.
+Then to format the output from this prepared statement, use code
+similar to the following:
 
 > ~~~
 sqlite3_qrf_spec spec;  /* Format specification */
@@ -41,14 +41,55 @@ if( rc ){
   sqlite3_free(zErrMsg);              /* Free the error message text */
 }else{
   printf("%s", zResult);              /* Report the results */
-  sqlite3_free(zResult);              /* Free memory used to hold results */
 }
+sqlite3_free(zResult);              /* Free memory used to hold results */
 ~~~
 
 The `sqlite3_qrf_spec` object describes the desired output format
 and where to send the generated output. Most of the work in using
 the QRF involves filling out the sqlite3_qrf_spec.
 
+### 1.1 Using QRF with SQL text
+
+If you start with SQL text instead of an sqlite3_stmt pointer, and
+especially if the SQL text might comprise two or more statements, then
+the SQL text needs to be converted into sqlite3_stmt objects separately.
+If the original SQL text is in a variable `const char *zSql` and the
+database connection is in variable `sqlite3 *db`, then code
+similar to the following should work:
+
+> ~~~
+sqlite3_qrf_spec spec;  /* Format specification */
+char *zErrMsg;          /* Text error message (optional) */
+char *zResult = 0;      /* Formatted output written here */
+sqlite3_stmt *pStmt;    /* Next prepared statement */
+int rc;                 /* Result code */
+
+memset(&spec, 0, sizeof(spec));       /* Initialize the spec */
+spec.iVersion = 1;                    /* Version number must be 1 */
+spec.pzOutput = &zResult;             /* Write results in variable zResult */
+/* Optionally fill in other settings in spec here, as needed */
+zErrMsg = 0;                          /* Not required; just being pedantic */
+while( zSql && zSql[0] ){
+  pStmt = 0;                          /* Not required; just being pedantic */
+  rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zSql);
+  if( rc!=SQLITE_OK ){
+    printf("Error: %s\n", sqlite3_errmsg(db));
+  }else{
+    rc = sqlite3_format_query_result(pStmt, &spec, &zErrMsg); /* Get results */
+    if( rc ){
+      printf("Error (%d): %s\n", rc, zErrMsg);  /* Report an error */
+      sqlite3_free(zErrMsg);              /* Free the error message text */
+    }else{
+      printf("%s", zResult);              /* Report the results */
+      sqlite3_free(zResult);              /* Free memory used to hold results */
+      zResult = 0;
+    }
+  }
+  sqlite3_finalize(pStmt);
+}
+~~~
+
 ## 2.0 The `sqlite3_qrf_spec` object
 
 The most recent definition of `sqlite3_qrf_spec` is shown below.
index 0b9c4d5c88d7f50b3354d6b1e194c4110360f348..9d3d8556e5872d27e041e40af418dcb0c293104f 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Do\snot\somit\sthe\sbeginning\sand\sending\smargins\swhen\ssetting\sbBorder\sto\sQRF_Off,\nexcept\swhen\sthe\smargins\sneed\sto\sbe\ssqueezed\sto\sfit.\s\sThose\sextra\smargins\sgive\na\smore\spleasing\sappearance,\sand\salso\smake\sthe\soutput\sthe\ssame\sas\spsql.
-D 2025-11-26T21:56:55.233
+C Improvements\sto\sthe\sQRF\sREADME.md\sfile\sto\shelp\sclarify\show\sto\suse\sit.
+D 2025-11-26T22:58:26.158
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -416,7 +416,7 @@ F ext/misc/wholenumber.c 0fa0c082676b7868bf2fa918e911133f2b349bcdceabd1198bba5f6
 F ext/misc/windirent.h 02211ce51f3034c675f2dbf4d228194d51b3ee05734678bad5106fff6292e60c
 F ext/misc/zipfile.c 09e6e3a3ff40a99677de3c0bc6569bd5f4709b1844ac3d1c1452a456c5a62f1c
 F ext/misc/zorder.c bddff2e1b9661a90c95c2a9a9c7ecd8908afab5763256294dd12d609d4664eee
-F ext/qrf/README.md 07dcefad86c259c161d0ec2ee5f8430a88d1645ff9b23f535b7cf27a1c527d32
+F ext/qrf/README.md 86fc5c3c5e3eddbe54fc1235cbdc52b8c2c0732791d224345c3014cd45c4c0e7
 F ext/qrf/qrf.c f5dfef8bcd71144bc57023b875363101f89ab332f13593aed49361cdce8be19e
 F ext/qrf/qrf.h 322d48537a5aa39c206c2ec0764a7938ea7662a8c25be1c4e9d742789609ba1e
 F ext/rbu/rbu.c 801450b24eaf14440d8fd20385aacc751d5c9d6123398df41b1b5aa804bf4ce8
@@ -2180,8 +2180,8 @@ F tool/version-info.c 33d0390ef484b3b1cb685d59362be891ea162123cea181cb8e6d2cf6dd
 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
 F tool/warnings.sh d924598cf2f55a4ecbc2aeb055c10bd5f48114793e7ba25f9585435da29e7e98
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 5fdedc69b1ac05bcdc40ee30c1473be75d3afe89e031d750c8fc3dcfa9846d5b
-R 07acb13ffa0345c135c8758f8bc105e4
+P 2892aaeed9f55ad87791491068493c2e530eeff4194d156f16745d185760797c
+R 47643b76f3fa2e8ace4e989a9a6981ec
 U drh
-Z 658d4fe01ec54e040334567598ba30cd
+Z d304c4e1d952783653a628c674b5ed4e
 # Remove this line to create a well-formed Fossil manifest.
index a5481c703496d58a50b105646729d275ee32ae47..52b3d8431591ee551d00fe0a021906c46db4d3e1 100644 (file)
@@ -1 +1 @@
-2892aaeed9f55ad87791491068493c2e530eeff4194d156f16745d185760797c
+ff589e9e0da99e2248bc7a8bff37e1deb7cbdf8285c18467acd89b65c67401d3