Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

18.5 Manage forms and data


May 24, 2021 That's what Linux should learn



Next, insert a book message into the mybook data form. T o do this, you need to use the INSERT command and write the form name and the corresponding field items in the command. A fter you execute this command, you can complete the book writing information. L et's use this command to insert a book message called linuxprobe, which is priced at $60 and 518 pages, respectively. A fter the command is executed, it means that the book information has been successfully written to the data form, and then you can query the contents of the form. When we query the form content using the select command, we need to add the fields we want to query, and if we want to see everything in the form, we can use the asterisk wildcard to display:

MariaDB [linuxprobe]> INSERT INTO mybook(name,price,pages) VALUES('linuxprobe','60', '518'); Q uery OK, 1 row affected (0.00 sec) MariaDB [linuxprobe]> select * from mybook; + ------------+-------+-------+ | n ame | p rice | p ages | + ------------+-------+-------+ | l inuxprobe | 6 0 | 5 18 | F or database operations ------------, -------, -------, and 1 rows in set (0.01 sec), there are four things that need to be done for database operations personnel - add, delete, change, check. T his means that creating a data form and inserting content into it is only the first step, and you also need to know how to modify the contents of the data form. F or example, we can use the update command to change the price of the linuxprobe book information we just inserted to $55, and then use the select command to view the name and pricing information for the book. Note that because only the name and pricing of the book are viewed here, not the page number, there is no need to display everything with an asterisk wildcard.

MariaDB [linuxprobe]> UPDATE mybook SET price=55 ; Q uery OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 MariaDB [linuxprobe]> SELECT name,price FROM mybook; + ------------+-------+ | n ame | p rice | + ------------+-------+ | l inuxprobe | 5 5 | W e ------------ delete ------- content in a data form using the delete command for the 1 row in set (0.00 sec). Let's use the delete command to delete everything in the data form mybook, and then look at the contents of the form and you'll see that the form is empty.

MariaDB [linuxprobe]> DELETE FROM mybook; Q uery OK, 1 row affected (0.01 sec) MariaDB [linuxprobe]> SELECT * FROM mybook; E mpty set (0.00 sec) In general, there are thousands of pieces of data in data forms. F or example, we have just created a mybook form for saving book information, over time, there will be more and more book information inside. In this case, how do we define a query statement if we only want to see a book whose price is greater than a certain value?

Here are four book messages inserted in turn using the insert command:

MariaDB [linuxprobe]> INSERT INTO mybook(name,price,pages) VALUES('linuxprobe1','30','518'); Q uery OK, 1 row affected (0.05 sec) MariaDB [linuxprobe]> INSERT INTO mybook(name,price,pages) VALUES('linuxprobe2','50','518'); Q uery OK, 1 row affected (0.05 sec) MariaDB [linuxprobe]> INSERT INTO mybook(name,price,pages) VALUES('linuxprobe3','80','518'); Q uery OK, 1 row affected (0.01 sec) MariaDB [linuxprobe]> INSERT INTO mybook(name,price,pages) VALUES('linuxprobe4','100','518'); Q uery OK, 1 row affected (0.00 sec) For the query results to be more accurate, you need to use a combination of select and where commands. W here commands are conditional commands that match queries in the database. B y setting a query condition, you can find only data that meets that condition. Table 18-3 lists the query parameters and roles commonly used in the where command.

The parameters and effects used in the Where command in Table 18-3

Argument Action - Equal

lt; s amp;or!=not equal greater than lt; L ess than - greater than or equal to lt; - Less than or equal to BETWEEN in a range LIKE search for an example IN searches for multiple values in a column now into the hands-on session. F ind books in the mybook form that have a price greater than $75 or a price that is not equal to $80, and the corresponding commands are shown below. Now that you are familiar with these two query criteria, you can try to find exactly what the book is called linuxprobe2.

MariaDB [linuxprobe]> SELECT FROM mybook WHERE price>75; + -------------+-------+-------+ | n ame | p rice | p ages | + -------------+-------+-------+ | l inuxprobe3 | 8 0 | 5 18 | | l inuxprobe4 | 1 00 | 5 18 | + -------------+-------+-------+ 2 rows in set (0.06 sec) MariaDB [linuxprobe]> SELECT FROM mybook WHERE price!=80; + -------------+-------+-------+ | n ame | p rice | p ages | + -------------+-------+-------+ | l inuxprobe1 | 3 0 | 5 18 | | l inuxprobe2 | 5 0 | 5 18 | | l inuxprobe4 | 1 00 | 5 18 | +-------------+-------+-------+ 3 rows in set (0.01 sec) MariaDB [mysql]> exit Bye