使用 ADB 和 SQLITE 进行转义,连接命令
我正在尝试将二进制数据插入在 Android 中运行的应用程序的数据库中。
如果我从 shell 内部运行命令,我可以完美地完成它,就像
G011A:/ # sqlite3 /data/data/com.app.test/db/data.db "insert or replace into sessions (record, timestamp) values (X'0a81',1645815520)"
它完美地插入数据一样。但我需要从外部运行它,就像
adb shell 'sqlite3 /data/data/com.app.test/db/data.db "insert or replace into sessions (record, timestamp) values (X'0a81',1645815520)"'
它不起作用,它给了我一个
/system/bin/sh: syntax error: '(' unexpected
我尝试了所有可能的转义和序列
adb shell "sqlite3 /data/data/com.myapp/db/test.db 'insert or replace into sessions (record, timestamp) values (X"0a81",1645815520)'"
WARNING: linker: /mnt/runtime/default/emulated/0/Download/sqlite3: unsupported flags DT_FLAGS_1=0x8000001
Error: unrecognized token: "0a81"
adb shell 'sqlite3 /data/data/com.myapp/db/test.db "insert or replace into sessions (record, timestamp) values (X'0a81',1645815520)"'
/system/bin/sh: syntax error: '(' unexpected
adb shell 'sqlite3 /data/data/com.myapp/db/test.db "insert or replace into sessions (record, timestamp) values (X\'0a81\',1645815520)"'
/system/bin/sh: syntax error: '(' unexpected
adb shell 'sqlite3 /data/data/com.myapp/db/test.db \"insert or replace into sessions (record, timestamp) values (X\'0a81\',1645815520)\"'
/system/bin/sh: syntax error: '(' unexpected
adb shell "sqlite3 /data/data/com.myapp/db/test.db \'insert or replace into sessions (record, timestamp) values (X\'0a81\',1645815520)\'"
/system/bin/sh: syntax error: '(' unexpected
adb shell "sqlite3 /data/data/com.myapp/db/test.db \'insert or replace into sessions (record, timestamp) values (X\'0a81\',1645815520)\'"
/system/bin/sh: syntax error: '(' unexpected
有什么想法如何做到这一点吗?
这个更简单的查询有效,因为我在查询中间没有另一个 '
adb shell "sqlite3 /data/data/com.app.test/db/data.db 'select * from sessions'"
顺便说一句:这是一个在 Windows 10 上运行的 PowerShell 终端。稍后我将此命令行嵌入到 Java 应用程序中。
I'm trying to insert binary data in database of an app running in Android.
I can do it perfectly if I run the command from inside the shell like
G011A:/ # sqlite3 /data/data/com.app.test/db/data.db "insert or replace into sessions (record, timestamp) values (X'0a81',1645815520)"
It inserts data perfectly. But I need to run it from outside like
adb shell 'sqlite3 /data/data/com.app.test/db/data.db "insert or replace into sessions (record, timestamp) values (X'0a81',1645815520)"'
And it does not work, it gives me a
/system/bin/sh: syntax error: '(' unexpected
I tried every possible escaping and sequence
adb shell "sqlite3 /data/data/com.myapp/db/test.db 'insert or replace into sessions (record, timestamp) values (X"0a81",1645815520)'"
WARNING: linker: /mnt/runtime/default/emulated/0/Download/sqlite3: unsupported flags DT_FLAGS_1=0x8000001
Error: unrecognized token: "0a81"
adb shell 'sqlite3 /data/data/com.myapp/db/test.db "insert or replace into sessions (record, timestamp) values (X'0a81',1645815520)"'
/system/bin/sh: syntax error: '(' unexpected
adb shell 'sqlite3 /data/data/com.myapp/db/test.db "insert or replace into sessions (record, timestamp) values (X\'0a81\',1645815520)"'
/system/bin/sh: syntax error: '(' unexpected
adb shell 'sqlite3 /data/data/com.myapp/db/test.db \"insert or replace into sessions (record, timestamp) values (X\'0a81\',1645815520)\"'
/system/bin/sh: syntax error: '(' unexpected
adb shell "sqlite3 /data/data/com.myapp/db/test.db \'insert or replace into sessions (record, timestamp) values (X\'0a81\',1645815520)\'"
/system/bin/sh: syntax error: '(' unexpected
adb shell "sqlite3 /data/data/com.myapp/db/test.db \'insert or replace into sessions (record, timestamp) values (X\'0a81\',1645815520)\'"
/system/bin/sh: syntax error: '(' unexpected
Any ideas how to do it?
This more simple query works, as I don't have another ' in the middle of the query
adb shell "sqlite3 /data/data/com.app.test/db/data.db 'select * from sessions'"
BTW: this a PowerShell terminal running on Windows 10. And I'm later embedding this command line in a Java application.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该可以
编辑
或者这是超级难看的
编辑2
使用你最喜欢的编辑器创建一个包含SQL的文件,没有任何转义(即
my.sql
),推送它
然后
This should work
edit
Or this which is super ugly
edit 2
Use your favorite editor to create a file containing the SQL with nothing escaped (i.e.
my.sql
)push it
then