开发者

Problem reading SQlite from actionsipt 3 (AIR or Flash)

开发者 https://www.devze.com 2023-03-20 23:42 出处:网络
im having some problems trying to read a SQlite data base from flash using AS3. The data base was created with this php script:

im having some problems trying to read a SQlite data base from flash using AS3. The data base was created with this php script:

$db = new PDO('sqlite:abaco.sqlite');
$db->exec("CREATE TABLE 'abacodata' ('mod' varchar(25) NOT NULL,'name' varchar(25) NOT NULL,'pos' int(3) NOT NULL,'posx' int(11) NOT NULL,'posy'开发者_Python百科 int(11) NOT NULL,'image' varchar(50) NOT NULL,'type' int(1) NOT NULL);");  
$lines=file("TEMPDATA.txt");
foreach($lines as $v) {
   $values = explode(',',$v);
   $sql = "INSERT INTO abacodata VALUES ('".$values[0]."', '".$values[1]."', '".$values[2]."', '".$values[3]."', '".$values[4]."', '".$values[6]."', '".$values[5]."');";
   $db->exec($sql);
}

As you can see, this creates a database like this:

Problem reading SQlite from actionsipt 3 (AIR or Flash)

After this i need to read this database in AS3, using this very simple script:

trace("INITIATED");
import flash.filesystem.File;
import flash.data.*;
var dbFile:File= File.applicationStorageDirectory.resolvePath("abaco.sqlite");
var sqlConn:SQLConnection = new SQLConnection();
var sqlStatement:SQLStatement = new SQLStatement();
sqlConn.open(dbFile);
sqlStatement.sqlConnection = sqlConn;
sqlStatement.text = "SELECT * FROM abacodata;";
sqlStatement.execute();
var result:Array = sqlStatement.getResult().data;
trace(result[0]['mod']);

The script achive to conect to the file, but it cant locate the table!;

Problem reading SQlite from actionsipt 3 (AIR or Flash)

Any one have any idea of what am i doing wrong? Thanks alot!


Can you see if you actually connected to the correct database file?

I'd check the 3 following things:

1- Does the file object point the correct file; you can check this by tracing nativePath:

trace(dbFile.nativePath);

2- Make sure that when you open that db, you open the existing db instead of creating a new one. Open your connection this way; if the db file doesn't exist, you'll get an error:

sqlConn.open(dbFile, SQLMode.READ);

3- Finally, make sure your table exists by querying the sqlite_master table:

sqlStatement.text = "select * from sqlite_master;";
sqlStatement.execute();


It might be a format conflict between the tool you are using to create the database and Adobe's implementation.

Try running the same creation script from actionscript and see if you get the same error.

0

精彩评论

暂无评论...
验证码 换一张
取 消