Sqlite getting started exercise, adding, deleting, modifying, and querying address book

Source: Internet
Author: User
I chose sqlite as the database for the SQL language getting started exercise, so I also chose AAuto, a lightweight programming tool that encapsulates the sqlite library, which is easy to use and quickly writes out a tool with an interface, if you are interested, you only need to download the kuaishou development tool from the official website, decompress the tool, and run the following code to create a new project to see the effect. Understand and write this tool

I chose sqlite as the database for the SQL language getting started exercise, so I also chose AAuto, a lightweight programming tool that encapsulates the sqlite library, which is easy to use and quickly writes out a tool with an interface, if you are interested, you only need to download the kuaishou development tool from the official website, decompress the tool, and run the following code to create a new project to see the effect. Understand and write this tool

I chose sqlite as the database for the SQL language getting started exercise, so I also chose AAuto, a lightweight programming tool that encapsulates the sqlite library, which is easy to use and quickly writes out a tool with an interface, if you are interested, you only need to download the kuaishou development tool from the official website, decompress the tool, and run the following code to create a new project to see the effect.

You have learned the following knowledge by writing this tool:
1. Basic SQL language, sqlite database creation, data addition, modification, deletion, and fuzzy query, and use of named parameters.
2. simple use of the List View listview control.
3. Knowledge about windows controls, form command responses, notifications, and message loops.
4. Data Type and namespace features of aauto programming language.


SQLite AAuto Quicker

