neko icon indicating copy to clipboard operation
neko copied to clipboard

Unable to read 32-bit and 64-bit integer from sqlite database

Open avl93 opened this issue 7 years ago • 2 comments

Sqlite in neko can only read 31-bit integers from sqlite. Example:

class Main
{
	public static function main(){
		var connection = sys.db.Sqlite.open("test.db");
		
		var max31bit: haxe.Int64 = 0x40000000 - 1 ;
		
		var values : Array<haxe.Int64> = [ max31bit, max31bit+1, max31bit<<33];

		connection.request('create table if not exists test (column1 int)');
		connection.request('delete from test');
		for (currValue in values) {
			connection.request('insert into test values ($currValue)');
		}
		
		var rs : sys.db.ResultSet = connection.request("select * from test");
		while (rs.hasNext()){
			trace(rs.next());
		}
	}
}

Result:

Main.hx:18: { column1 => 1073741823 }
Main.hx:18: { column1 => -1073741824 }
Main.hx:18: { column1 => 0 }

Expected:

Main.hx:18: { column1 => 1073741823 }
Main.hx:18: { column1 => 1073741824 }
Main.hx:18: { column1 => 9223372028264841216 }

Though, Neko can correctly write 32-bit and even 64-bit integers to sqlite database, and I can read them using sqlite CLI:

>sqlite3 test.db
SQLite version 3.18.0 2017-03-28 18:48:43
Enter ".help" for usage hints.
sqlite> select * from test;
1073741823
1073741824
9223372028264841216

Tested on NekoVM 2.1.0 and Haxe Compiler 3.4.2.

avl93 avatar Jun 21 '17 12:06 avl93

I guess some alloc_int needs to be replaced by alloc_best_int in sqlite.c support

On Wed, Jun 21, 2017 at 2:47 PM, avl93 [email protected] wrote:

Sqlite in neko can only read 31-bit integers from sqlite. Example:

class Main { public static function main(){ var connection = sys.db.Sqlite.open("test.db");

  var max31bit: haxe.Int64 = 0x40000000 -1 ;
  
  var values : Array<haxe.Int64> = [ max31bit, max31bit+1, max31bit<<33];

  connection.request('create table if not exists test (column1 int)');
  connection.request('delete from test');
  for (currValue in values) {
  	connection.request('insert into test values ($currValue)');
  }
  
  var rs : sys.db.ResultSet = connection.request("select * from test");
  while (rs.hasNext()){
  	trace(rs.next());
  }

} }

Result:

Main.hx:18: { column1 => 1073741823 } Main.hx:18: { column1 => -1073741824 } Main.hx:18: { column1 => 0 }

Expected:

Main.hx:18: { column1 => 1073741823 } Main.hx:18: { column1 => 1073741824 } Main.hx:18: { column1 => 9223372028264841216 }

Though, Neko can correctly write 32-bit and even 64-bit integers to sqlite database, and I can read them using sqlite CLI:

sqlite3 test.db SQLite version 3.18.0 2017-03-28 18:48:43 Enter ".help" for usage hints. sqlite> select * from test; 1073741823 1073741824 9223372028264841216

Tested on NekoVM 2.1.0 and Haxe Compiler 3.4.2.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/HaxeFoundation/neko/issues/167, or mute the thread https://github.com/notifications/unsubscribe-auth/AA-bwNEmidfAvH4ClFz7jXHrsNv-EPOCks5sGRDngaJpZM4OA6EL .

ncannasse avatar Jun 24 '17 08:06 ncannasse

I fixed the int32 case, such that it outputs

Test.hx:18: { column1 => 1073741823 }
Test.hx:18: { column1 => 1073741824 }
Test.hx:18: { column1 => 0 }

No idea about int64. (#55?)

andyli avatar Dec 19 '17 06:12 andyli