The difference between like and = in the SQLite where statement

Source: Internet
Author: User
Tags sqlite db
1   #  ! /Usr/bin/ENV Python  2   3   '''  4   Genearte the SQLite DB  5   '''  6   Import  Time  7   Import  Apsw  8  9   10 Loop_insert = 10000 11 Loops _search = 1000 12   13   Def  Gendb ():  14 Loop_time = Loop_insert  15 DB = apsw. Connection ( "  : Memory:  "  )  16 Cursor =DB. cursor ()  17 Cursor.exe cute ( "  Create Table big (itemall string );  "  )  18 Cursor.exe cute ( "  Begin;  "  )  19       For I In  Xrange (loop_time ):  20 Cursor.exe cute ( "  Insert into big (itemall) values (% 010d );  " % I)  21   22 Cursor.exe cute ( "  Commit;  "  )  23   24 Cursor.exe cute ( "  Create Table small (idx int primary key, V1 int, V2 char ); "  )  25 Cursor.exe cute ( "  Begin;  "  )  26       For I In  Xrange (loop_time ):  27 Cursor.exe cute ( "  Insert into small (V1, V2) values (% d, % 010d );  " %(I, I ))  28   29 Cursor.exe cute ( "  Commit;  "  )  30   31       Return  DB  32   33   34   Def  Test1 (db ):  35 C =DB. cursor ()  36 Start = Time. Time ()  37       For I In  Xrange (loop_search ):  38 C2 = c.exe cute ( "  Select * from big where itemall like '% 010d' limit 1;  " % I)  39 Values = C2.fetchall () 40           If Len (values)> 0:  41               Pass  42 End = Time. Time ()  43       44       Print   "  Duration test1  " , End- Start  45       46  47   Def  Test2 (db ):  48 C = DB. cursor ()  49 Start = Time. Time ()  50       For I In  Xrange (loop_search ):  51 C2 = c.exe cute ( "  Select * from small where V1 = '% 010d' and v2 = % 10d limit 1; " % (I, I ))  52 Values = C2.fetchall ()  53           If Len (values)> 0:  54               Pass  55 End = Time. Time ()  56       57       Print   "  Duration Test2 " , End- Start  58           59   60   Def  Main ():  61 DB = Gendb ()  62   Test1 (db)  63   Test2 (db)  64       65   66   If  _ Name __ = '  _ Main __  '  :  67 Main ()

 

Related Article

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.