As the title: is it possible to attach a (encrypted or non-encrypted) database to a database, encrypted with SQLCipher 1.5?
Whatever way I do this (tried lots) I get this error:
net.sqlcipher.database.SQLiteException: file is not a database: ATTACH DATABASE '/storage/3637-6230/Android/data/b4a.testing/files/SQL.db' AS 'DBA'
B4X:
strAttachResult = AttachDB(Starter.strAppDir & "/" & strDBNew , "DBA")
Sub AttachDB(strDBFolder As String, strDBName As String) As String
Dim strSQL As String
strSQL = "ATTACH DATABASE '" & strDBFolder & "' AS '" & strDBName & "'"
Try
cConnection.SQL1.ExecNonQuery(strSQL)
Catch
ShowError("Error in AttachDB", "")
Return "Error"
End Try
Return ""
End Sub
Sub AttachDB(strFullDBPath As String, strDBName As String, strPassword As String) As String
Dim strSQL As String
If strPassword.Length = 0 Then
strSQL = "ATTACH DATABASE '" & strFullDBPath & "' AS '" & strDBName & "'"
Else
strSQL = "ATTACH DATABASE '" & strFullDBPath & "' AS '" & strDBName & "' KEY '" & strPassword & "'"
End If
Try
cConnection.SQL1.ExecNonQuery(strSQL)
Catch
ShowError("Error in AttachDB", "")
Return "Error"
End Try
Return ""
End Sub
Sub AttachDB(strFullDBPath As String, strDBName As String, strPassword As String) As String
Dim strSQL As String
If strPassword.Length = 0 Then
strSQL = "ATTACH DATABASE '" & strFullDBPath & "' AS '" & strDBName & "'"
Else
strSQL = "ATTACH DATABASE '" & strFullDBPath & "' AS '" & strDBName & "' KEY '" & strPassword & "'"
End If
Try
cConnection.SQL1.ExecNonQuery(strSQL)
Catch
ShowError("Error in AttachDB", "")
Return "Error"
End Try
Return ""
End Sub
This works attaching an encrypted DB to an encrypted DB.
Not figured out yet how to attach an unencrypted DB to an encrypted DB.
Off now, will check this later.
This works attaching an encrypted DB to an encrypted DB.
Not figured out yet how to attach an unencrypted DB to an encrypted DB.
Off now, will check this later.
Sub AttachDB(strFullDBPath As String, strDBName As String, strPassword As String) As String
Dim strSQL As String
If strPassword.Length = 0 Then
strSQL = "ATTACH DATABASE '" & strFullDBPath & "' AS '" & strDBName & "'"
Else
strSQL = "ATTACH DATABASE '" & strFullDBPath & "' AS '" & strDBName & "' KEY '" & strPassword.Trim & "'"
End If
Try
cConnection.SQL1.ExecNonQuery(strSQL)
Catch
ShowError("Error in AttachDB", "")
Return "Error"
End Try
Return ""
End Sub
So we can do with a key or without.
It looks attaching an unencrypted DB to an encrypted one you still need the key, so supply the password as " ",
so it will do with a key but do the key as "".