0

I'm using the Sqlcipher library to encrypt my Database in Android. Everything is ok when i create or open the database but if in my script before encrypt the data base there a special character, the encrypt is putting a "?".

INSERT INTO [fr_preguntas_x_formularios] ([idPregunta], [idFormulario], [descripcion], [tipoCampo], [tipoCampoDetalle], [respuesta], [sw_obligatorio], [min_rango], [max_rango], [separador_numerico], [expresion_regular]) VALUES (4, 1, 'Niveles de azúcar en la sangre (ng)', 'numerico', ',,300&1000__#,###', null, '', null, null, null, null);

when i'm obtaining the "description" I receive "Niveles de az?car en la sangre (ng)"

How can i solve this?

I'm creating my database with this code

try {
        File file = new File(Environment.getExternalStorageDirectory()
                .getPath() + "/dbtest/" + DATABASE_NAME_SCRIPT);
        InputStream stream = new FileInputStream(file);
        InputStreamReader inputStreamReader = new InputStreamReader(stream);
        BufferedReader bufferedReader = new BufferedReader(
                inputStreamReader);
        String line;
        String strSentenciaSql = "";
        int cont = 0;
        while ((line = bufferedReader.readLine()) != null) {
            if (!line.contains("--") && !line.isEmpty()) {
                strSentenciaSql += line;
                if (line.contains(";")) {
                    database.execSQL(strSentenciaSql);
                    strSentenciaSql = "";
                    System.out.println(cont);
                    cont++;
                } else {
                    strSentenciaSql += " ";
                }
            }
        }
        bufferedReader.close();
        inputStreamReader.close();
        stream.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
  • SQLite does not change strings. The original file or the displaying code use a wrong encoding. – CL. Jul 26 '14 at 06:47
  • But is just when I'm encrypting, because after when I use the same library and insert data with special characters, the String is ok. – merryrppin Jul 26 '14 at 13:40

1 Answers1

0

The problema wasn't in the library, was in the code. I checked this answer: https://stackoverflow.com/a/9282017/3820750, the problema was when the BufferReader was Reading.

BufferedReader bufRdr  = new BufferedReader(
    new InputStreamReader(new FileInputStream(file),"ISO-8859-1"));
Community
  • 1
  • 1