<p>I have 2 SQLite databases, one downloaded from a server (<code>server.db</code>), and one used as storage on the client (<code>client.db</code>). I need to perform various sync queries on the client database, using data from the server database.</p>

<p>For example, I want to delete all rows in the <code>client.db tRole</code> table, and repopulate with all rows in the <code>server.db tRole</code> table.</p>

<p>Another example, I want to delete all rows in the <code>client.db tFile</code> table where the <code>fileID</code> is not in the <code>server.db tFile</code> table.</p>

<p>In SQL Server you can just prefix the table with the name of the database. Is there anyway to do this in SQLite using Adobe Air?</p>

[{'answer_id': 8783, 'author': 'Theo', 'author_id': 1109, 'author_profile': 'https://Stackoverflow.com/users/1109', 'pm_score': 2, 'selected': False, 'text': '<p>It\'s possible to open multiple databases at once in SQLite, but it\'s doubtful if can be done when working from Flex/AIR. In the command line client you run <code>ATTACH DATABASE path/to/other.db AS otherDb</code> and then you can refer to tables in that database as <code>otherDb.tableName</code> just as in MySQL or SQL Server.</p>\n<blockquote>\n<p>Tables in an attached database can be referred to using the syntax database-name.table-name.</p>\n<p><a href="http://www.sqlite.org/lang_attach.html" rel="nofollow noreferrer">ATTACH DATABASE documentation at sqlite.org</a></p>\n</blockquote>\n'}, {'answer_id': 10020, 'author': 'Theo', 'author_id': 1109, 'author_profile': 'https://Stackoverflow.com/users/1109', 'pm_score': 4, 'selected': True, 'text': "<p>I just looked at the AIR SQL API, and there's an <code>attach</code> method on <code>SQLConnection</code> it looks exactly what you need.</p>\n<p>I haven't tested this, but according to the documentation it should work:</p>\n<pre><code>var connection : SQLConnection = new SQLConnection();\n\nconnection.open(firstDbFile);\nconnection.attach(secondDbFile, &quot;otherDb&quot;);\n\nvar statement : SQLStatement = new SQLStatement();\n\nstatement.connection = connection;\nstatement.text = &quot;INSERT INTO main.myTable SELECT * FROM otherDb.myTable&quot;;\nstatement.execute();\n</code></pre>\n<p>There may be errors in that code snippet, I haven't worked much with the AIR SQL API lately. Notice that the tables of the database opened with <code>open</code> are available using <code>main.tableName</code>, any attached database can be given any name at all (<code>otherDb</code> in the example above).</p>\n"}, {'answer_id': 368983, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>this code can be work,it is write of me:</p>\n\n<pre><code>package lib.tools\n\nimport flash.utils.ByteArray;\nimport flash.data.SQLConnection;\nimport flash.data.SQLStatement;\nimport flash.data.SQLResult;\nimport flash.data.SQLMode; \nimport flash.events.SQLErrorEvent;\nimport flash.events.SQLEvent;\nimport flash.filesystem.File;\nimport mx.core.UIComponent;\nimport flash.data.SQLConnection;\n\npublic class getConn {\n    public var Conn:SQLConnection;\n\n    public function getConn(database:Array) {       \n        Conn = new SQLConnection();\n        var Key:ByteArray = new ByteArray();\n        Key.writeUTFBytes("Some16ByteString"); \n        Conn.addEventListener(SQLErrorEvent.ERROR, createError);\n        var dbFile:File = File.applicationDirectory.resolvePath(database[0]);\n        Conn.open(dbFile);\n        if(database.length &gt; 1) {\n            for(var i:Number = 1; i &lt; database.length; i++) {\n                var DBname:String = database[i];\n                Conn.attach(DBname.split("\\.")[0], File.applicationDirectory.resolvePath(DBname));\n            }\n        }\n        Conn.open(dbFile, SQLMode.CREATE, false, 1024, Key); \n    }\n\n    private function createError(event:SQLErrorEvent):void {\n        trace("Error code:", event.error.details);\n        trace("Details:", event.error.message);\n    }\n\n    public function Rs(sql:Array):Object {\n        var stmt:SQLStatement = new SQLStatement();\n        Conn.begin();\n        stmt.sqlConnection = Conn;\n        try {\n            for(var i:String in sql) {          \n                stmt.text = sql[i]; \n                stmt.execute();\n            }\n            Conn.commit();\n        } catch(error:SQLErrorEvent) {\n            createError(error);\n            Conn.rollback();\n        };\n        var result:Object =stmt.getResult();\n        return result;\n    }\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/2518', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/26/']