[API]
MySQL_Field
mysql_queryreal
mysql_store_result
mysql_num_fields
mysql_num_rows
CallWindowProcA
mysql_fetch_field
RtlMoveMemory
mysql_fetch_row
mysql_fetch_lengths
LocalFree
mysql_free_result

[INCLUDE]
LocalAllocFromString_Ansi

[DEFINE]
Public Const RowDiv As Long = &H100&
Public Const RowRow As Long = &HFFFFFF00
Public Const RowCol As Long = &HFF&

[CODE]
Public Function MySQL_Select_Enum(ByVal QueryString As String, ByVal ptrCallbackGen As Long, ByVal ptrCallbackFields As Long, ByVal ptrCallbackRows As Long) As Boolean
  Dim hEnum As Long
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xLong3 As Long
  Dim xLong4 As Long
  Dim xLong5 As Long
  Dim xLong6 As Long
  Dim xLongA1() As Long
  Dim xLongA2() As Long
  Dim xBoolA1() As Long
  Dim xByteA1() As Byte
  Dim xChar1 As String
  Dim xType1 As MySQL_Field

  If mysql_queryreal(MySQL_Handle, QueryString) = 0& Then
  'If mysql_queryreal(MySQL_Handle, "SHOW GRANTS") = 0& Then
    hEnum = mysql_store_result(MySQL_Handle)
    If Not hEnum = 0& Then
      xLong1 = mysql_num_fields(hEnum)
      xLong2 = mysql_num_rows(hEnum)
      If Not (xLong1 = 0&) Then
        If Not ptrCallbackGen = 0& Then
          Call CallWindowProcA(ptrCallbackGen, 0&, 0&, 0&, xLong1 * RowDiv + xLong2)
          End If
        ReDim xBoolA1(xLong1 - 1&)
        If ptrCallbackFields = 0& Then
          For xLong3 = 0& To xLong1 - 1&
            xLong4 = mysql_fetch_field(hEnum)
            If Not xLong4 = 0& Then
              Call MySQL_FieldFromPointer(xLong4, xType1)
              Select Case xType1.xType
                Case 252& To 254&
                  xBoolA1(xLong3) = CBool(xType1.Flags And &H80&)
                End Select
              End If
            Next
          Else
          For xLong3 = 0& To xLong1 - 1&
            xLong4 = mysql_fetch_field(hEnum)
            If Not xLong4 = 0& Then
              Call MySQL_FieldFromPointer(xLong4, xType1)
              Select Case xType1.xType
                Case 252& To 254&
                  xBoolA1(xLong3) = CBool(xType1.Flags And &H80&)
                End Select
              Call CallWindowProcA(ptrCallbackFields, 0&, 0&, xLong3, xLong4)
              End If
            Next
          End If
        If Not ptrCallbackGen = 0& Then
          Call CallWindowProcA(ptrCallbackGen, 0&, 0&, 1&, xLong1 * RowDiv + xLong2)
          End If
        If Not ptrCallbackRows = 0& Then
          Const xx = 20&
          ReDim xLongA1(xLong1 - 1&)
          ReDim xLongA2(xLong1 - 1&)
          For xLong3 = 0& To (xLong2 - 1&) * RowDiv Step RowDiv
            xLong4 = mysql_fetch_row(hEnum)
            xLong5 = mysql_fetch_lengths(hEnum)
            If Not (xLong5 = 0& Or xLong4 = 0&) Then
              Call RtlMoveMemory(ByVal VarPtr(xLongA1(0)), ByVal xLong4, xLong1 * 4&)
              Call RtlMoveMemory(ByVal VarPtr(xLongA2(0)), ByVal xLong5, xLong1 * 4&)
              For xLong5 = 0& To xLong1 - 1&
                'Debug.Print Timer, xLongA1(xLong5), PeekS_Ansi(xLongA1(xLong5))
                If Not xBoolA1(xLong5) Or xLongA1(xLong5) = 0& Or xLongA2(xLong5) = 0& Then
                  Call CallWindowProcA(ptrCallbackRows, 0&, 0&, xLong3 + xLong5, xLongA1(xLong5))
                  Else
                  ReDim xByteA1(xLongA2(xLong5) - 1&)
                  Call RtlMoveMemory(xByteA1(0), ByVal xLongA1(xLong5), xLongA2(xLong5))
                  xChar1 = ""
                  For xLong6 = 0 To xLongA2(xLong5) - 1&
                    xChar1 = xChar1 + Hex((xByteA1(xLong6) And &HF0&) \ &H10&) + Hex(xByteA1(xLong6) And &HF&)
                    Next
                  xLong6 = LocalAllocFromString_Ansi(xChar1)
                  Call CallWindowProcA(ptrCallbackRows, 0&, 0&, xLong3 + xLong5, xLong6)
                  If Not xLong6 = 0& Then Call LocalFree(xLong6)
                  End If
                Next
              End If
            Next
          End If
        If Not ptrCallbackGen = 0& Then
          Call CallWindowProcA(ptrCallbackGen, 0&, 0&, 2&, xLong1 * RowDiv + xLong2)
          End If
        MySQL_Select_Enum = True
        End If
      Call mysql_free_result(hEnum)
      End If
    End If
  End Function
