added db_*.getRow

This commit is contained in:
Araq
2012-04-24 08:44:36 +02:00
parent 7e7c514dfc
commit afd8ca2f15
6 changed files with 42 additions and 4 deletions

View File

@@ -99,6 +99,21 @@ iterator FastRows*(db: TDbConn, query: TSqlQuery,
yield result
properFreeResult(sqlres, row)
proc getRow*(db: TDbConn, query: TSqlQuery,
args: openarray[string]): TRow =
## retrieves a single row.
Exec(db, query, args)
var sqlres = mysql.UseResult(db)
if sqlres != nil:
var L = int(mysql.NumFields(sqlres))
var result = newRow(L)
var row = mysql.FetchRow(sqlres)
if row != nil:
for i in 0..L-1:
setLen(result[i], 0)
add(result[i], row[i])
properFreeResult(sqlres, row)
proc GetAllRows*(db: TDbConn, query: TSqlQuery,
args: openarray[string]): seq[TRow] =
## executes the query and returns the whole result dataset.

View File

@@ -103,6 +103,15 @@ iterator FastRows*(db: TDbConn, query: TSqlQuery,
yield result
PQclear(res)
proc getRow*(db: TDbConn, query: TSqlQuery,
args: openarray[string]): TRow =
## retrieves a single row.
var res = setupQuery(db, query, args)
var L = int(PQnfields(res))
var result = newRow(L)
setRow(res, result, 0, L)
PQclear(res)
proc GetAllRows*(db: TDbConn, query: TSqlQuery,
args: openarray[string]): seq[TRow] =
## executes the query and returns the whole result dataset.

View File

@@ -101,6 +101,16 @@ iterator FastRows*(db: TDbConn, query: TSqlQuery,
yield result
if finalize(stmt) != SQLITE_OK: dbError(db)
proc getRow*(db: TDbConn, query: TSqlQuery,
args: openarray[string]): TRow =
## retrieves a single row.
var stmt = setupQuery(db, query, args)
var L = int(columnCount(stmt))
var result = newRow(L)
if step(stmt) == SQLITE_ROW:
setRow(stmt, result, L)
if finalize(stmt) != SQLITE_OK: dbError(db)
proc GetAllRows*(db: TDbConn, query: TSqlQuery,
args: openarray[string]): seq[TRow] =
## executes the query and returns the whole result dataset.