15.10.2012 Views

Actionscript 3 Entwicklerhandbuch

Actionscript 3 Entwicklerhandbuch

Actionscript 3 Entwicklerhandbuch

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ACTIONSCRIPT 3.0 ENTWICKLERHANDBUCH<br />

Arbeiten mit lokalen SQL-Datenbanken in AIR<br />

var conn:SQLConnection = new SQLConnection();<br />

// The database file is in the application storage directory<br />

var folder:File = File.applicationStorageDirectory;<br />

var dbFile:File = folder.resolvePath("DBSample.db");<br />

// open the database<br />

conn.open(dbFile, SQLMode.UPDATE);<br />

// start a transaction<br />

conn.begin();<br />

try<br />

{<br />

// add the customer record to the database<br />

var insertCustomer:SQLStatement = new SQLStatement();<br />

insertCustomer.sqlConnection = conn;<br />

insertCustomer.text =<br />

"INSERT INTO customers (firstName, lastName)" +<br />

"VALUES ('Bob', 'Jones')";<br />

insertCustomer.execute();<br />

var customerId:Number = insertCustomer.getResult().lastInsertRowID;<br />

// add a related phone number record for the customer<br />

var insertPhoneNumber:SQLStatement = new SQLStatement();<br />

insertPhoneNumber.sqlConnection = conn;<br />

insertPhoneNumber.text =<br />

"INSERT INTO customerPhoneNumbers (customerId, number)" +<br />

"VALUES (:customerId, '800-555-1234')";<br />

insertPhoneNumber.parameters[":customerId"] = customerId;<br />

insertPhoneNumber.execute();<br />

// if we've gotten to this point without errors, commit the transaction<br />

conn.commit();<br />

}<br />

catch (error:SQLError)<br />

{<br />

// rollback the transaction<br />

conn.rollback();<br />

}<br />

Informationen zum asynchronen Ausführungsmodell<br />

Adobe AIR 1.0 und höher<br />

Ein häufig geäußerter Vorbehalt gegenüber dem asynchronen Ausführungsmodus ist die Annahme, dass eine<br />

SQLStatement-Instanz nicht ausgeführt werden kann, solange noch eine andere SQLStatement-Instanz für dieselbe<br />

Datenbankverbindung ausgeführt wird. Diese Annahme ist jedoch falsch. Während eine SQLStatement-Instanz<br />

ausgeführt wird, können Sie die text-Eigenschaft dieser Anweisung nicht ändern. Wenn Sie jedoch für jede SQL-<br />

Anweisung, die Sie ausführen möchten, eine separate SQLStatement-Instanz verwenden, können Sie die execute()-<br />

Methode einer SQLStatement-Instanz aufrufen, während eine andere SQLStatement-Instanz noch ausgeführt wird,<br />

ohne dass es zu einem Fehler kommt.<br />

Letzte Aktualisierung 27.6.2012<br />

801

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!