Fossil SCM

fixed: json_cap_value() now returns NULL (instead of prematurely/fataly querying the db) if g.userUid has not been set (i.e. CLI mode).

stephan 2011-10-09 11:57 UTC json-multitag-test
Commit 96920e7c04746c55ceed6e24fc82879886cb8197
1 file changed +15 -11
+15 -11
--- src/json.c
+++ src/json.c
@@ -1908,21 +1908,25 @@
19081908
** Returned value is owned by the caller, and will only be NULL if
19091909
** g.userUid is invalid or an out of memory error. Or, it turns out,
19101910
** in CLI mode (where there is no logged-in user).
19111911
*/
19121912
cson_value * json_cap_value(){
1913
- Stmt q;
1914
- cson_value * val = NULL;
1915
- db_prepare(&q, "SELECT cap FROM user WHERE uid=%d", g.userUid);
1916
- if( db_step(&q)==SQLITE_ROW ){
1917
- char const * str = (char const *)sqlite3_column_text(q.pStmt,0);
1918
- if( str ){
1919
- val = json_new_string(str);
1920
- }
1921
- }
1922
- db_finalize(&q);
1923
- return val;
1913
+ if(g.userUid<=0){
1914
+ return NULL;
1915
+ }else{
1916
+ Stmt q = empty_Stmt;
1917
+ cson_value * val = NULL;
1918
+ db_prepare(&q, "SELECT cap FROM user WHERE uid=%d", g.userUid);
1919
+ if( db_step(&q)==SQLITE_ROW ){
1920
+ char const * str = (char const *)sqlite3_column_text(q.pStmt,0);
1921
+ if( str ){
1922
+ val = json_new_string(str);
1923
+ }
1924
+ }
1925
+ db_finalize(&q);
1926
+ return val;
1927
+ }
19241928
}
19251929
19261930
/*
19271931
** Implementation for /json/cap
19281932
**
19291933
--- src/json.c
+++ src/json.c
@@ -1908,21 +1908,25 @@
1908 ** Returned value is owned by the caller, and will only be NULL if
1909 ** g.userUid is invalid or an out of memory error. Or, it turns out,
1910 ** in CLI mode (where there is no logged-in user).
1911 */
1912 cson_value * json_cap_value(){
1913 Stmt q;
1914 cson_value * val = NULL;
1915 db_prepare(&q, "SELECT cap FROM user WHERE uid=%d", g.userUid);
1916 if( db_step(&q)==SQLITE_ROW ){
1917 char const * str = (char const *)sqlite3_column_text(q.pStmt,0);
1918 if( str ){
1919 val = json_new_string(str);
1920 }
1921 }
1922 db_finalize(&q);
1923 return val;
 
 
 
 
1924 }
1925
1926 /*
1927 ** Implementation for /json/cap
1928 **
1929
--- src/json.c
+++ src/json.c
@@ -1908,21 +1908,25 @@
1908 ** Returned value is owned by the caller, and will only be NULL if
1909 ** g.userUid is invalid or an out of memory error. Or, it turns out,
1910 ** in CLI mode (where there is no logged-in user).
1911 */
1912 cson_value * json_cap_value(){
1913 if(g.userUid<=0){
1914 return NULL;
1915 }else{
1916 Stmt q = empty_Stmt;
1917 cson_value * val = NULL;
1918 db_prepare(&q, "SELECT cap FROM user WHERE uid=%d", g.userUid);
1919 if( db_step(&q)==SQLITE_ROW ){
1920 char const * str = (char const *)sqlite3_column_text(q.pStmt,0);
1921 if( str ){
1922 val = json_new_string(str);
1923 }
1924 }
1925 db_finalize(&q);
1926 return val;
1927 }
1928 }
1929
1930 /*
1931 ** Implementation for /json/cap
1932 **
1933

Keyboard Shortcuts

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