[API]
LocalAlloc
RtlMoveMemory
mysql_queryreal
mysql_store_result
mysql_free_result
mysql_num_fields
mysql_num_rows
LocalFree

RtlMoveMemory
RtlZeroMemory
mysql_fetch_row

[INCLUDE]
MySQL_Shared
PeekS_Ansi

[DEFINE]
Private Type MySQL_QueryInfo
  hEnum As Long
  nFields As Long
  nRows As Long
  FieldsLeft As Long
  End Type
Private Const MySQL_QueryInfoLen As Long = 4& * 4&

[CODE]
Public Function MySQL_Select_Query(ByVal QueryString As String, Optional ByRef NumFields As Long, Optional ByRef NumResults As Long, Optional ByRef ErrorCode As Long) As Long
  Dim xLong1 As Long
  Dim xType1 As MySQL_QueryInfo

  If mysql_queryreal(MySQL_Handle, QueryString) = 0& Then
    xLong1 = mysql_store_result(MySQL_Handle)
    If Not xLong1 = 0& Then
      xType1.hEnum = xLong1
      NumFields = mysql_num_fields(xLong1)
      If Not NumFields = 0& Then
        xType1.nFields = NumFields
        xType1.FieldsLeft = NumFields
        NumResults = mysql_num_rows(xLong1)
        xType1.nRows = NumResults
        MySQL_Select_Query = LocalAlloc(&H40&, MySQL_QueryInfoLen + NumFields * 4&)
        If Not MySQL_Select_Query = 0& Then
          Call RtlMoveMemory(ByVal MySQL_Select_Query, xType1, MySQL_QueryInfoLen)
          Exit Function
          End If
        End If
      End If
    End If
  End Function

Public Function MySQL_Select_GetResult(ByVal hQRManual As Long) As Boolean
  Dim xLong1 As Long
  Dim xType1 As MySQL_QueryInfo

  Call RtlMoveMemory(xType1, ByVal hQRManual, MySQL_QueryInfoLen)
  Call RtlZeroMemory(ByVal (hQRManual + MySQL_QueryInfoLen), xType1.nFields * 4&)
  If Not xType1.nRows = 0& Then
    xType1.nRows = xType1.nRows - 1&
    xLong1 = mysql_fetch_row(xType1.hEnum)
    If xLong1 = 0& Then
      xType1.nRows = 0&
      Else
      Call RtlMoveMemory(ByVal (hQRManual + MySQL_QueryInfoLen), ByVal xLong1, xType1.nFields * 4&)
      MySQL_Select_GetResult = True
      End If
    Call RtlMoveMemory(ByVal hQRManual, xType1, MySQL_QueryInfoLen)
    'Else
    End If
  End Function

Public Sub MySQL_Select_Close(ByRef hQRManual As Long)
  Dim xLong1 As Long

  Call RtlMoveMemory(ByVal VarPtr(xLong1), ByVal hQRManual, 4&)
  If Not xLong1 = 0& Then
    Call mysql_free_result(xLong1)
    End If
  Call LocalFree(hQRManual)
  hQRManual = 0&
  End Sub
