Jump to content

How to search the string in the database


 Share

Recommended Posts

I have the database

name       a         b          c          d       e
khang      1        2          3          4       5
tuan       6        7          8          9       10
minh       11      12         13         14     15
toan       16      17         18         19     20
tan        21      22         23         24     25

I want to search the column and the row

ex : if khang and e the result is 5

if tan and c the result is 23

if minh and d the result is 14

please help me how can i search the string in database

my database is sqlite

Edited by khang0001
Link to comment
Share on other sites

I have the database

name       a         b          c          d       e
khang      1        2          3          4       5
tuan       6        7          8          9       10
minh       11      12         13         14     15
toan       16      17         18         19     20
tan        21      22         23         24     25

I want to search the column and the row

ex : if khang and e the result is 5

if tan and c the result is 23

if minh and d the result is 14

please help me how can i search the string in database

my database is sqlite

#Include <Date.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>
FileDelete("Database.db")
Dim $hQuery , $aRow
_SQLite_Startup ()
$DatabaseH = _SQLite_Open("Database.db")
_SQLite_Exec (-1, "CREATE TABLE iTABLE (name,a,b,c,d,e);")
_SQLite_Exec (-1, "INSERT INTO iTABLE (name,a,b,c,d,e) VALUES ('khang','1','2','3','4','5');")
_SQLite_Exec (-1, "INSERT INTO iTABLE (name,a,b,c,d,e) VALUES ('tuan','6','7','8','9','10');")
_SQLite_Exec (-1, "INSERT INTO iTABLE (name,a,b,c,d,e) VALUES ('minh','11','12','13','14','15');")
_SQLite_Exec (-1, "INSERT INTO iTABLE (name,a,b,c,d,e) VALUES ('toan','16','17','18','19','20');")
_SQLite_Exec (-1, "INSERT INTO iTABLE (name,a,b,c,d,e) VALUES ('tan','21','22','23','24','25');")

$BOOL = TableSearch($DatabaseH,"iTABLE","name,e","'khang','5'")
MsgBox(0,"",$BOOL)

$BOOL = TableSearch($DatabaseH,"iTABLE","name,a,b,c,d,e","'tuan','6','7','8','9','10'")
MsgBox(0,"",$BOOL)

$BOOL = TableSearch($DatabaseH,"iTABLE","name,e","'khang','100'")
MsgBox(0,"",$BOOL)

$BOOL = TableSearch($DatabaseH,"iTABLE","name,a,b,c,d,e","'tuan','6','7','8','9','200'")
MsgBox(0,"",$BOOL)

Func TableSearch($DatabaseH,$iTABLE,$ColumnsList,$ValuesList)
$SplitColumns = StringSplit($ColumnsList,",")
$SplitValues = StringSplit($ValuesList,",")
if $SplitColumns[0] <> $SplitValues[0] Then Return SetError(1,0,False)
For $i = 1 To $SplitColumns[0]
_SQlite_Query($DatabaseH, "SELECT " & $SplitColumns[$i] & " FROM " & $iTABLE & " WHERE " & $SplitColumns[$i] & " = " & $SplitValues[$i] & ";", $hQuery)
if _SQLite_FetchData ($hQuery, $aRow) <> $SQLITE_OK Then Return SetError(2,0,False)
Next
Return SetError(0,0,True)
EndFunc
Edited by wolf9228

صرح السماء كان هنا

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...