@@ -1812,14 +1812,8 @@ static int L_DatabaseColumnText (lua_State *L)
1812
1812
return 1 ; // number of result fields
1813
1813
} // end of L_DatabaseColumnText
1814
1814
1815
- // ----------------------------------------
1816
- // world.DatabaseColumnValue
1817
- // ----------------------------------------
1818
- static int L_DatabaseColumnValue (lua_State *L)
1815
+ static void GetDatabaseColumnValue (lua_State *L, CMUSHclientDoc *pDoc, LPCTSTR Name, int Column)
1819
1816
{
1820
- CMUSHclientDoc *pDoc = doc (L);
1821
- LPCTSTR Name = my_checkstring (L, 1 ); // Name
1822
- int Column = my_checknumber (L, 2 ); // Column
1823
1817
1824
1818
tDatabaseMapIterator it = pDoc->m_Databases .find (Name);
1825
1819
@@ -1862,6 +1856,19 @@ static int L_DatabaseColumnValue (lua_State *L)
1862
1856
else
1863
1857
lua_pushnil (L);
1864
1858
1859
+ } // end of GetDatabaseColumnValue
1860
+
1861
+ // ----------------------------------------
1862
+ // world.DatabaseColumnValue
1863
+ // ----------------------------------------
1864
+ static int L_DatabaseColumnValue (lua_State *L)
1865
+ {
1866
+ CMUSHclientDoc *pDoc = doc (L);
1867
+ LPCTSTR Name = my_checkstring (L, 1 ); // Name
1868
+ int Column = my_checknumber (L, 2 ); // Column
1869
+
1870
+ GetDatabaseColumnValue (L, pDoc, Name, Column);
1871
+
1865
1872
return 1 ; // number of result fields
1866
1873
} // end of L_DatabaseColumnValue
1867
1874
@@ -1908,11 +1915,30 @@ static int L_DatabaseChanges (lua_State *L)
1908
1915
static int L_DatabaseGetField (lua_State *L)
1909
1916
{
1910
1917
CMUSHclientDoc *pDoc = doc (L);
1911
- VARIANT v = pDoc->DatabaseGetField (
1912
- my_checkstring (L, 1 ), // Name
1913
- my_checkstring (L, 2 ) // Sql
1914
- );
1915
- return pushVariant (L, v); // number of result fields
1918
+ LPCTSTR Name = my_checkstring (L, 1 ); // Name
1919
+ LPCTSTR Sql = my_checkstring (L, 2 ); // Sql
1920
+
1921
+ // prepare the SQL statement
1922
+ long rc = pDoc->DatabasePrepare (Name, Sql);
1923
+
1924
+ if (rc != SQLITE_OK)
1925
+ lua_pushnil (L); // could not prepare statement, give up
1926
+ else
1927
+ {
1928
+ // step to get one row
1929
+ rc = pDoc->DatabaseStep (Name);
1930
+
1931
+ // if we got one, extract the value from column 1
1932
+ if (rc == SQLITE_ROW)
1933
+ GetDatabaseColumnValue (L, pDoc, Name, 1 );
1934
+ else
1935
+ lua_pushnil (L); // did not get a row
1936
+
1937
+ // finalize the current statement
1938
+ pDoc->DatabaseFinalize (Name);
1939
+ } // end of if could prepare SQL
1940
+
1941
+ return 1 ; // number of result fields
1916
1942
} // end of L_DatabaseGetField
1917
1943
1918
1944
// ----------------------------------------
0 commit comments