aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordanielk1977 <danielk1977@noemail.net>2004-05-24 09:10:10 +0000
committerdanielk1977 <danielk1977@noemail.net>2004-05-24 09:10:10 +0000
commit0ffba6b26931bb69b230a2ec480d3fb7cfd5ff4c (patch)
treed3a7d9dec02b9d4843a87074dfbc4c4bb4c7a97a /src
parentbd7e46086ecc51cd722d4db69b60976e310f6f19 (diff)
downloadsqlite-0ffba6b26931bb69b230a2ec480d3fb7cfd5ff4c.tar.gz
sqlite-0ffba6b26931bb69b230a2ec480d3fb7cfd5ff4c.zip
Add the sqlite3_value_*() access functions. (CVS 1447)
FossilOrigin-Name: 4bf925fcfccb18e66be031f8a234f370d581e9ea
Diffstat (limited to 'src')
-rw-r--r--src/sqlite.h.in69
-rw-r--r--src/vdbe.c74
2 files changed, 134 insertions, 9 deletions
diff --git a/src/sqlite.h.in b/src/sqlite.h.in
index c8f0717fc..9eeedabc0 100644
--- a/src/sqlite.h.in
+++ b/src/sqlite.h.in
@@ -12,7 +12,7 @@
** This header file defines the interface that the SQLite library
** presents to client programs.
**
-** @(#) $Id: sqlite.h.in,v 1.71 2004/05/23 13:30:58 danielk1977 Exp $
+** @(#) $Id: sqlite.h.in,v 1.72 2004/05/24 09:10:11 danielk1977 Exp $
*/
#ifndef _SQLITE_H_
#define _SQLITE_H_
@@ -1342,12 +1342,75 @@ double sqlite3_column_float(sqlite3_stmt*,int);
typedef struct Mem sqlite3_value;
+/*
+** Return the type of the sqlite3_value* passed as the first argument.
+** The type is one of SQLITE3_NULL, SQLITE3_INTEGER, SQLITE3_FLOAT,
+** SQLITE3_TEXT or SQLITE3_BLOB.
+*/
int sqlite3_value_type(sqlite3_value*);
-int sqlite3_value_bytes(sqlite3_value*);
-int sqlite3_value_bytes16(sqlite3_value*);
+
+/*
+** Return the value of the sqlite3_value* passed as the first argument.
+** The value returned depends on the type of the value, as returned by
+** sqlite3_value_type():
+**
+** SQLITE3_NULL A Null pointer.
+** SQLITE3_INTEGER String representation of the integer, UTF-8 encoded.
+** SQLITE3_FLOAT String representation of the real, UTF-8 encoded.
+** SQLITE3_TEXT The string UTF-8 encoded.
+** SQLITE3_BLOB A pointer to the blob of data.
+*/
const unsigned char *sqlite3_value_data(sqlite3_value*);
+
+/*
+** Return the number of bytes in the string or blob returned by a call
+** to sqlite3_value_data() on the same sqlite3_value* object.
+*/
+int sqlite3_value_bytes(sqlite3_value*);
+
+/*
+** Return the value of the sqlite3_value* passed as the first argument.
+** The value returned depends on the type of the value, as returned by
+** sqlite3_value_type():
+**
+** SQLITE3_NULL A Null pointer.
+** SQLITE3_INTEGER String representation of the integer, UTF-16 encoded.
+** SQLITE3_FLOAT String representation of the real, UTF-16 encoded.
+** SQLITE3_TEXT The string UTF-16 encoded.
+** SQLITE3_BLOB A pointer to the blob of data.
+*/
const void *sqlite3_value_data16(sqlite3_value*);
+
+/*
+** Return the number of bytes in the string or blob returned by a call
+** to sqlite3_value_data16() on the same sqlite3_value* object.
+*/
+int sqlite3_value_bytes16(sqlite3_value*);
+
+/*
+** Return the value of the sqlite3_value* passed as the first argument.
+** The value returned depends on the type of the value, as returned by
+** sqlite3_value_type():
+**
+** SQLITE3_NULL 0
+** SQLITE3_INTEGER The integer value.
+** SQLITE3_FLOAT The integer component of the real (2^63 if too large)
+** SQLITE3_TEXT Integer conversion of string, or 0
+** SQLITE3_BLOB 0
+*/
long long int sqlite3_value_int(sqlite3_value*);
+
+/*
+** Return the value of the sqlite3_value* passed as the first argument.
+** The value returned depends on the type of the value, as returned by
+** sqlite3_value_type():
+**
+** SQLITE3_NULL 0.0
+** SQLITE3_INTEGER The value of the integer. Some rounding may occur.
+** SQLITE3_FLOAT The value of the float.
+** SQLITE3_TEXT Real number conversion of string, or 0.0
+** SQLITE3_BLOB 0.0
+*/
double sqlite3_value_float(sqlite3_value*);
#ifdef __cplusplus
diff --git a/src/vdbe.c b/src/vdbe.c
index ad47150d6..cb540592e 100644
--- a/src/vdbe.c
+++ b/src/vdbe.c
@@ -43,7 +43,7 @@
** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
**
-** $Id: vdbe.c,v 1.323 2004/05/24 07:34:48 danielk1977 Exp $
+** $Id: vdbe.c,v 1.324 2004/05/24 09:10:11 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -632,6 +632,48 @@ const void *sqlite3_value_data16(sqlite3_value* pVal){
/*
** Return the number of bytes of data that will be returned by the
+** equivalent sqlite3_value_data() call.
+*/
+int sqlite3_value_bytes(sqlite3_value *pVal){
+ if( sqlite3_value_data(pVal) ){
+ return ((Mem *)pVal)->n;
+ }
+ return 0;
+}
+
+/*
+** Return the number of bytes of data that will be returned by the
+** equivalent sqlite3_value_data16() call.
+*/
+int sqlite3_value_bytes(sqlite3_value *pVal){
+ if( sqlite3_value_data16(pVal) ){
+ return ((Mem *)pVal)->n;
+ }
+ return 0;
+}
+
+/*
+** Return the value of the sqlite_value* argument coerced to a 64-bit
+** integer.
+*/
+long long int sqlite3_value_int(sqlite3_value *pVal){
+ Mem *pMem = (Mem *)pVal;
+ Integerify(pMem, flagsToEnc(pMem->flags));
+ return pVal->i;
+}
+
+/*
+** Return the value of the sqlite_value* argument coerced to a 64-bit
+** IEEE float.
+*/
+double sqlite3_value_float(sqlite3_value*){
+ pVal = &pVm->pTos[(1-vals)+i];
+ Realify(pVal, flagsToEnc(pMem->flags));
+ return pVal->r;
+}
+
+/*
+** Return the number of bytes of data that will be returned by the
** equivalent sqlite3_column_data() call.
*/
int sqlite3_column_bytes(sqlite3_stmt *pStmt, int i){
@@ -674,8 +716,7 @@ long long int sqlite3_column_int(sqlite3_stmt *pStmt, int i){
}
pVal = &pVm->pTos[(1-vals)+i];
- Integerify(pVal, pVm->db->enc);
- return pVal->i;
+ return sqlite3_value_int(pVal);
}
/*
@@ -693,9 +734,7 @@ double sqlite3_column_float(sqlite3_stmt *pStmt, int i){
return 0;
}
- pVal = &pVm->pTos[(1-vals)+i];
- Realify(pVal, pVm->db->enc);
- return pVal->r;
+ return sqlite3_value_float(pVal);
}
/*
@@ -714,6 +753,29 @@ const char *sqlite3_column_name(sqlite3_stmt *pStmt, int N){
}
/*
+** Return the type of the value stored in the sqlite_value* object.
+*/
+int sqlite3_value_type(sqlite3_value* pVal){
+ int f = ((Mem *)pVal)->flags;
+ if( f&MEM_Null ){
+ return SQLITE3_NULL;
+ }
+ if( f&MEM_Int ){
+ return SQLITE3_INTEGER;
+ }
+ if( f&MEM_Real ){
+ return SQLITE3_FLOAT;
+ }
+ if( f&MEM_Str ){
+ return SQLITE3_TEXT;
+ }
+ if( f&MEM_Blob ){
+ return SQLITE3_BLOB;
+ }
+ assert(0);
+}
+
+/*
** Return the type of the 'i'th column of the current row of the currently
** executing statement pStmt.
*/