Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| SHA1 Hash: | 8027581c5e9e8754d9a629bc94b3baa7980d9e61 |
|---|---|
| Date: | 2012-07-15 12:52:17 |
| User: | stephan |
| Comment: | Made a few more functions static. th1 ob doc additions. |
Tags And Properties
- branch=th1-query-api inherited from [c3b10e12a1]
- sym-th1-query-api inherited from [c3b10e12a1]
Changes
Changes to src/th_main.c
849 ** pStmt is transfered to interp and it must be cleaned up by the 849 ** pStmt is transfered to interp and it must be cleaned up by the 850 ** client by calling Th_FinalizeStmt(), passing it the value returned 850 ** client by calling Th_FinalizeStmt(), passing it the value returned 851 ** by this function. 851 ** by this function. 852 ** 852 ** 853 ** If interp is destroyed before all statements are finalized, 853 ** If interp is destroyed before all statements are finalized, 854 ** it will finalize them but may emit a warning message. 854 ** it will finalize them but may emit a warning message. 855 */ 855 */ 856 int Th_AddStmt(Th_Interp *interp, sqlite3_stmt * pStmt); | 856 static int Th_AddStmt(Th_Interp *interp, sqlite3_stmt * pStmt); 857 857 858 /* 858 /* 859 ** Expects stmtId to be a statement identifier returned by 859 ** Expects stmtId to be a statement identifier returned by 860 ** Th_AddStmt(). On success, finalizes the statement and returns 0. 860 ** Th_AddStmt(). On success, finalizes the statement and returns 0. 861 ** On error (statement not found) non-0 is returned. After this 861 ** On error (statement not found) non-0 is returned. After this 862 ** call, some subsequent call to Th_AddStmt() may return the 862 ** call, some subsequent call to Th_AddStmt() may return the 863 ** same statement ID. 863 ** same statement ID. 864 */ 864 */ 865 int Th_FinalizeStmt(Th_Interp *interp, int stmtId); | 865 static int Th_FinalizeStmt(Th_Interp *interp, int stmtId); 866 866 867 /* 867 /* 868 ** Fetches the statement with the given ID, as returned by 868 ** Fetches the statement with the given ID, as returned by 869 ** Th_AddStmt(). Returns NULL if stmtId does not refer (or no longer 869 ** Th_AddStmt(). Returns NULL if stmtId does not refer (or no longer 870 ** refers) to a statement added via Th_AddStmt(). 870 ** refers) to a statement added via Th_AddStmt(). 871 */ 871 */ 872 sqlite3_stmt * Th_GetStmt(Th_Interp *interp, int stmtId); | 872 static sqlite3_stmt * Th_GetStmt(Th_Interp *interp, int stmtId); 873 873 874 874 875 struct Th_Sqlite { 875 struct Th_Sqlite { 876 sqlite3_stmt ** aStmt; 876 sqlite3_stmt ** aStmt; 877 int nStmt; 877 int nStmt; 878 }; 878 }; 879 #define Th_Sqlite_KEY "Th_Sqlite" 879 #define Th_Sqlite_KEY "Th_Sqlite" ................................................................................................................................................................................ 880 typedef struct Th_Sqlite Th_Sqlite; 880 typedef struct Th_Sqlite Th_Sqlite; 881 881 882 static Th_Sqlite * Th_sqlite_manager( Th_Interp * interp ){ 882 static Th_Sqlite * Th_sqlite_manager( Th_Interp * interp ){ 883 void * p = Th_Data_Get( interp, Th_Sqlite_KEY ); 883 void * p = Th_Data_Get( interp, Th_Sqlite_KEY ); 884 return p ? (Th_Sqlite*)p : NULL; 884 return p ? (Th_Sqlite*)p : NULL; 885 } 885 } 886 886 887 int Th_AddStmt(Th_Interp *interp, sqlite3_stmt * pStmt){ | 887 static int Th_AddStmt(Th_Interp *interp, sqlite3_stmt * pStmt){ 888 Th_Sqlite * sq = Th_sqlite_manager(interp); 888 Th_Sqlite * sq = Th_sqlite_manager(interp); 889 int i, x; 889 int i, x; 890 sqlite3_stmt * s; 890 sqlite3_stmt * s; 891 sqlite3_stmt ** list = sq->aStmt; 891 sqlite3_stmt ** list = sq->aStmt; 892 for( i = 0; i < sq->nStmt; ++i ){ 892 for( i = 0; i < sq->nStmt; ++i ){ 893 s = list[i]; 893 s = list[i]; 894 if(NULL==s){ 894 if(NULL==s){ ................................................................................................................................................................................ 905 x = sq->nStmt; 905 x = sq->nStmt; 906 sq->nStmt = i; 906 sq->nStmt = i; 907 sq->aStmt = list; 907 sq->aStmt = list; 908 return x + 1; 908 return x + 1; 909 } 909 } 910 910 911 911 912 int Th_FinalizeStmt(Th_Interp *interp, int stmtId){ | 912 static int Th_FinalizeStmt(Th_Interp *interp, int stmtId){ 913 Th_Sqlite * sq = Th_sqlite_manager(interp); 913 Th_Sqlite * sq = Th_sqlite_manager(interp); 914 sqlite3_stmt * st; 914 sqlite3_stmt * st; 915 int rc = 0; 915 int rc = 0; 916 assert( stmtId>0 && stmtId<=sq->nStmt ); 916 assert( stmtId>0 && stmtId<=sq->nStmt ); 917 st = sq->aStmt[stmtId-1]; 917 st = sq->aStmt[stmtId-1]; 918 if(NULL != st){ 918 if(NULL != st){ 919 sq->aStmt[stmtId-1] = NULL; 919 sq->aStmt[stmtId-1] = NULL; ................................................................................................................................................................................ 920 sqlite3_finalize(st); 920 sqlite3_finalize(st); 921 return 0; 921 return 0; 922 }else{ 922 }else{ 923 return 1; 923 return 1; 924 } 924 } 925 } 925 } 926 926 927 sqlite3_stmt * Th_GetStmt(Th_Interp *interp, int stmtId){ | 927 static sqlite3_stmt * Th_GetStmt(Th_Interp *interp, int stmtId){ 928 Th_Sqlite * sq = Th_sqlite_manager(interp); 928 Th_Sqlite * sq = Th_sqlite_manager(interp); 929 return ((stmtId<1) || (stmtId > sq->nStmt)) 929 return ((stmtId<1) || (stmtId > sq->nStmt)) 930 ? NULL 930 ? NULL 931 : sq->aStmt[stmtId-1]; 931 : sq->aStmt[stmtId-1]; 932 } 932 } 933 933 934 934 935 static void finalizerSqlite( Th_Interp * interp, void * p ){ 935 static void finalizerSqlite( Th_Interp * interp, void * p ){ 936 Th_Sqlite * sq = Th_sqlite_manager( interp ); | 936 Th_Sqlite * sq = (Th_Sqlite *)p; 937 int i; 937 int i; 938 sqlite3_stmt * st = NULL; 938 sqlite3_stmt * st = NULL; 939 if(!sq) { 939 if(!sq) { 940 fossil_warning("Got a finalizer call for a NULL Th_Sqlite."); 940 fossil_warning("Got a finalizer call for a NULL Th_Sqlite."); 941 return; 941 return; 942 } 942 } 943 for( i = 0; i < sq->nStmt; ++i ){ 943 for( i = 0; i < sq->nStmt; ++i ){ 944 st = sq->aStmt[i]; 944 st = sq->aStmt[i]; 945 if(NULL != st){ 945 if(NULL != st){ 946 fossil_warning("Auto-finalizing unfinalized query_prepare " | 946 fossil_warning("Auto-finalizing unfinalized " 947 "statement id #%d: %s", 947 "statement id #%d: %s", 948 i+1, sqlite3_sql(st)); 948 i+1, sqlite3_sql(st)); 949 Th_FinalizeStmt( interp, i+1 ); 949 Th_FinalizeStmt( interp, i+1 ); 950 } 950 } 951 } 951 } 952 Th_Free(interp, sq->aStmt); 952 Th_Free(interp, sq->aStmt); 953 Th_Free(interp, sq); 953 Th_Free(interp, sq);
Changes to www/th1_ob.wiki
9 * Supports nesting buffering arbitrarily deep, but each level which gets ope 9 * Supports nesting buffering arbitrarily deep, but each level which gets ope 10 10 11 Example usage: 11 Example usage: 12 12 13 <nowiki><pre> 13 <nowiki><pre> 14 <th1> 14 <th1> 15 puts "this is unbuffered" 15 puts "this is unbuffered" 16 ob start | 16 ob push # or: ob start (same thing) 17 # all output until the next ob start|end gets collected 17 # all output until the next ob start|end gets collected 18 # in a buffer... 18 # in a buffer... 19 </th1> 19 </th1> 20 20 21 this is buffered 21 this is buffered 22 22 23 <th1> 23 <th1> 24 puts "current buffer level = " [ob level] "\n" 24 puts "current buffer level = " [ob level] "\n" 25 puts "this part is also collected in the buffer." 25 puts "this part is also collected in the buffer." 26 26 27 # Collect the buffer's contents: 27 # Collect the buffer's contents: 28 set buf [ob get end] | 28 set buf [ob get pop] 29 # That is equivalent to: 29 # That is equivalent to: 30 # set buf [ob get] 30 # set buf [ob get] 31 # ob end | 31 # ob pop 32 32 33 puts "\nThis is now unbuffered, but we buffered: $buf\n" 33 puts "\nThis is now unbuffered, but we buffered: $buf\n" 34 </th1> 34 </th1> 35 </pre></nowiki> 35 </pre></nowiki> 36 36 37 The functions are summarized below... 37 The functions are summarized below... 38 38 39 <h2>ob start</h2> | 39 <h2>ob push|start</h2> > 40 > 41 <tt>push</tt> and <tt>start</tt> are aliases ("start" comes from the PHP API, bu > 42 "push" is probably more natural to those working with th1). 40 43 41 <tt>ob start</tt> pushes a level of buffering onto the buffer stack, such that 44 <tt>ob start</tt> pushes a level of buffering onto the buffer stack, such that 42 future calls which generate output through the th1-internal mechanism will have 45 future calls which generate output through the th1-internal mechanism will have 43 transparently redirected to the current buffer. 46 transparently redirected to the current buffer. 44 47 45 It is important that every call to <tt>ob start</tt> be followed up (eventually) 48 It is important that every call to <tt>ob start</tt> be followed up (eventually) 46 by either <tt>ob end</tt> or <tt>ob get end</tt>. 49 by either <tt>ob end</tt> or <tt>ob get end</tt>. 47 50 48 <h2>ob end</h2> | 51 <h2>ob pop|end</h2> > 52 > 53 <tt>pop</tt> and <tt>end</tt> are aliases ("end" comes from the PHP API, but > 54 "pop" is probably more natural to those working with th1). 49 55 50 This discards any current buffered contents and reverts the output state to 56 This discards any current buffered contents and reverts the output state to 51 the one it had before the previous <tt>ob start</tt>. i.e. that might be another 57 the one it had before the previous <tt>ob start</tt>. i.e. that might be another 52 buffering level or it might be the th1-normal output mechanism. 58 buffering level or it might be the th1-normal output mechanism. 53 59 54 The global resources associated with buffering are cleaned up when the 60 The global resources associated with buffering are cleaned up when the 55 last buffering level is left (and re-created as needed when a new 61 last buffering level is left (and re-created as needed when a new ................................................................................................................................................................................ 59 65 60 This discards the current contents of the current buffer level but 66 This discards the current contents of the current buffer level but 61 does not change the buffer stack level. 67 does not change the buffer stack level. 62 68 63 <h2>ob get</h2> 69 <h2>ob get</h2> 64 70 65 This fetches the current contents as a string. It optionally accepts 71 This fetches the current contents as a string. It optionally accepts 66 either <tt>end</tt> or <tt>clean</tt>, in which cases it behaves like | 72 either <tt>end</tt> (or its alias <tt>pop</tt>) or <tt>clean</tt>, in which case 67 either <tt>ob end</tt> or <tt>ob clean</tt>, respectively, in addition | 73 either <tt>ob end|pop</tt> or <tt>ob clean</tt>, respectively, in addition 68 to returning the buffer contents. i.e. <tt>ob get clean</tt> will 74 to returning the buffer contents. i.e. <tt>ob get clean</tt> will 69 fetch the contents and clean up the buffer, but does not change the 75 fetch the contents and clean up the buffer, but does not change the 70 buffering level, whereas <tt>ob get end</tt> pops the buffer off the | 76 buffering level, whereas <tt>ob get end|pop</tt> pops the buffer off the 71 stack after fetching its contents. 77 stack after fetching its contents. 72 78 73 <h2>ob level</h2> 79 <h2>ob level</h2> 74 80 75 Returns the current buffering level (0 if not buffering). 81 Returns the current buffering level (0 if not buffering). 76 82 77 <h2>ob flush</h2> 83 <h2>ob flush</h2> ................................................................................................................................................................................ 79 It is not expected that this will be useful all that often, but for 85 It is not expected that this will be useful all that often, but for 80 the cases where it is, here's how it works: this behaves as if we 86 the cases where it is, here's how it works: this behaves as if we 81 fetched the buffer state (<tt>ob get</tt>), reverted TH1 to its 87 fetched the buffer state (<tt>ob get</tt>), reverted TH1 to its 82 previous output mechanism, push the buffer state to TH1, revert TH1 88 previous output mechanism, push the buffer state to TH1, revert TH1 83 <em>back</em> to the current buffering state, and then clear the 89 <em>back</em> to the current buffering state, and then clear the 84 current buffer contents (like <tt>ob clean</tt>). This does not change 90 current buffer contents (like <tt>ob clean</tt>). This does not change 85 the buffering level, though it temporarily behaves as if it does. 91 the buffering level, though it temporarily behaves as if it does. > 92 > 93 In other words, this function pushes the current buffer contents to the > 94 next-lower output mechanism (which may be another ob buffering level, > 95 fossil's internal CGI output buffer, or it might be be > 96 <tt>fwrite(stdout)</tt>).