Guidance
指路人
g.yi.org
software / RapidQ / System / Win32 / rqlibsql / SQL.BAS

Register 
新用户注册
Search 搜索
首页 
Home Home
Software
Upload

  
' Sorry for lack of documentation, still a work in progress...
' This simply checks that you have a working MySQL server.

     $TYPECHECK ON
     $INCLUDE "RAPIDQ.INC"

     DECLARE SUB Button1Click (Sender AS QBUTTON)
     DECLARE SUB DBListBoxClick (Sender AS QLISTBOX)
     DECLARE SUB TableListBoxClick (Sender AS QLISTBOX)
     DECLARE SUB SQLFormResize (Sender AS QFORM)

     DIM Font AS QFONT
     Font.Name = "Courier"
     DIM MySQL AS QMYSQL

     CREATE SQLForm AS QFORM
      CAPTION = "Connected"
      Width = 330
      Height = 300
      Center
      CREATE DBLabel AS QLABEL
       CAPTION = "Select a database:"
      END CREATE
      CREATE DBListBox AS QLISTBOX
       Top = 20
       Width = 150
       Height = 100
       OnClick = DBListBoxClick
      END CREATE
      CREATE TableListBox AS QLISTBOX
       Top = 20
       Left = 165
       Width = 150
       Height = 100
       OnClick = TableListBoxClick
      END CREATE
      CREATE FieldEdit AS QRICHEDIT
       Top = 130
       Width = SQLForm.ClientWidth
       Height = SQLForm.ClientHeight-130
       ReadOnly = TRUE
       WordWrap = FALSE
       PlainText = TRUE
       Font = Font
       ScrollBars = ssBoth
      END CREATE
      CREATE Grid AS QSTRINGGRID
       Top = 130
       Width = SQLForm.ClientWidth
       Height = SQLForm.ClientHeight-130
       AddOptions(goEditing)
      END CREATE
      OnResize = SQLFormResize
     END CREATE

     CREATE Form AS QFORM
      CAPTION = "SQL Demo"
      Width = 230
      Height = 174
      Center
      CREATE Label1 AS QLABEL
       CAPTION = "Host:"
       Left = 44
       Top = 23
      END CREATE
      CREATE Label2 AS QLABEL
       CAPTION = "User name:"
       Left = 16
       Top = 50
       Width = 57
      END CREATE
      CREATE Label3 AS QLABEL
       CAPTION = "Password:"
       Left = 21
       Top = 79
       Width = 54
      END CREATE
      CREATE Edit1 AS QEDIT
       Text = ""
       Left = 83
       Top = 18
      END CREATE
      CREATE Edit2 AS QEDIT
       Text = ""
       Left = 83
       Top = 46
      END CREATE
      CREATE Edit3 AS QEDIT
       Text = ""
       Left = 83
       Top = 74
      END CREATE
      CREATE Button1 AS QBUTTON
       CAPTION = "&Ok"
       Left = 32
       Top = 112
       Kind = 1
       Default = 1
       NumBMPs = 2
       OnClick = Button1Click
      END CREATE
      CREATE Button2 AS QBUTTON
       CAPTION = "E&xit"
       Left = 118
       Top = 112
       Kind = 6
       NumBMPs = 2
      END CREATE
      SHOWMODAL
     END CREATE


     SUB Button1Click
      DIM I AS INTEGER

      IF MySQL.Connect(Edit1.Text, Edit2.Text, Edit3.Text) = 0 THEN
       SHOWMESSAGE("Failed to connect to MySQL Server")
       EXIT SUB
      END IF

      FOR I = 0 TO MySQL.DBCount-1
       DBListBox.AddItems(MySQL.DB(I))
      NEXT

      SQLForm.SHOWMODAL

      SUB DBListBoxClick (Sender AS QLISTBOX)

       IF Sender.ItemIndex < 0 THEN EXIT SUB
       IF MySQL.SelectDB(Sender.Item(Sender.ItemIndex)) = 0 THEN
        SHOWMESSAGE("Could not open "+Sender.Item(Sender.ItemIndex))
        EXIT SUB
       END IF

       TableListBox.Clear
       FOR I = 0 TO MySQL.TableCount-1
        TableListBox.AddItems(MySQL.Table(I))
       NEXT
      END SUB

      SUB TableListBoxClick (Sender AS QLISTBOX)
       DIM Str AS STRING, J AS INTEGER

       IF Sender.ItemIndex < 0 THEN EXIT SUB
       IF MySQL.Query("show columns from "+Sender.Item(Sender.ItemIndex)) = 0 THEN
        SHOWMESSAGE("Could not query "+Sender.Item(Sender.ItemIndex))
        EXIT SUB
       END IF

       FieldEdit.Clear
       Grid.ColCount = MySQL.FieldCount
       I = 0
       WHILE MySQL.FetchField
        Grid.Cell(I,0) = MySQL.Field.Name
        I++
       WEND

       Grid.RowCount = MySQL.RowCount+1
       IF MySQL.RowCount THEN
        J = 1
        WHILE MySQL.FetchRow
         MySQL.FieldSeek(0)
         FOR I=0 TO MySQL.NumFields-1
          Grid.Cell(I,J) = MySQL.Row(I)
         NEXT
         J++
        WEND
       END IF
      END SUB
     END SUB

     SUB SQLFormResize (Sender AS QFORM)
      Grid.Height = Sender.ClientHeight - Grid.Top
      Grid.Width = Sender.ClientWidth-1
      TableListBox.Width = Sender.ClientWidth-1 - TableListBox.Left
     END SUB

     IF MySQL.Connected THEN MySQL.CLOSE
     END
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Tue 2019-4-23  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2013-08-20 12:35:25