Hey
My program uses MariaDB through ADODB. I would like to copy a specific table (data, but if there was also a possibility to recreate the schema automatically instead of doing it by hand that would be a bonus) from MariaDB to an SQLite filedb.
So far I learned how to create tables and insert data using cMemDB and cConnection.
Now I would like to learn the simplest way to copy over data from a table from MariaDB to SQLite. It doesn't matter whether we use cMemDB or cConnection, as long as the resulting SQLite DB is stored on disk in a file.
I could iterate over each result in the Recordset from MariaDB and INSERT each row into SQLite, but that's not efficient, not the simplest solution. I have a vague memory of seeing a solution in this forum involving pointing SQLite to a Recordset or Connection to mirror all of the data in that Recordset, but I can't find this post.
Some testing code, these reside in a MariaHandler class and return the Recordset or Connection to MariaDB/ODBC:
I tried:
Neither fails, but g_sqliteConn has no databases, and g_sqliteMemDB has a database but no tables.
The attachment shows that m_rs does indeed contain data.
My program uses MariaDB through ADODB. I would like to copy a specific table (data, but if there was also a possibility to recreate the schema automatically instead of doing it by hand that would be a bonus) from MariaDB to an SQLite filedb.
So far I learned how to create tables and insert data using cMemDB and cConnection.
Now I would like to learn the simplest way to copy over data from a table from MariaDB to SQLite. It doesn't matter whether we use cMemDB or cConnection, as long as the resulting SQLite DB is stored on disk in a file.
I could iterate over each result in the Recordset from MariaDB and INSERT each row into SQLite, but that's not efficient, not the simplest solution. I have a vague memory of seeing a solution in this forum involving pointing SQLite to a Recordset or Connection to mirror all of the data in that Recordset, but I can't find this post.
Some testing code, these reside in a MariaHandler class and return the Recordset or Connection to MariaDB/ODBC:
Code:
Public Function getRs() As ADODB.Recordset
Dim queryStr As String
On Error GoTo Fail
queryStr = "SELECT * FROM country;"
Call executeQuery(queryStr, "getRs")
Set getRs = m_rs
Do While Not m_rs.EOF
Debug.Print m_rs("item_name")
m_rs.MoveNext
Loop
Exit Function
Fail:
Call failHandler("getRs", queryStr, err)
End Function
Public Function getCnn() As ADODB.Connection
Dim queryStr As String
On Error GoTo Fail
queryStr = "SELECT * FROM country;"
Call executeQuery(queryStr, "getCnn")
Set getCnn = m_cn
Exit Function
Fail:
Call failHandler("getRs", queryStr, err)
End Function
Code:
g_sqliteMemDB.Cnn.CreateTableFromADORs g_sqliteMemDB.Cnn, "country", g_mhD.getRs
g_sqliteConn.CreateTableFromADORs g_sqliteConn, "country", g_mhD.getRs
The attachment shows that m_rs does indeed contain data.