diff options
author | Pixel <pixel@nobis-crew.org> | 2009-10-08 10:08:47 -0700 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2009-10-08 10:08:47 -0700 |
commit | 56d07c65e3966566c3e50045fc72f6a36ea0bcd6 (patch) | |
tree | 3c8f5de842ab8130771ac9dfa3d0b9d0df5c2fe0 | |
parent | 008b684090a2c0f1ca6e1fb3a7c4587de1fb9bfd (diff) |
Fixing once and for all that ugly baby of to_charp and extract from String, and fixing a couple of minor issues with dblib.lua
-rw-r--r-- | lib/HttpServ.cc | 5 | ||||
-rw-r--r-- | lib/String.cc | 14 | ||||
-rw-r--r-- | lib/dblib.lua | 7 |
3 files changed, 20 insertions, 6 deletions
diff --git a/lib/HttpServ.cc b/lib/HttpServ.cc index 80448a8..2e1779b 100644 --- a/lib/HttpServ.cc +++ b/lib/HttpServ.cc @@ -596,8 +596,7 @@ bool ProcessRequest::ParseUri(String & file, String & domain, String & gvars, Ha ssize_t poshttp, posslash; Uri = p; sppos = Uri.strrchr(' '); - p = Uri.to_charp(0, sppos - 1); - Uri = p; + Uri = Uri.extract(0, sppos - 1); // On enlève tout le host spécifié éventuellement dans la requete. if ((poshttp = Uri.strstr("http://")) > 0) { Uri = Uri.to_charp(poshttp + 7); @@ -615,7 +614,7 @@ bool ProcessRequest::ParseUri(String & file, String & domain, String & gvars, Ha posslash = Uri.strrchr('/'); file = Uri.to_charp(posslash + 1); if (posslash > 0) { - domain = Uri.to_charp(0, posslash - 1); + domain = Uri.extract(0, posslash - 1); } else { domain = ""; } diff --git a/lib/String.cc b/lib/String.cc index c960992..674e3a3 100644 --- a/lib/String.cc +++ b/lib/String.cc @@ -258,7 +258,19 @@ const char * String::to_charp(size_t from, ssize_t to) const throw (GeneralExcep } String String::extract(size_t from, ssize_t to) const { - return String(to_charp(from, to)); + if (to < 0) { + return String(to_charp(from)); + } else { + to++; + if (siz == 0) { + return ""; + } + if (((size_t) to) >= siz) { + to = siz - 1; + } + + return String(to_charp(from), to - from); + } } char * String::strdup(size_t from, ssize_t to) const { diff --git a/lib/dblib.lua b/lib/dblib.lua index a47b755..f9130be 100644 --- a/lib/dblib.lua +++ b/lib/dblib.lua @@ -905,7 +905,7 @@ END; if query_type == "update" or query_type == "raw" then if query_type == "update" then - str = str:gsub(" *(.*) *;", "%1") + str = str:gsub("%s*(.*)%s*;", "%1") end db._.affectedRows = stmt:executeUpdate(str) if db._.affectedRows == nil then @@ -923,7 +923,7 @@ END; r = 0 end elseif query_type == "query" then - str = str:gsub(" *(.*) *;", "%1") + str = str:gsub("%s*(.*)%s*;", "%1") local rset = stmt:executeQuery(str) if rset then db._.errNO = 0 @@ -1122,6 +1122,9 @@ luadb = { id = id._.id end conn = l_env:createConnection(user, password, base) + if not conn then + return nil, l_env:getErrorCode(), l_env:getErrorMsg() + end return { opentable = _luadb.opentable, SafeQuery = _luadb.oracle.SafeQuery, |