I just started looking into mysql connections with nim and I can't figure out how to do a select * from table where blank = variable
var conn = db_mysql.open(gameserver.host, gameserver.db_user, gameserver.db_pass,
gameserver.db_name)
var query_string = "SELECT * FROM users WHERE username= (?)"
var values = @["username"]
var sql = sql(query_string)
var data = conn.getAllRows(sql, values)
I tried this but it doesn't work Edit: Can someone actually give me an example on how to do update, insert as well? Thanks
var
conn = db_mysql.open(gameserver.host, gameserver.db_user, gameserver.db_pass,
gameserver.db_name)
for data in conn.getAllRows(sql"SELECT * FROM users WHERE username=?", "username"):
# do something here with each data
The parameter substitution automatically quotes the substituted variable, so the sql string becomes
SELECT * FROM users WHERE username='username'
I end up with this error
Traceback (most recent call last)
test.nim(19) test
system.nim(2095) $
system.nim(2077) collectionToString
system.nim(2095) $
system.nim(2077) collectionToString
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
when I try to get * from the DB. Single values work fine.