Fossil SCM

Pulled in latest cson_amalgamation for cson_sqlite3_bind_value().

stephan 2012-03-31 14:35 trunk
Commit 1eec62808d82759b2f171d907aa6cd1986f550e0
--- src/cson_amalgamation.c
+++ src/cson_amalgamation.c
@@ -5629,10 +5629,66 @@
56295629
rc = cson_sqlite3_stmt_to_json( st, tgt, fat );
56305630
sqlite3_finalize( st );
56315631
return rc;
56325632
}
56335633
}
5634
+
5635
+int cson_sqlite3_bind_value( sqlite3_stmt * st, int ndx, cson_value const * v )
5636
+{
5637
+ int rc = 0;
5638
+ char convertErr = 0;
5639
+ if(!st) return cson_rc.ArgError;
5640
+ else if( ndx < 1 ) {
5641
+ rc = cson_rc.RangeError;
5642
+ }
5643
+ else if( cson_value_is_array(v) ){
5644
+ cson_array * ar = cson_value_get_array(v);
5645
+ unsigned int len = cson_array_length_get(ar);
5646
+ unsigned int i;
5647
+ assert(NULL != ar);
5648
+ for( i = 0; !rc && (i < len); ++i ){
5649
+ rc = cson_sqlite3_bind_value( st, (int)i+ndx,
5650
+ cson_array_get(ar, i));
5651
+ }
5652
+ }
5653
+ else if(!v || cson_value_is_null(v)){
5654
+ rc = sqlite3_bind_null(st,ndx);
5655
+ convertErr = 1;
5656
+ }
5657
+ else if( cson_value_is_double(v) ){
5658
+ rc = sqlite3_bind_double( st, ndx, cson_value_get_double(v) );
5659
+ convertErr = 1;
5660
+ }
5661
+ else if( cson_value_is_bool(v) ){
5662
+ rc = sqlite3_bind_int( st, ndx, cson_value_get_bool(v) ? 1 : 0 );
5663
+ convertErr = 1;
5664
+ }
5665
+ else if( cson_value_is_integer(v) ){
5666
+ rc = sqlite3_bind_int64( st, ndx, cson_value_get_integer(v) );
5667
+ convertErr = 1;
5668
+ }
5669
+ else if( cson_value_is_string(v) ){
5670
+ cson_string const * s = cson_value_get_string(v);
5671
+ rc = sqlite3_bind_text( st, ndx,
5672
+ cson_string_cstr(s),
5673
+ cson_string_length_bytes(s),
5674
+ SQLITE_TRANSIENT);
5675
+ convertErr = 1;
5676
+ }
5677
+ else {
5678
+ rc = cson_rc.TypeError;
5679
+ }
5680
+ if(convertErr && rc) switch(rc){
5681
+ case SQLITE_TOOBIG:
5682
+ case SQLITE_RANGE: rc = cson_rc.RangeError; break;
5683
+ case SQLITE_NOMEM: rc = cson_rc.AllocError; break;
5684
+ case SQLITE_IOERR: rc = cson_rc.IOError; break;
5685
+ default: rc = cson_rc.UnknownError; break;
5686
+ };
5687
+ return rc;
5688
+}
5689
+
56345690
56355691
#if defined(__cplusplus)
56365692
} /*extern "C"*/
56375693
#endif
56385694
#undef MARKER
56395695
--- src/cson_amalgamation.c
+++ src/cson_amalgamation.c
@@ -5629,10 +5629,66 @@
5629 rc = cson_sqlite3_stmt_to_json( st, tgt, fat );
5630 sqlite3_finalize( st );
5631 return rc;
5632 }
5633 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5634
5635 #if defined(__cplusplus)
5636 } /*extern "C"*/
5637 #endif
5638 #undef MARKER
5639
--- src/cson_amalgamation.c
+++ src/cson_amalgamation.c
@@ -5629,10 +5629,66 @@
5629 rc = cson_sqlite3_stmt_to_json( st, tgt, fat );
5630 sqlite3_finalize( st );
5631 return rc;
5632 }
5633 }
5634
5635 int cson_sqlite3_bind_value( sqlite3_stmt * st, int ndx, cson_value const * v )
5636 {
5637 int rc = 0;
5638 char convertErr = 0;
5639 if(!st) return cson_rc.ArgError;
5640 else if( ndx < 1 ) {
5641 rc = cson_rc.RangeError;
5642 }
5643 else if( cson_value_is_array(v) ){
5644 cson_array * ar = cson_value_get_array(v);
5645 unsigned int len = cson_array_length_get(ar);
5646 unsigned int i;
5647 assert(NULL != ar);
5648 for( i = 0; !rc && (i < len); ++i ){
5649 rc = cson_sqlite3_bind_value( st, (int)i+ndx,
5650 cson_array_get(ar, i));
5651 }
5652 }
5653 else if(!v || cson_value_is_null(v)){
5654 rc = sqlite3_bind_null(st,ndx);
5655 convertErr = 1;
5656 }
5657 else if( cson_value_is_double(v) ){
5658 rc = sqlite3_bind_double( st, ndx, cson_value_get_double(v) );
5659 convertErr = 1;
5660 }
5661 else if( cson_value_is_bool(v) ){
5662 rc = sqlite3_bind_int( st, ndx, cson_value_get_bool(v) ? 1 : 0 );
5663 convertErr = 1;
5664 }
5665 else if( cson_value_is_integer(v) ){
5666 rc = sqlite3_bind_int64( st, ndx, cson_value_get_integer(v) );
5667 convertErr = 1;
5668 }
5669 else if( cson_value_is_string(v) ){
5670 cson_string const * s = cson_value_get_string(v);
5671 rc = sqlite3_bind_text( st, ndx,
5672 cson_string_cstr(s),
5673 cson_string_length_bytes(s),
5674 SQLITE_TRANSIENT);
5675 convertErr = 1;
5676 }
5677 else {
5678 rc = cson_rc.TypeError;
5679 }
5680 if(convertErr && rc) switch(rc){
5681 case SQLITE_TOOBIG:
5682 case SQLITE_RANGE: rc = cson_rc.RangeError; break;
5683 case SQLITE_NOMEM: rc = cson_rc.AllocError; break;
5684 case SQLITE_IOERR: rc = cson_rc.IOError; break;
5685 default: rc = cson_rc.UnknownError; break;
5686 };
5687 return rc;
5688 }
5689
5690
5691 #if defined(__cplusplus)
5692 } /*extern "C"*/
5693 #endif
5694 #undef MARKER
5695
--- src/cson_amalgamation.h
+++ src/cson_amalgamation.h
@@ -2494,10 +2494,29 @@
24942494
takes SQL instead of a sqlite3_stmt object. It has the same
24952495
return value and argument semantics as that function.
24962496
*/
24972497
int cson_sqlite3_sql_to_json( sqlite3 * db, cson_value ** tgt, char const * sql, char fat );
24982498
2499
+/**
2500
+ Binds a JSON value to a 1-based parameter index in a prepared SQL
2501
+ statement. v must be NULL or one of one of the types (null, string,
2502
+ integer, double, boolean, array). Booleans are bound as integer 0
2503
+ or 1. NULL or null are bound as SQL NULL. Integers are bound as
2504
+ 64-bit ints. Strings are bound using sqlite3_bind_text() (as
2505
+ opposed to text16), but we could/should arguably bind them as
2506
+ blobs.
2507
+
2508
+ If v is an Array then ndx is is used as a starting position
2509
+ (1-based) and each item in the array is bound to the next parameter
2510
+ position (starting and ndx, though the array uses 0-based offsets).
2511
+
2512
+ TODO: add Object support for named parameters.
2513
+
2514
+ Returns 0 on success, non-0 on error.
2515
+ */
2516
+int cson_sqlite3_bind_value( sqlite3_stmt * st, int ndx, cson_value const * v );
2517
+
24992518
#if defined(__cplusplus)
25002519
} /*extern "C"*/
25012520
#endif
25022521
25032522
#endif /* CSON_ENABLE_SQLITE3 */
25042523
--- src/cson_amalgamation.h
+++ src/cson_amalgamation.h
@@ -2494,10 +2494,29 @@
2494 takes SQL instead of a sqlite3_stmt object. It has the same
2495 return value and argument semantics as that function.
2496 */
2497 int cson_sqlite3_sql_to_json( sqlite3 * db, cson_value ** tgt, char const * sql, char fat );
2498
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2499 #if defined(__cplusplus)
2500 } /*extern "C"*/
2501 #endif
2502
2503 #endif /* CSON_ENABLE_SQLITE3 */
2504
--- src/cson_amalgamation.h
+++ src/cson_amalgamation.h
@@ -2494,10 +2494,29 @@
2494 takes SQL instead of a sqlite3_stmt object. It has the same
2495 return value and argument semantics as that function.
2496 */
2497 int cson_sqlite3_sql_to_json( sqlite3 * db, cson_value ** tgt, char const * sql, char fat );
2498
2499 /**
2500 Binds a JSON value to a 1-based parameter index in a prepared SQL
2501 statement. v must be NULL or one of one of the types (null, string,
2502 integer, double, boolean, array). Booleans are bound as integer 0
2503 or 1. NULL or null are bound as SQL NULL. Integers are bound as
2504 64-bit ints. Strings are bound using sqlite3_bind_text() (as
2505 opposed to text16), but we could/should arguably bind them as
2506 blobs.
2507
2508 If v is an Array then ndx is is used as a starting position
2509 (1-based) and each item in the array is bound to the next parameter
2510 position (starting and ndx, though the array uses 0-based offsets).
2511
2512 TODO: add Object support for named parameters.
2513
2514 Returns 0 on success, non-0 on error.
2515 */
2516 int cson_sqlite3_bind_value( sqlite3_stmt * st, int ndx, cson_value const * v );
2517
2518 #if defined(__cplusplus)
2519 } /*extern "C"*/
2520 #endif
2521
2522 #endif /* CSON_ENABLE_SQLITE3 */
2523

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button