home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / bp_1_94 / vbwin / prof_db / bspsel.bas
BASIC Source File  |  1994-04-08  |  6KB  |  215 lines

  1. ' DEKLARATIONSTEIL
  2.  
  3. '********************************************************************
  4. '                   BeginnW3ISQL_Declared
  5. '********************************************************************
  6.  
  7. Global Const ITEMSIZE = 255
  8. Global Const TABUNITS = 5
  9.  
  10. Type COLTYPE
  11.     Name As String
  12.     Type As Integer
  13.     Len As Integer
  14.     Buffer As String
  15. End Type
  16.  
  17. 'Konstanten
  18.  
  19. Global Const SUCCEED = 1
  20. Global Const fail = 0
  21.  
  22. Global Const NO_MORE_RESULTS = -2
  23.  
  24. Global Const SQLCHAR = 0
  25. Global Const SQLSMINT = 1
  26. Global Const SQLINT = 2
  27. Global Const SQLFLOAT = 3
  28. Global Const SQLSMFLOAT = 4
  29. Global Const SQLDECIMAL = 5
  30. Global Const SQLSERIAL = 6
  31. Global Const SQLDATE = 7
  32. Global Const SQLMONEY = 8
  33. Global Const SQLNULL = 9
  34. Global Const SQLDTIME = 10
  35. Global Const SQLBYTES = 11
  36. Global Const SQLTEXT = 12
  37. Global Const SQLVCHAR = 13
  38. Global Const SQLINTERVAL = 14
  39. Global dbproc As Long
  40. Global backend_present As Integer
  41.  
  42. 'Limits
  43.  
  44. Global Const MAXCOLS = 40
  45.  
  46. 'Datenbankfunktionen
  47.  
  48. Declare Function dbbind Lib "w3isql.dll" (ByVal dbproc%, ByVal ColNum%, ByVal DestType%, ByVal DestLen&, ByVal Dest$) As Integer
  49. Declare Function dbcmd Lib "w3isql.dll" (ByVal dbproc%, ByVal cmd$) As Integer
  50. Declare Sub dbclose Lib "w3isql.dll" (ByVal dbproc%)
  51. Declare Function dbcollen Lib "w3isql.dll" (ByVal dbproc%, ByVal ColNum%) As Integer
  52. Declare Function dbcolname Lib "w3isql.dll" (ByVal dbproc%, ByVal ColNum%) As Long
  53. Declare Function dbcoltype Lib "w3isql.dll" (ByVal dbproc%, ByVal ColNum%) As Integer
  54. Declare Function dbxldata Lib "w3isql.dll" (ByVal dbproc%, ByVal ColNum%) As String
  55. Declare Function dbdata Lib "w3isql.dll" (ByVal dbproc%, ByVal ColNum%) As Long
  56. Declare Function dbdatlen Lib "w3isql.dll" (ByVal dbproc%, ByVal ColNum%) As Integer
  57. Declare Function dbcount Lib "w3isql.dll" (ByVal dbproc%) As Integer
  58. Declare Sub dbexit Lib "w3isql.dll" ()
  59. Declare Function dbinit Lib "w3isql.dll" () As Integer
  60. Declare Function dbinst Lib "w3isql.dll" () As Integer
  61. Declare Function dbnextrow Lib "w3isql.dll" (ByVal dbproc%) As Integer
  62. Declare Function dbnumcols Lib "w3isql.dll" (ByVal dbproc%) As Integer
  63. Declare Function dbconnect Lib "w3isql.dll" (ByVal user$, ByVal password$) As Integer
  64. Declare Function dbopen Lib "w3isql.dll" (ByVal login&, ByVal s$) As Integer
  65. Declare Function dbresults Lib "w3isql.dll" (ByVal dbproc%) As Integer
  66. Declare Function dbrows Lib "w3isql.dll" (ByVal dbproc%) As Integer
  67. Declare Function dbsqlexec Lib "w3isql.dll" (ByVal dbproc%) As Integer
  68. Declare Function dbuse Lib "w3isql.dll" (ByVal dbproc%, ByVal dbname$) As Integer
  69. Declare Sub dbwinexit Lib "w3isql.dll" ()
  70.  
  71.  
  72. 'VisualBasicSupport
  73.  
  74. Declare Function vbstring Lib "w3isql.dll" (ByVal pointer&) As String
  75. Declare Function vbstrbas Lib "w3isql.dll" Alias "vbstring" (ByVal vbstr$) As String
  76.  
  77. Declare Function vbdeftab Lib "w3isql.dll" (EdCtl As Control) As Integer
  78. Declare Function vbmemtab Lib "w3isql.dll" (ByVal pos%) As Integer
  79. Declare Function vbsettab Lib "w3isql.dll" (EdCtl As Control) As Integer
  80.  
  81. Declare Sub VBGetDouble Lib "w3isql.dll" (Dest#, ByVal Source&)
  82. Declare Sub VBGetLong Lib "w3isql.dll" (Dest&, ByVal Source&)
  83. Declare Sub VBGetInt Lib "w3isql.dll" (Dest%, ByVal Source&)
  84.  
  85. 'LowLevel
  86.  
  87. Declare Function strtrimr Lib "w3isql.dll" (lpStr As Long) As Long
  88.  
  89.  
  90. '********************************************************************
  91. '                   EndeW3ISQL_Declared
  92. '********************************************************************
  93.  
  94.  
  95. Function SQL_SELECT() 
  96. Dim anz_row As Integer
  97. Dim anz_col As Integer
  98. Dim i As Integer
  99. Dim ret_code As Integer
  100. Dim n_row As Long
  101. Dim tmp As String
  102. Dim strlen As Integer
  103. Dim Col() As coltype
  104.  
  105. On Error GoTo err_sql_select_request
  106.  
  107.     '
  108.     ' Datenbank ÷ffnen
  109.     '
  110.     If dbcmd(dbproc, "DATABASE beispiel") = fail Then
  111.         sql_select_request = False
  112.         Exit Function
  113.     End If
  114.     If dbsqlexec(dbproc) = fail Then
  115.         sql_select_request = False
  116.         Exit Function
  117.     End If
  118.  
  119.     '
  120.     ' Selectstatement in den Commandbuffer schreiben
  121.     '
  122.     If dbcmd(dbproc, "SELECT * FROM kunden") = fail Then
  123.         sql_select_request = False
  124.         Exit Function
  125.     End If
  126.     ' SQL-Statement im Backend ausfⁿhren
  127.     If dbsqlexec(dbproc) = fail Then
  128.         sql_select_request = False
  129.         Exit Function
  130.     End If
  131.     ' Ergebniss in den Datenbuffer schreiben
  132.     If dbresults(dbproc) = fail Then
  133.         sql_select_request = False
  134.         Exit Function
  135.     End If
  136.  
  137.     'Anzahl der Datensaetze in der Ergebnismenge ermitteln
  138.     anz_row = dbcount(dbproc)
  139.     'Anzahl der Spalten feststellen
  140.     anz_col = dbnumcols(dbproc)
  141.  
  142.     '
  143.     ' Arrays vergroessern
  144.     '
  145.     ReDim Col(0 To anz_col) As coltype
  146.     ReDim result_array(0 To anz_col) As String
  147.     grid1.FixedRows = 1
  148.     grid1.FixedCols = 1
  149.     grid1.Cols = anz_col + 1
  150.  
  151.     '
  152.     'Spalten auslesen
  153.     '
  154.     For i = 1 To anz_col
  155.         Col(i).name = RTrim(vbstring(dbcolname(dbproc, i)))
  156.         Col(i).Len = Len(Col(i).name)
  157.         Col(i).buffer = String$(ITEMSIZE, 0)
  158.  
  159.         ret_code = dbbind(dbproc, i, SQLCHAR, ITEMSIZE - 20, Col(i).buffer)
  160.         If ret_code = fail Then
  161.             sql_select_request = False
  162.             Exit Function
  163.         End If
  164.         
  165.         'Spaltennamen im Ergebnissgrid anzeigen
  166.         grid1.Col = i
  167.         grid1.Text = Col(i).name
  168.  
  169.     Next i
  170.  
  171.     n_row = 0
  172.  
  173.     '
  174.     'Datenfelder auslesen
  175.     '
  176.     While dbnextrow(dbproc) <> NO_MORE_RESULTS
  177.         '
  178.         ' ZΣhler der gelesenen DatensΣtze erh÷hen
  179.         ' damit das Ergebnisgrid vergr÷▀ert werden kann
  180.         '
  181.         n_row = n_row + 1
  182.         grid1.Rows = n_row + 1
  183.  
  184.         '
  185.         ' Zeilen nummerieren
  186.         '
  187.         grid1.Row = n_row
  188.         grid1.Col = 0
  189.         grid1.Text = n_row
  190.  
  191.         For i = 1 To anz_col
  192.             tmp$ = vbstrbas(Col(i).buffer)
  193.  
  194.             strlen = Len(tmp$)
  195.  
  196.             '
  197.             ' Feststellen ob gelesener Datensatz lΣnger als
  198.             ' der bislang lΣngste String
  199.             '
  200.             If strlen > Col(i).Len Then
  201.                 Col(i).Len = strlen
  202.             End If
  203.  
  204.             '
  205.             ' String in die Zelle des Ergebnissgrids schreiben
  206.             '
  207.             grid1.Col = i
  208.             grid1.Text = tmp$
  209.  
  210.         Next i
  211.     
  212.     Wend
  213.  
  214. End Function
  215.