Hi,
I made a mistake when setting up and developing my B4J app, and I created a big SQLite database with a heap of columns like:
Column 1 | Column 2 | ...... | Column 300
(yes, has a lot of columns in the one table, this is the mistake I made.)
The column names are all different.
I now want to convert it to a MySQL database.
I want to change it to make it so its like the following, which I think it a better way in doing it:
Column 1 | Column 2 | Column 3
This way I can use Column 1 as the Account value, Column 2 will be the old column name, and the Column 3 will be the value from the old database.
Not sure if the following is the best way in doing it, or if there is a better way in doing it..
This will create the new MySQL table
Then I used the following to read the old database, and then move it to the MySQL table:
I have over 350 rows in the the SQLite database, which has 300 columns.
Based on my calculations moving it over to the MySQL database, will take approx 6 hours. (approx 1 minute per row)
Is the above the correct way in doing this, or is there a better easier way in converting it ?
I made a mistake when setting up and developing my B4J app, and I created a big SQLite database with a heap of columns like:
Column 1 | Column 2 | ...... | Column 300
(yes, has a lot of columns in the one table, this is the mistake I made.)
The column names are all different.
I now want to convert it to a MySQL database.
I want to change it to make it so its like the following, which I think it a better way in doing it:
Column 1 | Column 2 | Column 3
This way I can use Column 1 as the Account value, Column 2 will be the old column name, and the Column 3 will be the value from the old database.
Not sure if the following is the best way in doing it, or if there is a better way in doing it..
This will create the new MySQL table
B4X:
' Create new table in MySQL database
Dim SQLString As String
SQLString = "CREATE TABLE table1" & "(Account TEXT, Location TEXT, Value TEXT)"
Dim sql As SQL = pool.GetConnection
Try
'work with sql
sql.ExecNonQuery(SQLString)
Catch
'handle failure
Log(LastException.Message)
End Try
sql.Close
Then I used the following to read the old database, and then move it to the MySQL table:
B4X:
Dim sql As SQL = pool.GetConnection
'RS holds old SQLite database
Dim RS As ResultSet = db_old.ExecQuery("SELECT * FROM `old_table`")
Do While RS.NextRow
Try
'work with sql
For i = 0 To RS.ColumnCount - 1
If RS.GetColumnName(i) = "Account" Then
Else
sql.ExecNonQuery2("INSERT INTO table1 VALUES(?,?,?)", Array As Object(RS.GetString("Account"), RS.GetColumnName(i), RS.GetString(RS.GetColumnName(i))))
End If
Next
Catch
'handle failure
Log(LastException.Message)
End Try
Loop
sql.Close
RS.Close
Log("Done converting!")
I have over 350 rows in the the SQLite database, which has 300 columns.
Based on my calculations moving it over to the MySQL database, will take approx 6 hours. (approx 1 minute per row)
Is the above the correct way in doing this, or is there a better easier way in converting it ?