SQLite

Check-in [68ef170286]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Break Mem.flags into Mem.type and Mem.enc. (CVS 1466)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 68ef17028621681f5d091e77d5df84f663a15e27
User & Date: drh 2004-05-26 23:43:12.000
Context
2004-05-27
01:04
Add TCL test bindings and some more test cases for the new query API. (CVS 1467) (check-in: d72adf0c52 user: danielk1977 tags: trunk)
2004-05-26
23:43
Break Mem.flags into Mem.type and Mem.enc. (CVS 1466) (check-in: 68ef170286 user: drh tags: trunk)
23:25
Refactoring of the vdbe Mem functions and the APIs that deal with them. The code will not compile in its current state. (CVS 1465) (check-in: bba6684d50 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/vdbeInt.h.
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
** in a Mem struct is returned by the MemType(Mem*) macro. The type is
** one of SQLITE3_NULL, SQLITE3_INTEGER, SQLITE3_REAL, SQLITE3_TEXT or
** SQLITE3_BLOB.
*/
struct Mem {
  i64 i;              /* Integer value */
  int n;              /* Number of characters in string value, including '\0' */
  int flags;          /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */


  double r;           /* Real value */
  char *z;            /* String or BLOB value */
  char zShort[NBFS];  /* Space for short strings */
};
typedef struct Mem Mem;

/* One or more of the following flags are set to indicate the valid
** representations of the value stored in the Mem struct.
**
** If the MEM_Null flag is set, then the value is an SQL NULL value.
** No other flags may be set in this case.
**
** If the MEM_Str flag is set then Mem.z points at a string representation.
** Usually this is encoded in the same unicode encoding as the main
** database (see below for exceptions). If the MEM_Term flag is also
** set, then the string is nul terminated. The MEM_Int and MEM_Real 
** flags may coexist with the MEM_Str flag.
** 


*/
#define MEM_Null      0x0001   /* Value is NULL */
#define MEM_Str       0x0002   /* Value is a string */
#define MEM_Int       0x0004   /* Value is an integer */
#define MEM_Real      0x0008   /* Value is a real number */
#define MEM_Blob      0x0010   /* Value is a BLOB */

#define MEM_Term       0x0100   /* String rep is nul terminated */

/* Values with type NULL or BLOB can have only one representation. But
** values with a manifest type of REAL, INTEGER or STRING may have one
** or more representation cached in the Mem struct at any one time. The
** flags MEM_IntVal, MEM_RealVal and MEM_StrVal are true whenever the real,
** integer or string representation stored in a Mem struct is valid.
**
** When MEM_StrVal is set, then MEM_Term may also be set. This indicates
** that the string is terminated with a nul-terminator character.
*/
#define MEM_TypeInt    0x0020   /* Value type is an integer */
#define MEM_TypeReal   0x0040   /* Value type is real */
#define MEM_TypeStr    0x0080   /* Value type is string */


/* Whenever Mem contains a valid string or blob representation, one of
** the following flags must be set to determine the memory management
** policy for Mem.z

*/

#define MEM_Dyn       0x0200   /* Need to call sqliteFree() on Mem.z */
#define MEM_Static    0x0400   /* Mem.z points to a static string */
#define MEM_Ephem     0x0800   /* Mem.z points to an ephemeral string */
#define MEM_Short     0x1000   /* Mem.z points to Mem.zShort */

/* Internally, all strings manipulated by the  VDBE are encoded using the
** native encoding for the main database. Therefore the following three
** flags, which describe the text encoding of the string if the MEM_Str
** flag is true, are not generally valid for Mem* objects handled by the
** VDBE.
**
** When a user-defined function is called (see OP_Function), the Mem*
** objects that store the argument values for the function call are 
** passed to the user-defined function routine cast to sqlite3_value*.
** The user routine may then call sqlite3_value_text() or
** sqlite3_value_text16() to request a UTF-8 or UTF-16 string. If the
** string representation currently stored in Mem.z is not the requested
** encoding, then a translation occurs. To keep track of things, the
** MEM_Utf* flags are set correctly for the database encoding before a
** user-routine is called, and kept up to date if any translations occur
** thereafter.
** 
** When sqlite3_step() returns SQLITE3_ROW, indicating that a row of data
** is ready for processing by the caller, the data values are stored
** internally as Mem* objects. Before sqlite3_step() returns, the MEM_Utf*
** flags are set correctly for the database encoding. A translation may
** take place if the user requests a non-native encoding via
** sqlite3_column_text() or sqlite3_column_text16(). If this occurs, then
** the MEM_Utf* flags are updated accordingly.
*/
#define MEM_Utf8      0x2000   /* String uses UTF-8 encoding */
#define MEM_Utf16be   0x4000   /* String uses UTF-16 big-endian */
#define MEM_Utf16le   0x8000   /* String uses UTF-16 little-endian */

/* The following MEM_ value appears only in AggElem.aMem.s.flag fields.
** It indicates that the corresponding AggElem.aMem.z points to a
** aggregate function context that needs to be finalized.
*/
#define MEM_AggCtx    0x10000  /* Mem.z points to an agg function context */

/*
** The "context" argument for a installable function.  A pointer to an
** instance of this structure is the first argument to the routines used
** implement the SQL functions.
**
** There is a typedef for this structure in sqlite.h.  So all routines,







|
>
>






|










|
>
>







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


|
>

>
|
|
|
|

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<




|







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
** in a Mem struct is returned by the MemType(Mem*) macro. The type is
** one of SQLITE3_NULL, SQLITE3_INTEGER, SQLITE3_REAL, SQLITE3_TEXT or
** SQLITE3_BLOB.
*/
struct Mem {
  i64 i;              /* Integer value */
  int n;              /* Number of characters in string value, including '\0' */
  u16 flags;          /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
  u8  type;           /* One of MEM_Null, MEM_Str, etc. */
  u8  enc;            /* TEXT_Utf8, TEXT_Utf16le, or TEXT_Utf16be */
  double r;           /* Real value */
  char *z;            /* String or BLOB value */
  char zShort[NBFS];  /* Space for short strings */
};
typedef struct Mem Mem;

/* One or more of the following flags are set to indicate the validOK
** representations of the value stored in the Mem struct.
**
** If the MEM_Null flag is set, then the value is an SQL NULL value.
** No other flags may be set in this case.
**
** If the MEM_Str flag is set then Mem.z points at a string representation.
** Usually this is encoded in the same unicode encoding as the main
** database (see below for exceptions). If the MEM_Term flag is also
** set, then the string is nul terminated. The MEM_Int and MEM_Real 
** flags may coexist with the MEM_Str flag.
**
** Multiple of these values can appear in Mem.flags.  But only one
** at a time can appear in Mem.type.
*/
#define MEM_Null      0x0001   /* Value is NULL */
#define MEM_Str       0x0002   /* Value is a string */
#define MEM_Int       0x0004   /* Value is an integer */
#define MEM_Real      0x0008   /* Value is a real number */
#define MEM_Blob      0x0010   /* Value is a BLOB */

















/* Whenever Mem contains a valid string or blob representation, one of
** the following flags must be set to determine the memory management
** policy for Mem.z.  The MEM_Term flag tells us whether or not the
** string is \000 or \u0000 terminated
*/
#define MEM_Term      0x0020   /* String rep is nul terminated */
#define MEM_Dyn       0x0040   /* Need to call sqliteFree() on Mem.z */
#define MEM_Static    0x0080   /* Mem.z points to a static string */
#define MEM_Ephem     0x0100   /* Mem.z points to an ephemeral string */
#define MEM_Short     0x0200   /* Mem.z points to Mem.zShort */






























/* The following MEM_ value appears only in AggElem.aMem.s.flag fields.
** It indicates that the corresponding AggElem.aMem.z points to a
** aggregate function context that needs to be finalized.
*/
#define MEM_AggCtx    0x0400  /* Mem.z points to an agg function context */

/*
** The "context" argument for a installable function.  A pointer to an
** instance of this structure is the first argument to the routines used
** implement the SQL functions.
**
** There is a typedef for this structure in sqlite.h.  So all routines,