Tôi đã viết một kịch bản thế hệ cơ sở dữ liệu trong SQL và muốn thực hiện nó trong Adobe AIR ứng dụng của tôi:SQLStatement.execute() - nhiều truy vấn trong một tuyên bố
Create Table tRole (
roleID integer Primary Key
,roleName varchar(40)
);
Create Table tFile (
fileID integer Primary Key
,fileName varchar(50)
,fileDescription varchar(500)
,thumbnailID integer
,fileFormatID integer
,categoryID integer
,isFavorite boolean
,dateAdded date
,globalAccessCount integer
,lastAccessTime date
,downloadComplete boolean
,isNew boolean
,isSpotlight boolean
,duration varchar(30)
);
Create Table tCategory (
categoryID integer Primary Key
,categoryName varchar(50)
,parent_categoryID integer
);
...
tôi thực hiện điều này trong Adobe AIR sử dụng sau phương pháp:
public static function RunSqlFromFile(fileName:String):void {
var file:File = File.applicationDirectory.resolvePath(fileName);
var stream:FileStream = new FileStream();
stream.open(file, FileMode.READ)
var strSql:String = stream.readUTFBytes(stream.bytesAvailable);
NonQuery(strSql);
}
public static function NonQuery(strSQL:String):void {
var sqlConnection:SQLConnection = new SQLConnection();
sqlConnection.open(File.applicationStorageDirectory.resolvePath(DBPATH));
var sqlStatement:SQLStatement = new SQLStatement();
sqlStatement.text = strSQL;
sqlStatement.sqlConnection = sqlConnection;
try {
sqlStatement.execute();
} catch (error:SQLError) {
Alert.show(error.toString());
}
}
Không có lỗi nào được tạo, tuy nhiên chỉ tồn tại tRole
. Dường như nó chỉ nhìn vào truy vấn đầu tiên (lên đến dấu chấm phẩy- nếu tôi xóa nó, truy vấn thất bại). Có cách nào để gọi nhiều truy vấn trong một câu lệnh không?
Chỉ cần nhận ra điều này sẽ thất bại như thế nào nếu một dấu chấm phẩy xuất hiện trong trường varchar. – Shawn