httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From humbed...@apache.org
Subject svn commit: r1570530 - in /httpd/httpd/branches/2.4.x: CHANGES docs/manual/mod/mod_lua.xml modules/lua/lua_dbd.c
Date Fri, 21 Feb 2014 11:13:53 GMT
Author: humbedooh
Date: Fri Feb 21 11:13:53 2014
New Revision: 1570530

URL: http://svn.apache.org/r1570530
Log:
Backport r1570528

Modified:
    httpd/httpd/branches/2.4.x/CHANGES
    httpd/httpd/branches/2.4.x/docs/manual/mod/mod_lua.xml
    httpd/httpd/branches/2.4.x/modules/lua/lua_dbd.c

Modified: httpd/httpd/branches/2.4.x/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/CHANGES?rev=1570530&r1=1570529&r2=1570530&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/CHANGES [utf-8] (original)
+++ httpd/httpd/branches/2.4.x/CHANGES [utf-8] Fri Feb 21 11:13:53 2014
@@ -29,6 +29,9 @@ Changes with Apache 2.4.8
      the Set-Cookie header. PR56105
      [Kevin J Walters <kjw ms com>, Edward Lu <Chaosed0 gmail com>]
 
+  *) mod_lua: Allow for database results to be returned as a hash with 
+     row-name/value pairs instead of just row-number/value. [Daniel Gruno]
+
   *) mod_rewrite: Add %{CONN_REMOTE_ADDR} as the non-useragent counterpart to
      %{REMOTE_ADDR}. PR 56094. [Edward Lu <Chaosed0 gmail com>]
 

Modified: httpd/httpd/branches/2.4.x/docs/manual/mod/mod_lua.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/docs/manual/mod/mod_lua.xml?rev=1570530&r1=1570529&r2=1570530&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/docs/manual/mod/mod_lua.xml (original)
+++ httpd/httpd/branches/2.4.x/docs/manual/mod/mod_lua.xml Fri Feb 21 11:13:53 2014
@@ -1196,6 +1196,7 @@ local result, err = db:select(r, "SELECT
 local rows = result(0) -- Fetch ALL rows synchronously
 local row = result(-1) -- Fetch the next available row, asynchronously
 local row = result(1234) -- Fetch row number 1234, asynchronously
+local row = result(-1, true) -- Fetch the next available row, using row names as key indexes.
     </highlight>
     <p>One can construct a function that returns an iterative function to iterate over
all rows 
     in a synchronous or asynchronous way, depending on the async argument:

Modified: httpd/httpd/branches/2.4.x/modules/lua/lua_dbd.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/modules/lua/lua_dbd.c?rev=1570530&r1=1570529&r2=1570530&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/modules/lua/lua_dbd.c (original)
+++ httpd/httpd/branches/2.4.x/modules/lua/lua_dbd.c Fri Feb 21 11:13:53 2014
@@ -15,6 +15,7 @@
  * limitations under the License.
  */
 
+
 #include "mod_lua.h"
 #include "lua_dbd.h"
 
@@ -228,15 +229,19 @@ int lua_db_escape(lua_State *L)
  */
 int lua_db_get_row(lua_State *L) 
 {
-    int row_no,x;
-    const char      *entry;
+    int row_no,x,alpha = 0;
+    const char      *entry, *rowname;
     apr_dbd_row_t   *row = 0;
     lua_db_result_set *res = lua_get_result_set(L);
     
     row_no = luaL_optinteger(L, 2, 0);
+    if (lua_isboolean(L, 3)) {
+        alpha = lua_toboolean(L, 3);
+    }
     lua_settop(L,0);
     
     /* Fetch all rows at once? */
+    
     if (row_no == 0) {
         row_no = 1;
         lua_newtable(L);
@@ -248,7 +253,14 @@ int lua_db_get_row(lua_State *L) 
             for (x = 0; x < res->cols; x++) {
                 entry = apr_dbd_get_entry(res->driver, row, x);
                 if (entry) {
-                    lua_pushinteger(L, x + 1);
+                    if (alpha == 1) {
+                        rowname = apr_dbd_get_name(res->driver, 
+                                res->results, x);
+                        lua_pushstring(L, rowname ? rowname : "(oob)");
+                    }
+                    else {
+                        lua_pushinteger(L, x + 1);
+                    }
                     lua_pushstring(L, entry);
                     lua_rawset(L, -3);
                 }
@@ -268,7 +280,14 @@ int lua_db_get_row(lua_State *L) 
         for (x = 0; x < res->cols; x++) {
             entry = apr_dbd_get_entry(res->driver, row, x);
             if (entry) {
-                lua_pushinteger(L, x + 1);
+                if (alpha == 1) {
+                    rowname = apr_dbd_get_name(res->driver, 
+                            res->results, x);
+                    lua_pushstring(L, rowname ? rowname : "(oob)");
+                }
+                else {
+                    lua_pushinteger(L, x + 1);
+                }
                 lua_pushstring(L, entry);
                 lua_rawset(L, -3);
             }



Mime
View raw message