MySQL_Select

4D - Documentation   Français   English   German   4D For MySQL, Command Theme List   4D For MySQL, Command Alphabetical List   Back   Previous   Next

version 2004


MySQL_Select (connID; query) Longint

ParameterTypeDescription
connIDLongintConnection ID returned by MySQL_Connect
queryTextSQL statement to execute
Function resultLongintSelect ID

Description

The MySQL_Select command executes every SQL statement that is supposed to return a set of data, such as "SELECT * FROM mytable", "SHOW DATABASES", "SHOW TABLES", etc. The returned Longint identifies the cursor that contains the results of the MySQL_Select call. This value is used to retrieve the contents of the Select query.

If the method returns 0, then an error occurred and the error details can be retrieved with MySQL_ErrorCode/MySQL_ErrorString.

If you want to execute an SQL statement that doesn't return a cursor, you must use the MySQL_Execute method.

connID is a Longint returned from MySQL_Connect.

query is a text introducing the SQL statement (e.g. "SHOW TABLES FROM mydb").

Examples

(1) This is an example of the basic use of MySQL_Select:

   selID:=MySQL_Select(connID;"SELECT * FROM clients WHERE zip_code = '90210'")

(2) This is an example of a complete Select session:

      `Start Connection
   connID:=MySQL_Connect($Host;$Database;$User;$Password)
   If(connID#0)
         `Introduce your query here
      $Query:="SELECT id_clt, name_clt, email_clt, country_clt FROM clients"
         `Execute query
      selectID:=MySQL_Select(connID;$Query)
      If(SelectID#0)
            `Get query result
         While(0#MySQL_NextRow(selectID))
            $NewPos:=Size of array(arrLON_ClientID)
            MySQL_GetLongIntField(selectID;0;$id_clt)
            INSERT ELEMENT(arrLON_ClientID;$NewPos;1)
            arrLON_ClientID{$NewPos}:=$id_clt
            MySQL_GetStringField(selectID;1;$name_clt)
            INSERT ELEMENT(arrSTR_Name;$NewPos;1)
            arrSTR_Name{$NewPos}:=$name_clt
            MySQL_GetStringField(selectID;1;$email_clt)
            INSERT ELEMENT(arrSTR_Email;$NewPos;1)
            arrSTR_Email{$NewPos}:=$email_clt
         End while
            `Close Select
         MySQL_CloseSelect(selectID)
      Else
         ALERT(MySQL_ErrorString(connID))
      End if
         `Connection close
      MySQL_Close(connID)
   Else
         `Getting the last Connect Failure
      ALERT(MySQL_LastConnectFailure)
   End if

4D - Documentation   Français   English   German   4D For MySQL, Command Theme List   4D For MySQL, Command Alphabetical List   Back   Previous   Next