interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / ext / qrf / qrf.h

221 lines · 9749 bytes Raw Blame History
1/*
2** 2025-10-20
3**
4** The author disclaims copyright to this source code. In place of
5** a legal notice, here is a blessing:
6**
7** May you do good and not evil.
8** May you find forgiveness for yourself and forgive others.
9** May you share freely, never taking more than you give.
10**
11*************************************************************************
12** Header file for the Query Result-Format or "qrf" utility library for
13** SQLite. See the README.md documentation for additional information.
14*/
15#ifndef SQLITE_QRF_H
16#define SQLITE_QRF_H
17#ifdef __cplusplus
18extern "C" {
19#endif
20#include <stdlib.h>
21#include "sqlite3.h"
22
23/*
24** Specification used by clients to define the output format they want
25*/
26typedef struct sqlite3_qrf_spec sqlite3_qrf_spec;
27struct sqlite3_qrf_spec {
28 unsigned char iVersion; /* Version number of this structure */
29 unsigned char eStyle; /* Formatting style. "box", "csv", etc... */
30 unsigned char eEsc; /* How to escape control characters in text */
31 unsigned char eText; /* Quoting style for text */
32 unsigned char eTitle; /* Quating style for the text of column names */
33 unsigned char eBlob; /* Quoting style for BLOBs */
34 unsigned char bTitles; /* True to show column names */
35 unsigned char bWordWrap; /* Try to wrap on word boundaries */
36 unsigned char bTextJsonb; /* Render JSONB blobs as JSON text */
37 unsigned char eDfltAlign; /* Default alignment, no covered by aAlignment */
38 unsigned char eTitleAlign; /* Alignment for column headers */
39 unsigned char bSplitColumn; /* Wrap single-column output into many columns */
40 unsigned char bBorder; /* Show outer border in Box and Table styles */
41 short int nWrap; /* Wrap columns wider than this */
42 short int nScreenWidth; /* Maximum overall table width */
43 short int nLineLimit; /* Maximum number of lines for any row */
44 short int nTitleLimit; /* Maximum number of characters in a title */
45 unsigned int nMultiInsert; /* Add rows to one INSERT until size exceeds */
46 int nCharLimit; /* Maximum number of characters in a cell */
47 int nWidth; /* Number of entries in aWidth[] */
48 int nAlign; /* Number of entries in aAlignment[] */
49 short int *aWidth; /* Column widths */
50 unsigned char *aAlign; /* Column alignments */
51 char *zColumnSep; /* Alternative column separator */
52 char *zRowSep; /* Alternative row separator */
53 char *zTableName; /* Output table name */
54 char *zNull; /* Rendering of NULL */
55 char *(*xRender)(void*,sqlite3_value*); /* Render a value */
56 int (*xWrite)(void*,const char*,sqlite3_int64); /* Write output */
57 void *pRenderArg; /* First argument to the xRender callback */
58 void *pWriteArg; /* First argument to the xWrite callback */
59 char **pzOutput; /* Storage location for output string */
60 /* The following are available in iVersion 2 and later */
61 unsigned char bRowCount; /* Show the number of rows at end of each query */
62 char *zIFmt; /* Format string for integers */
63 char *zFpFmt; /* Format string for floating point */
64 /* Additional fields may be added in the future */
65};
66
67/*
68** Interfaces
69*/
70int sqlite3_format_query_result(
71 sqlite3_stmt *pStmt, /* SQL statement to run */
72 const sqlite3_qrf_spec *pSpec, /* Result format specification */
73 char **pzErr /* OUT: Write error message here */
74);
75
76/*
77** Range of values for sqlite3_qrf_spec.aWidth[] entries.
78*/
79#define QRF_MAX_WIDTH 10000
80#define QRF_MIN_WIDTH 0
81
82/*
83** Output styles:
84*/
85#define QRF_STYLE_Auto 0 /* Choose a style automatically */
86#define QRF_STYLE_Box 1 /* Unicode box-drawing characters */
87#define QRF_STYLE_Column 2 /* One record per line in neat columns */
88#define QRF_STYLE_Count 3 /* Output only a count of the rows of output */
89#define QRF_STYLE_Csv 4 /* Comma-separated-value */
90#define QRF_STYLE_Eqp 5 /* Format EXPLAIN QUERY PLAN output */
91#define QRF_STYLE_Explain 6 /* EXPLAIN output */
92#define QRF_STYLE_Html 7 /* Generate HTML-style <tr><td> output */
93#define QRF_STYLE_Insert 8 /* Generate SQL "insert" statements */
94#define QRF_STYLE_Json 9 /* Output is a list of JSON objects */
95#define QRF_STYLE_JObject 10 /* Independent JSON objects for each row */
96#define QRF_STYLE_Line 11 /* One column per line. */
97#define QRF_STYLE_List 12 /* One record per line with a separator */
98#define QRF_STYLE_Markdown 13 /* Markdown formatting */
99#define QRF_STYLE_Off 14 /* No query output shown */
100#define QRF_STYLE_Quote 15 /* SQL-quoted, comma-separated */
101#define QRF_STYLE_Stats 16 /* EQP-like output but with performance stats */
102#define QRF_STYLE_StatsEst 17 /* EQP-like output with planner estimates */
103#define QRF_STYLE_StatsVm 18 /* EXPLAIN-like output with performance stats */
104#define QRF_STYLE_Table 19 /* MySQL-style table formatting */
105
106/*
107** Quoting styles for text.
108** Allowed values for sqlite3_qrf_spec.eText
109*/
110#define QRF_TEXT_Auto 0 /* Choose text encoding automatically */
111#define QRF_TEXT_Plain 1 /* Literal text */
112#define QRF_TEXT_Sql 2 /* Quote as an SQL literal */
113#define QRF_TEXT_Csv 3 /* CSV-style quoting */
114#define QRF_TEXT_Html 4 /* HTML-style quoting */
115#define QRF_TEXT_Tcl 5 /* C/Tcl quoting */
116#define QRF_TEXT_Json 6 /* JSON quoting */
117#define QRF_TEXT_Relaxed 7 /* Relaxed SQL quoting */
118
119/*
120** Quoting styles for BLOBs
121** Allowed values for sqlite3_qrf_spec.eBlob
122*/
123#define QRF_BLOB_Auto 0 /* Determine BLOB quoting using eText */
124#define QRF_BLOB_Text 1 /* Display content exactly as it is */
125#define QRF_BLOB_Sql 2 /* Quote as an SQL literal */
126#define QRF_BLOB_Hex 3 /* Hexadecimal representation */
127#define QRF_BLOB_Tcl 4 /* "\000" notation */
128#define QRF_BLOB_Json 5 /* A JSON string */
129#define QRF_BLOB_Size 6 /* Display the blob size only */
130
131/*
132** Control-character escape modes.
133** Allowed values for sqlite3_qrf_spec.eEsc
134*/
135#define QRF_ESC_Auto 0 /* Choose the ctrl-char escape automatically */
136#define QRF_ESC_Off 1 /* Do not escape control characters */
137#define QRF_ESC_Ascii 2 /* Unix-style escapes. Ex: U+0007 shows ^G */
138#define QRF_ESC_Symbol 3 /* Unicode escapes. Ex: U+0007 shows U+2407 */
139
140/*
141** Allowed values for "boolean" fields, such as "bColumnNames", "bWordWrap",
142** and "bTextJsonb". There is an extra "auto" variants so these are actually
143** tri-state settings, not booleans.
144*/
145#define QRF_SW_Auto 0 /* Let QRF choose the best value */
146#define QRF_SW_Off 1 /* This setting is forced off */
147#define QRF_SW_On 2 /* This setting is forced on */
148#define QRF_Auto 0 /* Alternate spelling for QRF_*_Auto */
149#define QRF_No 1 /* Alternate spelling for QRF_SW_Off */
150#define QRF_Yes 2 /* Alternate spelling for QRF_SW_On */
151
152/*
153** Additional value allowed for bTitles
154*/
155#define QRF_Always 3 /* Always show titles, even if no rows */
156
157/*
158** Possible alignment values alignment settings
159**
160** Horizontal Vertial
161** ---------- -------- */
162#define QRF_ALIGN_Auto 0 /* auto auto */
163#define QRF_ALIGN_Left 1 /* left auto */
164#define QRF_ALIGN_Center 2 /* center auto */
165#define QRF_ALIGN_Right 3 /* right auto */
166#define QRF_ALIGN_Top 4 /* auto top */
167#define QRF_ALIGN_NW 5 /* left top */
168#define QRF_ALIGN_N 6 /* center top */
169#define QRF_ALIGN_NE 7 /* right top */
170#define QRF_ALIGN_Middle 8 /* auto middle */
171#define QRF_ALIGN_W 9 /* left middle */
172#define QRF_ALIGN_C 10 /* center middle */
173#define QRF_ALIGN_E 11 /* right middle */
174#define QRF_ALIGN_Bottom 12 /* auto bottom */
175#define QRF_ALIGN_SW 13 /* left bottom */
176#define QRF_ALIGN_S 14 /* center bottom */
177#define QRF_ALIGN_SE 15 /* right bottom */
178#define QRF_ALIGN_HMASK 3 /* Horizontal alignment mask */
179#define QRF_ALIGN_VMASK 12 /* Vertical alignment mask */
180
181/*
182** Auxiliary routines contined within this module that might be useful
183** in other contexts, and which are therefore exported.
184*/
185/*
186** Return an estimate of the width, in columns, for the single Unicode
187** character c. For normal characters, the answer is always 1. But the
188** estimate might be 0 or 2 for zero-width and double-width characters.
189**
190** Different devices display unicode using different widths. So
191** it is impossible to know that true display width with 100% accuracy.
192** Inaccuracies in the width estimates might cause columns to be misaligned.
193** Unfortunately, there is nothing we can do about that.
194*/
195int sqlite3_qrf_wcwidth(int c);
196
197/*
198** Return an estimate of the number of display columns used by the
199** string in the argument. The width of individual characters is
200** determined as for sqlite3_qrf_wcwidth(). VT100 escape code sequences
201** are assigned a width of zero.
202*/
203size_t sqlite3_qrf_wcswidth(const char*);
204
205/*
206** The argument is a proposed format string for the zIFmt or zFpFmt
207** parameters. Return value indicates:
208**
209** 0 The input is not a valid format string. If this string
210** appears in either zIFmt or zFpFmt, it will be ignored.
211**
212** 1 The input is a valid format string for integers.
213**
214** 2 The input is a valid format string for floating point.
215*/
216int sqlite3_qrf_ckformat(const char*);
217
218#ifdef __cplusplus
219}
220#endif
221#endif /* !defined(SQLITE_QRF_H) */