Skip to content

Commit

Permalink
enable style:usages for stdlib tests [backport: 1.6] (#19715)
Browse files Browse the repository at this point in the history
* enable style:usages for stdlib tests

* freeAddrInfo

* more tests

* importc

* bufSize

* fix more

* => parseSql and renderSql
  • Loading branch information
ringabout committed Apr 13, 2022
1 parent ce00e92 commit eb1a217
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/db_mysql.nim
Original file line number Diff line number Diff line change
Expand Up @@ -150,25 +150,25 @@ proc tryExec*(db: DbConn, query: SqlQuery, args: varargs[string, `$`]): bool {.
tags: [ReadDbEffect, WriteDbEffect].} =
## tries to execute the query and returns true if successful, false otherwise.
var q = dbFormat(query, args)
return mysql.realQuery(PMySQL db, q, q.len) == 0'i32
return mysql.real_query(PMySQL db, q, q.len) == 0'i32

proc rawExec(db: DbConn, query: SqlQuery, args: varargs[string, `$`]) =
var q = dbFormat(query, args)
if mysql.realQuery(PMySQL db, q, q.len) != 0'i32: dbError(db)
if mysql.real_query(PMySQL db, q, q.len) != 0'i32: dbError(db)

proc exec*(db: DbConn, query: SqlQuery, args: varargs[string, `$`]) {.
tags: [ReadDbEffect, WriteDbEffect].} =
## executes the query and raises EDB if not successful.
var q = dbFormat(query, args)
if mysql.realQuery(PMySQL db, q, q.len) != 0'i32: dbError(db)
if mysql.real_query(PMySQL db, q, q.len) != 0'i32: dbError(db)

proc newRow(L: int): Row =
newSeq(result, L)
for i in 0..L-1: result[i] = ""

proc properFreeResult(sqlres: mysql.PRES, row: cstringArray) =
if row != nil:
while mysql.fetchRow(sqlres) != nil: discard
while mysql.fetch_row(sqlres) != nil: discard
mysql.freeResult(sqlres)

iterator fastRows*(db: DbConn, query: SqlQuery,
Expand All @@ -190,7 +190,7 @@ iterator fastRows*(db: DbConn, query: SqlQuery,
backup: Row
newSeq(result, L)
while true:
row = mysql.fetchRow(sqlres)
row = mysql.fetch_row(sqlres)
if row == nil: break
for i in 0..L-1:
setLen(result[i], 0)
Expand All @@ -209,7 +209,7 @@ iterator instantRows*(db: DbConn, query: SqlQuery,
let L = int(mysql.numFields(sqlres))
var row: cstringArray
while true:
row = mysql.fetchRow(sqlres)
row = mysql.fetch_row(sqlres)
if row == nil: break
yield InstantRow(row: row, len: L)
properFreeResult(sqlres, row)
Expand Down Expand Up @@ -290,7 +290,7 @@ iterator instantRows*(db: DbConn; columns: var DbColumns; query: SqlQuery;
setColumnInfo(columns, sqlres, L)
var row: cstringArray
while true:
row = mysql.fetchRow(sqlres)
row = mysql.fetch_row(sqlres)
if row == nil: break
yield InstantRow(row: row, len: L)
properFreeResult(sqlres, row)
Expand All @@ -317,7 +317,7 @@ proc getRow*(db: DbConn, query: SqlQuery,
if sqlres != nil:
var L = int(mysql.numFields(sqlres))
result = newRow(L)
var row = mysql.fetchRow(sqlres)
var row = mysql.fetch_row(sqlres)
if row != nil:
for i in 0..L-1:
setLen(result[i], 0)
Expand All @@ -335,7 +335,7 @@ proc getAllRows*(db: DbConn, query: SqlQuery,
var row: cstringArray
var j = 0
while true:
row = mysql.fetchRow(sqlres)
row = mysql.fetch_row(sqlres)
if row == nil: break
setLen(result, j+1)
newSeq(result[j], L)
Expand All @@ -361,7 +361,7 @@ proc tryInsertId*(db: DbConn, query: SqlQuery,
## executes the query (typically "INSERT") and returns the
## generated ID for the row or -1 in case of an error.
var q = dbFormat(query, args)
if mysql.realQuery(PMySQL db, q, q.len) != 0'i32:
if mysql.real_query(PMySQL db, q, q.len) != 0'i32:
result = -1'i64
else:
result = mysql.insertId(PMySQL db)
Expand Down

0 comments on commit eb1a217

Please sign in to comment.