Sign in to follow this  
Followers 0
khang0001

How to search the string in the database

5 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



Would help to know what kind of database it is.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

my database is sqlite in autoit

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

The sql is:

SELECT e FROM [tablename] WHERE name= 'khang';

Look in the helpfiles [uDFs - SQLite Management] for how to run that in autoit.

William

Edited by saywell

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

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

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0