From ff67b69368e6c40272fff92e5a350fc4058cad80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arda=20=C3=87=C4=B1nar?= Date: Thu, 5 Nov 2009 21:37:07 +0200 Subject: [PATCH] Fixed a segfault in SqliteStmt.toHashMap and changed select_from example to utilize that method --- examples/select_from.ooc | 10 +++++----- sqlite3/Sqlite3.ooc | 11 ++++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/examples/select_from.ooc b/examples/select_from.ooc index 848ce93..9712ba4 100644 --- a/examples/select_from.ooc +++ b/examples/select_from.ooc @@ -1,5 +1,6 @@ use sqlite3 import sqlite3/[Sqlite3, ResultCodes] +import structs/HashMap main: func { db := Sqlite3 new("asd.db") @@ -7,11 +8,10 @@ main: func { stmt toString() println() res := stmt step() while(res==Sqlite3Code row){ - stmt columnName(0) println() - stmt intColumn(0) toString() println() - stmt columnName(1) println() - stmt intColumn(1) toString() println() - + h := stmt toHashMap() + h get("asd") toInt() toString() println() + h get("zxc") toInt() toString() println() + res = stmt step() } stmt finalize() diff --git a/sqlite3/Sqlite3.ooc b/sqlite3/Sqlite3.ooc index 0da6b84..63252f8 100644 --- a/sqlite3/Sqlite3.ooc +++ b/sqlite3/Sqlite3.ooc @@ -1,4 +1,5 @@ include sqlite3 +import structs/HashMap SqliteStruct: cover from sqlite3* SqliteStmtStruct: cover from sqlite3_stmt* @@ -51,14 +52,14 @@ SqliteStmt: cover from SqliteStmtStruct { toString: extern(sqlite3_sql) func -> String toHashMap: func -> HashMap{ - res := HashMap new - n := this columnCount()+1 - for(i in 1..n){ + map := HashMap new() + n := this columnCount() + for(i in 0..n){ name := this columnName(i) val := this valueColumn(i) - res put(name, val) + map put(name, val) } - return res + return map } }