Android客户端开发—数据库SQLite基本语句
生活随笔
收集整理的這篇文章主要介紹了
Android客户端开发—数据库SQLite基本语句
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
之前接觸過一點MySQL數據庫方面的知識,現在在學習Android軟件開發過程中發現SQLite語句與MySQL的語句還是有部分不同,SQLite中的命令不算太多,可以在adb shell中進入App的data文件,之后執行sqite3 數據庫名,進入到sql命令行界面
查詢SQLite的基本命令,輸入".help"得到命令與句列表:
sqlite> .help
.backup ?DB? FILE Backup DB (default "main") to FILE
.bail on|off Stop after hitting an error. Default OFF
.binary on|off Turn binary output on or off. Default OFF
.clone NEWDB Clone data into NEWDB from the existing database
.databases List names and files of attached databases
.dbinfo ?DB? Show status information about the database
.dump ?TABLE? ... Dump the database in an SQL text formatIf TABLE specified, only dump tables matchingLIKE pattern TABLE.
.echo on|off Turn command echo on or off
.eqp on|off Enable or disable automatic EXPLAIN QUERY PLAN
.exit Exit this program
.explain ?on|off? Turn output mode suitable for EXPLAIN on or off.With no args, it turns EXPLAIN on.
.fullschema Show schema and the content of sqlite_stat tables
.headers on|off Turn display of headers on or off
.help Show this message
.import FILE TABLE Import data from FILE into TABLE
.indexes ?TABLE? Show names of all indexesIf TABLE specified, only show indexes for tablesmatching LIKE pattern TABLE.
.limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT
.log FILE|off Turn logging on or off. FILE can be stderr/stdout
.mode MODE ?TABLE? Set output mode where MODE is one of:ascii Columns/rows delimited by 0x1F and 0x1Ecsv Comma-separated valuescolumn Left-aligned columns. (See .width)html HTML <table> codeinsert SQL insert statements for TABLEline One value per linelist Values delimited by .separator stringstabs Tab-separated valuestcl TCL list elements
.nullvalue STRING Use STRING in place of NULL values
.once FILENAME Output for the next SQL command only to FILENAME
.open ?FILENAME? Close existing database and reopen FILENAME
.output ?FILENAME? Send output to FILENAME or stdout
.print STRING... Print literal STRING
.prompt MAIN CONTINUE Replace the standard prompts
.quit Exit this program
.read FILENAME Execute SQL in FILENAME
.restore ?DB? FILE Restore content of DB (default "main") from FILE
.save FILE Write in-memory database into FILE
.scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off
.schema ?TABLE? Show the CREATE statementsIf TABLE specified, only show tables matchingLIKE pattern TABLE.
.separator COL ?ROW? Change the column separator and optionally the rowseparator for both the output mode and .import
.shell CMD ARGS... Run CMD ARGS... in a system shell
.show Show the current values for various settings
.stats on|off Turn stats on or off
.system CMD ARGS... Run CMD ARGS... in a system shell
.tables ?TABLE? List names of tablesIf TABLE specified, only list tables matchingLIKE pattern TABLE.
.timeout MS Try opening locked tables for MS milliseconds
.timer on|off Turn SQL timer on or off
.trace FILE|off Output each SQL statement as it is run
.vfsname ?AUX? Print the name of the VFS stack
.width NUM1 NUM2 ... Set column widths for "column" modeNegative values right-justify
譬如語句“.table”查看當前數據庫下面的表單
語句“select * from MPD;”則與MySQL中檢索所有列的所有內容語句相同,查看某列則是“select id from MPD;”將通配符修改為列名
查看某些行,則加入limit參數,如“select * from MPD limit 3;”顯示第三行以后的所有列數據,“select id from MPD limit 3,3;”顯示第三行以后的三行(4-6行)id列數據
查看當前SQLite的基本配置,輸入命令".show"
之前打印出來的表單沒有顯示列名,因此執行語句“.headers on”,再打印
在MySQL中可以利用“\G”代替“;”,從而使表單以列形式顯示,但是SQLite中不能使用“\G”,修改mode即可
和MySQL相同地,可以使用where子句檢索數據
使用聚集函數AVG()求均值
總結
以上是生活随笔為你收集整理的Android客户端开发—数据库SQLite基本语句的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 张开头的成语有哪些?
- 下一篇: Android客户端开发—开源数据库框架