summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rwxr-xr-x[-rw-r--r--]lib/devel/httpclient.nim0
-rwxr-xr-x[-rw-r--r--]lib/devel/parseurl.nim0
-rwxr-xr-xlib/impure/db_postgres.nim28
-rwxr-xr-xlib/system/excpt.nim6
-rwxr-xr-xlib/system/sysio.nim5
5 files changed, 15 insertions, 24 deletions
diff --git a/lib/devel/httpclient.nim b/lib/devel/httpclient.nim
index abea34ea6..abea34ea6 100644..100755
--- a/lib/devel/httpclient.nim
+++ b/lib/devel/httpclient.nim
diff --git a/lib/devel/parseurl.nim b/lib/devel/parseurl.nim
index 769d07561..769d07561 100644..100755
--- a/lib/devel/parseurl.nim
+++ b/lib/devel/parseurl.nim
diff --git a/lib/impure/db_postgres.nim b/lib/impure/db_postgres.nim
index 25a04ed8e..cac5420d4 100755
--- a/lib/impure/db_postgres.nim
+++ b/lib/impure/db_postgres.nim
@@ -21,7 +21,7 @@ proc dbError(db: TDbConn) {.noreturn.} =
   ## raises an EDb exception.
   var e: ref EDb
   new(e)
-  e.msg = PQerrorMessage(db)
+  e.msg = $PQerrorMessage(db)
   raise e
 
 proc dbError*(msg: string) {.noreturn.} = 
@@ -31,17 +31,9 @@ proc dbError*(msg: string) {.noreturn.} =
   e.msg = msg
   raise e
 
-when false:
-  proc dbQueryOpt*(db: TDbConn, query: string, args: openarray[string]) =
-    var stmt = mysql_stmt_init(db)
-    if stmt == nil: dbError(db)
-    if mysql_stmt_prepare(stmt, query, len(query)) != 0: 
-      dbError(db)
-    var 
-      bindings: seq[MYSQL_BIND]
-    discard mysql_stmt_close(stmt)
-
 proc dbQuote(s: string): string =
+  #if s.len > 0 and allCharsInSet(s, {'0'..'9'}): result = s
+  #else:
   result = "'"
   for c in items(s):
     if c == '\'': add(result, "''")
@@ -86,7 +78,8 @@ proc setupQuery(db: TDbConn, query: TSqlQuery,
 proc setRow(res: PPGresult, r: var TRow, line, cols: int) =
   for col in 0..cols-1:
     setLen(r[col], 0)
-    add(r[col], PQgetvalue(res, line, cols))    
+    var x = PQgetvalue(res, line, col)
+    add(r[col], x)
   
 iterator dbFastRows*(db: TDbConn, query: TSqlQuery,
                      args: openarray[string]): TRow =
@@ -118,10 +111,8 @@ proc dbGetValue*(db: TDbConn, query: TSqlQuery,
   ## executes the query and returns the result dataset's the first column 
   ## of the first row. Returns "" if the dataset contains no rows. This uses
   ## `dbFastRows`, so it inherits its fragile behaviour.
-  result = ""
-  for row in dbFastRows(db, query, args): 
-    result = row[0]
-    break
+  var x = PQgetvalue(setupQuery(db, query, args), 0, 0)
+  result = if isNil(x): "" else: $x
   
 proc dbTryInsertID*(db: TDbConn, query: TSqlQuery, 
                     args: openarray[string]): int64 =
@@ -134,11 +125,6 @@ proc dbTryInsertID*(db: TDbConn, query: TSqlQuery,
     result = ParseBiggestInt(val)
   else:
     result = -1
-  #if mysqlRealQuery(db, q, q.len) != 0'i32: 
-  #  result = -1'i64
-  #else:
-  #  result = mysql_insert_id(db)
-  #LAST_INSERT_ID()
 
 proc dbInsertID*(db: TDbConn, query: TSqlQuery, 
                  args: openArray[string]): int64 = 
diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim
index 01d98c205..4d7b41da2 100755
--- a/lib/system/excpt.nim
+++ b/lib/system/excpt.nim
@@ -194,13 +194,15 @@ proc signalHandler(sig: cint) {.exportc: "signalHandler", noconv.} =
   rawWriteStackTrace(buf)
 
   if s == SIGINT: add(buf, "SIGINT: Interrupted by Ctrl-C.\n")
-  elif s == SIGSEGV: add(buf, "SIGSEGV: Illegal storage access.\n")
+  elif s == SIGSEGV: 
+    add(buf, "SIGSEGV: Illegal storage access. (Attempt to read from nil?)\n")
   elif s == SIGABRT:
     if dbgAborting: return # the debugger wants to abort
     add(buf, "SIGABRT: Abnormal termination.\n")
   elif s == SIGFPE: add(buf, "SIGFPE: Arithmetic error.\n")
   elif s == SIGILL: add(buf, "SIGILL: Illegal operation.\n")
-  elif s == SIGBUS: add(buf, "SIGBUS: Illegal storage access.\n")
+  elif s == SIGBUS: 
+    add(buf, "SIGBUS: Illegal storage access. (Attempt to read from nil?)\n")
   else: add(buf, "unknown signal\n")
   writeToStdErr(buf)
   dbgAborting = True # play safe here...
diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim
index 8b6d0e285..3c99a5eed 100755
--- a/lib/system/sysio.nim
+++ b/lib/system/sysio.nim
@@ -51,7 +51,6 @@ proc readLine(f: TFile): string =
   result = ""
   rawReadLine(f, result)
 
-proc write(f: TFile, s: string) = fputs(s, f)
 proc write(f: TFile, i: int) = 
   when sizeof(int) == 8:
     fprintf(f, "%lld", i)
@@ -167,6 +166,10 @@ proc writeChars(f: TFile, a: openarray[char], start, len: int): int =
 proc writeBuffer(f: TFile, buffer: pointer, len: int): int =
   result = fwrite(buffer, 1, len, f)
 
+proc write(f: TFile, s: string) =
+  if writeBuffer(f, cstring(s), s.len) != s.len:
+    raise newException(EIO, "cannot write string to file")
+
 proc setFilePos(f: TFile, pos: int64) =
   if fseek(f, clong(pos), 0) != 0:
     raise newException(EIO, "cannot set file position")