by wdiLi 16/02/14, 01:29 am
ต้องเรียกใช้งาน UDF (SQLite) ในการจัดการฐานข้อมูล - Code:
#include <SQLite.au3>
#include <SQLite.dll.au3>
โค้ด สร้างฐานข้อมูล และสร้างตาราง เพิ่มข้อมูล
- Code:
#include <SQLite.au3>
#include <SQLite.dll.au3>
; เปิดการใช้งาน sqlite.dll
_SQLite_Startup()
; สร้าง ฐานข้อมูล ชื่อ test.db
$DB = _SQLite_Open("Test.db")
; สร้างตารางชื่อ user มี 3 ฟิลด์ คือ user_id , user_name , user_pass
_SQLite_Exec ($DB , "CREATE TABLE user (user_id , user_name, user_pass);")
; เพิ่มข้อมูลลงตาราง user โดยค่ามีดังนี้ 0001 , admin , 1234
_SQLite_Exec ($DB , "INSERT INTO user (user_id , user_name, user_pass) VALUES ('0001', 'admin', '1234');")
; ปิดการใช้งาน sqlite.dll
_SQLite_Shutdown()
โค้ด แสดงข้อมูลจากฐานข้อมูล
- Code:
#include <SQLite.au3>
#include <SQLite.dll.au3>
; เปิดการใช้งาน sqlite.dll
_SQLite_Startup()
Local $Query, $Row
; เปิดใช้งาน ฐานข้อมูล Test.db
$DB = _SQLite_Open("Test.db")
; Query คำสั่ง SQL ค้นหาฟิลด์ ทั้งหมดใน Test.db
_SQLite_Query($DB , "SELECT * FROM user", $Query)
; ดึงข้อมูลในฟิลด์ทั้งหมด ออกมาในรูปแบบ Array แล้วเอาข้อมูลมาเก็บไว้ในตัวแปร $Row
_SQLite_FetchData($Query , $Row)
; แสดงข้อมูลออกมา ใส่ MessageBox ดู
MsgBox(1 , "Info", $Row[0]&" , "&$Row[1]& " , " & $Row[2])
; ปิดการใช้งาน sqlite.dll
_SQLite_Shutdown()
เมื่อเอาโค้ด SQLite กับ สคริปที่เอามาถาม น่าจะประมาณ นี้นะครับ
- Code:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>
$Form2 = GUICreate("Child window is still here", 377, 212, 192, 124)
$Username = GUICtrlCreateInput("Username", 64, 72, 209, 21)
$Password = GUICtrlCreateInput("Password", 64, 104, 209, 21)
$Button2 = GUICtrlCreateButton("Login", 136, 136, 73, 33, $WS_GROUP)
GUISetState(@SW_SHOW)
_SQLite_Startup()
Local $Query , $Row
$DB = _SQLite_Open("Test.db")
_SQLite_Query($DB , "SELECT * FROM user" , $Query)
_SQLite_FetchData($Query , $Row)
ConsoleWrite("row : "&$Row[0]&" , "&$Row[1]&" , "&$Row[2]&@CRLF)
;~ _SQLite_Close()
_SQLite_Shutdown()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button2
$ReadingUsername = GUICtrlRead($Username)
$ReadingPassword = GUICtrlRead($Password)
If $ReadingUsername = $Row[1] And $ReadingPassword = $Row[2] Then
MsgBox(0,"TEST!", "ผ่าน")
Else
MsgBox(0,"TEST!", "ไม่ผ่าน")
EndIf
EndSwitch
WEnd
พอจะเป็นแนวทาง ให้นะคับ ผมก็ไม่เก่ง ภาษา autoit เท่าไร ถ้าเคยเรียนหรือศึกษา ภาษา SQL มา
น่าจะพอเข้าใจในระดับหนึ่ง แต่ถ้ามือใหม่จริงๆ คงต้องขยันศึกษาแล้วละคับ ถ้ายากเก่งในทางนี้ ขยันอ่านเยอะๆ
ค้นหาใน
Google , youtube ก็มีเยอะมาก เกี่ยวกับการเขียน สคริป Autoit