Guidance
指路人
g.yi.org
software / RapidQ / RQ Doc / html / qmysql.html

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

  
Appendix A: QMYSQL
Rapid-Q Documentation by William Yu (c)1999-2000 Appendix A: QMYSQL


QMYSQL Component

QMySQL is used to access your local or remote MySQL server. More information on MySQL can be obtained at http://www.mysql.com/

QMySQL Properties
FieldTypeR/WDefaultSupport





ConnectedINTEGERRWXG
Connected specifies whether you are currently connected to a MySQL server. Use the Connect method to establish a connection.
DBARRAY of STRINGRWXG
DB returns a database list that are currently available on the MySQL server.
DBCountINTEGERRWXG
DBCount returns the number of databases that are currently available on the MySQL server.
ColCountINTEGERRWXG
ColCount returns the number of columns in the table. ColCount is used after an SQL query to determine the number of columns in the resulting table.
FieldCountINTEGERRWXG
FieldCount returns the number of columns in the table. FieldCount is used after an SQL query to determine the number of columns in the resulting table.
Field.DecimalsINTEGERRWXG
Field.Decimals returns the number of decimals in the field.
Field.FlagsINTEGERRWXG
Field.Flags returns the flag settings. Refer to MYSQL.INC for supported values.
Field.LengthINTEGERRWXG
Field.Length returns the width of the column.
Field.MaxLengthINTEGERRWXG
Field.MaxLength returns the maximum width of the selected set. A result set can have multiple fields (or columns), Field.MaxLength returns the largest of these.
Field.NameSTRINGRWXG
Field.Name returns the name of the column.
Field.TableSTRINGRWXG
Field.TypeINTEGERRWXG
Field.Type returns the type of field. Refer to MYSQL.INC for supported values.
LengthARRAY of INTEGERRWXG
Length returns the length of each field. Make sure a call to FetchLengths is made.
RowARRAY of STRINGRWXG
Row returns the value stored in the particular Row for the current result set. The value is also dependent on the Field (or column). For example, Row(3) returns the value stored in Row 3 and whatever Column, ie. 2. Which is different from Row(3) of Column 3 for example.
RowCountINTEGERRWXG
TableARRAY of STRINGRWXG
Table returns a list of tables for the current database.
TableCountINTEGERRWXG


QMySQL Methods
MethodTypeDescriptionParamsSupport





CloseSUBDisconnect from MySQL0WXG
ConnectFUNCTION (Host$, User$, Passwd$) AS INTEGERConnect to MySQL3WXG
CreateDBFUNCTION (DB$) AS INTEGERCreates a new database1WXG
DropDBFUNCTION (DB$) AS INTEGERDrop database1WXG
EscapeStringFUNCTION (S$, Length%) AS STRINGParses binary string S$ and returns a string that can be used in Blob fields2WXG
FetchFieldFUNCTION AS INTEGERFetch next field0WXG
FetchLengthsFUNCTION AS INTEGERFetch lengths for current row0WXG
FetchRowFUNCTION AS INTEGERFetch next row0WXG
FieldSeekFUNCTION (Position%)Jump to Field Position%1WXG
QueryFUNCTION (Query$) AS INTEGERQuery database1WXG
RealConnectSUB (Host$, User$, Passwd$, DB$, Port%, UnixSock$, Flags%)Connect to MySQL7WXG
RefreshFUNCTION (RefreshFlags%) AS INTEGERRefresh database1WXG
RowBlobFUNCTION (Row%, Bytes&) AS STRINGReturns the binary blob as a string2WXG
RowSeekFUNCTION (Row%)Jump to a certain row1WXG
SelectDBFUNCTION (DB$) AS INTEGERSelect database to use1WXG

QMySQL Events
EventTypeOccurs when...Params






QMySQL Examples
' This simply checks that you have a working MySQL server and lets you
' view some database fields.

$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

Prev Component Contents Next Component
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Wed 2017-11-22  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2015-12-25 19:42:41