rocker
05-11-2009, 11:37 AM
I have two tables in my database which I populate as follows:
class myClass
{
var conn:SQLConnection;
var xml:XML;
public function myClass()
{
conn = new SQLConnection(....); /* initialize connection to the db */
xml = initXML(); /* Fill the xml var */
functionX(xml);
functionY(xml);
}
private functionX(xml:XML):void
{
var property:XML;
var sqlstatement:SQLStatement = new SQLStatement();
sqlstatement.sqlConnection = conn;
sqlstatement.text = "INSERT OR REPLACE INTO dbase.id VALUES(@id, @name)";
sqlstatement.sqlConnection.begin(); /* Begin transaction 1 */
for each(property in xml.prop)
{
<init params in the statement>
sqlstatement.execute();
}
sqlstatement.sqlConnection.commit();
}
private functionY(xml:XML):void
{
var property:XML;
var desc:XML;
var sqlstatement:SQLStatement = new SQLStatement();
sqlstatement.sqlConnection = conn;
sqlstatement.text = "INSERT OR REPLACE INTO dbase.description VALUES(@id, @desc, @secId)";
sqlstatement.sqlConnection.begin(); /* Begin transaction 2 */
for each(property in xml.prop)
{
for each (desc in property.desc)
{
<init params in the statement>
sqlstatement.execute();
}
}
sqlstatement.sqlConnection.commit();
}
}
I get an error in functionY's commit() saying there is no active transaction. But when I set a breakpoint at this line and observe the sqlstatement.sqlConnection.inTransaction variable, it is true.
Can anyone shed some light on this phenomenon? Is transaction 2 in functionY not queued up till transcation 1 of functionX is over?
Edit: If in functionY, the inner for loop does not execute (there is no 'desc' field in the xml), is there a way to undo the begin() of transaction 2? I am afraid, doing a cancel() or a rollback() might just cancel transaction 1 that might be ongoing.
My xml file is like this:
<xml>
<prop id="1", name="xyz">
<desc secId="A", description="This is a description">
...
... <0..n of desc fields>
<desc secId="N", description="This is a description">
</prop>
... <1..m of prop fields>
</xml>
class myClass
{
var conn:SQLConnection;
var xml:XML;
public function myClass()
{
conn = new SQLConnection(....); /* initialize connection to the db */
xml = initXML(); /* Fill the xml var */
functionX(xml);
functionY(xml);
}
private functionX(xml:XML):void
{
var property:XML;
var sqlstatement:SQLStatement = new SQLStatement();
sqlstatement.sqlConnection = conn;
sqlstatement.text = "INSERT OR REPLACE INTO dbase.id VALUES(@id, @name)";
sqlstatement.sqlConnection.begin(); /* Begin transaction 1 */
for each(property in xml.prop)
{
<init params in the statement>
sqlstatement.execute();
}
sqlstatement.sqlConnection.commit();
}
private functionY(xml:XML):void
{
var property:XML;
var desc:XML;
var sqlstatement:SQLStatement = new SQLStatement();
sqlstatement.sqlConnection = conn;
sqlstatement.text = "INSERT OR REPLACE INTO dbase.description VALUES(@id, @desc, @secId)";
sqlstatement.sqlConnection.begin(); /* Begin transaction 2 */
for each(property in xml.prop)
{
for each (desc in property.desc)
{
<init params in the statement>
sqlstatement.execute();
}
}
sqlstatement.sqlConnection.commit();
}
}
I get an error in functionY's commit() saying there is no active transaction. But when I set a breakpoint at this line and observe the sqlstatement.sqlConnection.inTransaction variable, it is true.
Can anyone shed some light on this phenomenon? Is transaction 2 in functionY not queued up till transcation 1 of functionX is over?
Edit: If in functionY, the inner for loop does not execute (there is no 'desc' field in the xml), is there a way to undo the begin() of transaction 2? I am afraid, doing a cancel() or a rollback() might just cancel transaction 1 that might be ongoing.
My xml file is like this:
<xml>
<prop id="1", name="xyz">
<desc secId="A", description="This is a description">
...
... <0..n of desc fields>
<desc secId="N", description="This is a description">
</prop>
... <1..m of prop fields>
</xml>