webmcp
changeset 380:16baed4c0483
Extended _column_info table to be an associative array as well (in addition to a sequence); Allow direct (proxy) access to fields of JSON object in a special column (completed write access)
author | jbe |
---|---|
date | Mon Nov 16 01:33:02 2015 +0100 (2015-11-16) |
parents | 4b1d88f77ab8 |
children | 46ff54bbd10e |
files | libraries/mondelefant/mondelefant_native.c |
line diff
1.1 --- a/libraries/mondelefant/mondelefant_native.c Mon Nov 16 01:01:51 2015 +0100 1.2 +++ b/libraries/mondelefant/mondelefant_native.c Mon Nov 16 01:33:02 2015 +0100 1.3 @@ -1012,8 +1012,12 @@ 1.4 lua_newtable(L); // 6 1.5 for (col = 0; col < cols; col++) { 1.6 lua_newtable(L); // 7 1.7 - lua_pushstring(L, PQfname(res, col)); 1.8 + lua_pushstring(L, PQfname(res, col)); // 8 1.9 + lua_pushvalue(L, 8); // 9 1.10 + lua_pushvalue(L, 7); // 10 1.11 + lua_rawset(L, 6); 1.12 lua_setfield(L, 7, "field_name"); 1.13 + // _column_info entry (for current column) on stack position 7 1.14 { 1.15 Oid tmp; 1.16 tmp = PQftable(res, col); 1.17 @@ -1690,6 +1694,26 @@ 1.18 return 0; 1.19 } 1.20 lua_settop(L, 5); 1.21 + // check proxy access to document in special column: 1.22 + if (lua_toboolean(L, 4)) { 1.23 + lua_getfield(L, 1, "_column_info"); // 6 1.24 + lua_pushvalue(L, 2); // 7 1.25 + lua_gettable(L, 6); // 7 1.26 + if (lua_toboolean(L, 7)) { 1.27 + lua_settop(L, 5); 1.28 + lua_pushvalue(L, 4); // 6 1.29 + // _data table is on stack position 5 1.30 + // document column name is on stack position 4 and 6 1.31 + lua_gettable(L, 5); // 6 1.32 + if (!lua_isnil(L, 6)) { 1.33 + lua_pushvalue(L, 2); // 7 1.34 + lua_pushvalue(L, 3); // 8 1.35 + lua_settable(L, 6); 1.36 + return 0; 1.37 + } 1.38 + } 1.39 + lua_settop(L, 5); 1.40 + } 1.41 // store value in data field info: 1.42 lua_pushvalue(L, 2); // 6 1.43 lua_pushvalue(L, 3); // 7