Import win. ui; import crreaDb;/* DSG {*/var winform = .. win. form (text = "kuaishou address book by Feifei OSC"; right = 558; bottom = 427; parent = ...) winform. add (button = {cls = "button"; text = "add record"; left = 19; top = 19; right = 100; bottom = 48; z = 1 }; button2 = {cls = "button"; text = "edit record"; left = 115; top = 19; right = 196; bottom = 48; z = 2 }; button3 = {cls = "button"; text = "delete record"; left = 211; top = 19; right = 292; bottom = 48; z = 3 }; button4 = {cls = "button"; text = ""; left = 476; top = 22; right = 536; bottom = 48; z = 5 }; dress = {cls = "edit"; left = 375; top = 152; right = 541; bottom = 176; edge = 1; z = 9 }; edit = {cls = "edit"; text = "Enter the search criteria... "; left = 318; top = 21; right = 457; bottom = 48; edge = 1; z = 4}; emal = {cls =" edit "; left = 375; top = 193; right = 541; bottom = 217; edge = 1; z = 10}; listview = {cls = "listview"; left = 19; top = 69; right = 292; bottom = 408; bgcolor = 16777215; edge = 1; fullRow = 1; z = 6}; mark = {cls = "richedit"; text = "Remarks "; left = 313; top = 280; right = 543; bottom = 408; edge = 1; hscroll = 1; multiline = 1; vscroll = 1; z = 17 }; name = {cls = "edit"; left = 375; top = 71; right = 541; bottom = 95; edge = 1; z = 7 }; qq = {cls = "edit"; left = 375; top = 234; right = 541; bottom = 258; edge = 1; z = 11 }; static = {cls = "static"; text = "name"; left = 319; top = 69; right = 359; bottom = 93; transparent = 1; z = 12 }; static2 = {cls = "static"; text = ""; left = 319; top = 110; right = 359; bottom = 134; transparent = 1; z = 13 }; static3 = {cls = "static"; text = "Address"; left = 319; top = 152; right = 359; bottom = 176; transparent = 1; z = 14 }; static4 = {cls = "static"; text = ""; left = 319; top = 193; right = 359; bottom = 217; transparent = 1; z = 15 }; static5 = {cls = "static"; text = "QQ/MSN"; left = 319; top = 234; right = 359; bottom = 258; transparent = 1; z = 16}; tel = {cls = "edit"; left = 375; top = 112; right = 541; bottom = 136; edge = 1; z = 8 }) /*} */var sqlConnection = sqlite ("\ res \ contact. db ") crreaDb. careaTable (sqlConnection) // display data var showData = function (SQL) {for id, name, phone number, address, email, QQ, remarks in sqlConnection. each ("select rowid, * from tl") {winform. listview. addItem ({tostring (id); Name; phone number; address; email address; QQ; remarks})} winform. listview. insertColumn ("id", 1) winform. listview. insertColumn ("name", 100) winform. listview. insertColumn ("tel", 100) winform. listview. insertColumn ("Address", 120) winform. listview. insertColumn ("Mailbox", 120) winform. listview. insertColumn ("QQ", 80) winform. listview. insertColumn ("Remarks", 150) showData () winform. show () winform. button. oncommand = function (id, event) {// Add var name = winform. name. textvar tel = winform. tel. textvar dress = winform. dress. textvar em = winform. emal. textvar qq = winform. qq. textvar mark = winform. mark. textcrreaDb. addData (sqlConnection, name, tel, dress, em, qq, mark) id = sqlConnection. lastInsertRowid () var data = sqlConnection. stepQuery ("select rowid, * from [tl] where rowid =" + id) winform. listview. addItem ({tostring (data. id); data. name; data. tel; data. dress; data. em; data. qq; data. mark})} winform. button3.oncommand = function (id, event) {// Delete var coun = winform. listview. selIndexvar id = winform. listview. getItemText (coun) if (id) {crreaDb. delData (sqlConnection, id) winform. listview. clear () showData () winform. listview. selIndex = coun} else {winform. msgbox ("select the column to be deleted")} winform. button2.oncommand = function (id, event) {// edit and modify crreaDb. editData (sqlConnection, name, tel, dress, em, qq, mark, id)} winform. button4.oncommand = function (id, event) {// query var vv = winform. edit. textvar id = crreaDb. inQuiry (sqlConnection, vv) winform. listview. clear () if (id) {for (I = 1; # id; 1) {winform. listview. addItem ({tostring (id [I]. rowid); id [I]. name; id [I]. tel; id [I]. dress; id [I]. em; id [I]. qq; id [I]. mark})} else {winform. msgbox ("records not found")} winform. edit. wndproc = function (hwnd, message, wParam, lParam) {if (message = 0x202/* _ WM_LBUTTONUP */) winform. edit. text = ""} winform. listview. onform y = function (id, code, ptr) {select (code) {case 0xFFFFFF9B/* _ LVN_ITEMCHANGED */{if (winform. listview. selIndex) {var lvw = winform. listviewwinform. name. text = lvw. getItemText (lvw. selIndex, 2) winform. tel. text = lvw. getItemText (lvw. selIndex, 3) winform. dress. text = lvw. getItemText (lvw. selIndex, 4) winform. emal. text = lvw. getItemText (lvw. selIndex, 5) winform. qq. text = lvw. getItemText (lvw. selIndex, 6) winform. mark. tex = lv1_getitemtext(lv1_selindex,7)}}}}win.loopmessage(;;;sqlconnection.exe c ("VACUUM") sqlConnection. close () return winform;

Namespace crreaDb; import sqlite; careaTable = function (db) {if (not db. existsTable ("tl") {// create table db.exe c ("create table tl (name, tel, dress, em, qq, mark );")}} // Add data addData = function (db, name, tell, dress, em, qq, mark) {var command = db. prepare ("insert into [tl] values (@ name, @ tel, @ dress, @ em, @ qq, @ mark);") command. bind. parameterAtNames (name = name; tel = tell; dress = dress; em = em; qq = qq; mark = mark ). step () command. finalize ()} // DELETE delData = function(db,id1_mongodb.exe c ("delete from [% s] where rowid = % d;", "tl", id )} // modify editData = function(db,name,tel,dress,em,qq,mark,id+mongodb.exe c ("UPDATE [tl] SET name = @ name, tel = @ te1, dress = @ dress, em = @ em, QQ = @ qq, mark = @ mark WHERE rowid = @ id; ", {name = name; tel = tel; dress = dress; em = em; qq = qq; mark = mark; id = id}) ;}// fuzzy query inQuiry = function (db, re) {var tab = db. getTable ("select rowid, * from [tl] where ifnull (name,'') | ifnull (tel, '') | ifnull (QQ ,'') like '% "+ re +" %' ") return tab}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.