home *** CD-ROM | disk | FTP | other *** search
/ Master 95 #1 / MASTER95_1.iso / microsof / vbasic4 / vb4-6.cab / sql.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-07-26  |  6.8 KB  |  208 lines

  1. VERSION 4.00
  2. Begin VB.Form frmSQL 
  3.    Caption         =   "SQL Statement"
  4.    ClientHeight    =   2880
  5.    ClientLeft      =   3690
  6.    ClientTop       =   1575
  7.    ClientWidth     =   5250
  8.    Height          =   3285
  9.    HelpContextID   =   2016144
  10.    Icon            =   "SQL.frx":0000
  11.    Left            =   3630
  12.    LinkTopic       =   "Form1"
  13.    LockControls    =   -1  'True
  14.    MDIChild        =   -1  'True
  15.    ScaleHeight     =   2863.353
  16.    ScaleMode       =   0  'User
  17.    ScaleWidth      =   5268
  18.    Top             =   1230
  19.    Width           =   5370
  20.    Begin VB.CommandButton cmdSaveQueryDef 
  21.       Caption         =   "&Save"
  22.       Height          =   375
  23.       Left            =   3480
  24.       TabIndex        =   3
  25.       Top             =   120
  26.       Visible         =   0   'False
  27.       Width           =   1695
  28.    End
  29.    Begin VB.CommandButton cmdExecuteSQL 
  30.       Caption         =   "&Execute"
  31.       Default         =   -1  'True
  32.       Enabled         =   0   'False
  33.       Height          =   375
  34.       Left            =   120
  35.       TabIndex        =   1
  36.       Top             =   120
  37.       Width           =   1575
  38.    End
  39.    Begin VB.CommandButton cmdClearSQL 
  40.       Caption         =   "&Clear"
  41.       Height          =   375
  42.       Left            =   1800
  43.       TabIndex        =   2
  44.       Top             =   120
  45.       Width           =   1575
  46.    End
  47.    Begin VB.TextBox txtSQLStatement 
  48.       BackColor       =   &H00FFFFFF&
  49.       Height          =   2175
  50.       Left            =   120
  51.       MultiLine       =   -1  'True
  52.       ScrollBars      =   2  'Vertical
  53.       TabIndex        =   0
  54.       Top             =   600
  55.       Width           =   5055
  56.    End
  57. Attribute VB_Name = "frmSQL"
  58. Attribute VB_Creatable = False
  59. Attribute VB_Exposed = False
  60. Option Explicit
  61. Private Sub cmdClearSQL_Click()
  62.   txtSQLStatement.Text = gsNULL_STR
  63.   txtSQLStatement.SetFocus
  64. End Sub
  65. Private Sub cmdSaveQueryDef_Click()
  66.   On Error GoTo SQDErr
  67.   Dim sQueryName As String
  68.   Dim sTmp As String
  69.   Dim qdNew As QueryDef
  70.   If gbDBOpenFlag = False Then
  71.     MsgBox "No Database Open", 48
  72.     Exit Sub
  73.   End If
  74.   If frmTables.optQueryDefs.Value = True _
  75.     And frmTables.lstQueryDefs.ListIndex >= 0 Then
  76.     'a querydef is selected so user may want to update it's SQL
  77.     If MsgBox("Update '" & frmTables.lstQueryDefs.Text & "'?", gnMSGBOX_TYPE) = gnMSGBOX_YES Then
  78.       'store the SQL from the SQL Window in the currently
  79.       'selected querydef
  80.       gdbCurrentDB.QueryDefs(frmTables.lstQueryDefs.Text).SQL = Me.txtSQLStatement.Text
  81.       Exit Sub
  82.     End If
  83.   End If
  84.   'either there is no current querydef selected or the user
  85.   'didn't want to update the current one so we need
  86.   'to propmpt for a new name
  87.   sQueryName = InputBox("Enter QueryDef Name:")
  88.   If Len(sQueryName) = 0 Then Exit Sub
  89.   'check for a dupe and exit if the user won't overwrite it
  90.   If DupeTableName(sQueryName) = True Then
  91.     Exit Sub
  92.   End If
  93.   'add the new querydef
  94.   Set qdNew = gdbCurrentDB.CreateQueryDef(sQueryName)
  95.   'prompt for passthrough querydef
  96.   If MsgBox("Is this a SQLPassThrough QueryDef?", vbYesNo + vbQuestion + vbDefaultButton2) = vbYes Then
  97.     sTmp = InputBox("Enter Connect property value:")
  98.     If Len(sTmp) > 0 Then
  99.       qdNew.Connect = sTmp
  100.       If MsgBox("Is the Query Row Returning?", vbYesNo + vbQuestion) = vbNo Then
  101.         qdNew.ReturnsRecords = False
  102.       End If
  103.     End If
  104.   End If
  105.   qdNew.SQL = txtSQLStatement.Text
  106.   gdbCurrentDB.QueryDefs.Refresh
  107.   RefreshTables frmTables.lstTables, True
  108.   Exit Sub
  109. SQDErr:
  110.   ShowError
  111.   Exit Sub
  112. End Sub
  113. Private Sub txtSQLStatement_Change()
  114.   If Len(txtSQLStatement.Text) > 0 Then
  115.     cmdExecuteSQL.Enabled = True
  116.   Else
  117.     cmdExecuteSQL.Enabled = False
  118.   End If
  119. End Sub
  120. Private Sub cmdExecuteSQL_Click()
  121.   Dim Start1 As Long, Finish1 As Long
  122.    If gbDBOpenFlag = False Then
  123.      MsgBox "No Database Open", 48
  124.      Exit Sub
  125.    End If
  126.    If Len(txtSQLStatement.Text) = 0 Then Exit Sub
  127.    MsgBar "Executing SQL Statement", True
  128.    SetHourglass
  129.    If UCase(Mid(txtSQLStatement, 1, 6)) = "SELECT" And InStr(UCase(txtSQLStatement), " INTO ") = 0 Then
  130.      On Error GoTo SQLErr
  131. MakeDynaset:
  132.      gbFromSQL = True
  133.      'create a new recordset form
  134.      gsDynaString = gsNULL_STR
  135.      On Error GoTo SQLErr
  136.      If frmMDI.optNoDataCtl.Value = True Then
  137.        Dim recform1 As New frmDynaSnap
  138.        recform1.Show
  139.      ElseIf frmMDI.optDataCtl.Value = True Then
  140.        Dim recform2 As New frmDataControl
  141.        recform2.Show
  142.      ElseIf frmMDI.optTable.Value = True Then
  143.        Dim recform3 As New frmTableObj
  144.        recform3.Show
  145.      Else
  146.        Dim recform4 As New frmDataGrid
  147.        recform4.Show
  148.      End If
  149.    ElseIf Left(UCase(txtSQLStatement.Text), 9) = "TRANSFORM" Then
  150.      GoTo MakeDynaset
  151.    ElseIf UCase(txtSQLStatement.Text) = "LISTTABLES" Then
  152.      GoTo MakeDynaset
  153.    Else
  154.      On Error GoTo SQLErr
  155.      
  156.      Start1 = OSTimeGetTime()
  157.      If gsDataType = gsSQLDB Then
  158.        gdbCurrentDB.Execute (txtSQLStatement.Text), dbSQLPassThrough
  159.      Else
  160.        gdbCurrentDB.Execute (txtSQLStatement.Text)
  161.      End If
  162.      Finish1 = OSTimeGetTime()
  163.      
  164.      If gdbCurrentDB.RecordsAffected > 0 Then
  165.        If gbTransPending Then gbDBChanged = True
  166.      End If
  167.      
  168.      If frmMDI.mnuPShowPerf.Checked Then
  169.        MsgBox gdbCurrentDB.RecordsAffected & " row(s) Affected by SQL Statement in " & (Finish1 - Start1) / 1000 & " seconds!", 48
  170.      Else
  171.        MsgBox gdbCurrentDB.RecordsAffected & " row(s) Affected by SQL Statement.", 48
  172.      End If
  173.    End If
  174.    Screen.MousePointer = vbDefault
  175.    MsgBar gsNULL_STR, False
  176.    Exit Sub
  177. SQLErr:
  178.    If Err = 3065 Or Err = 3078 Then 'row returning or name not found so try to create recordset
  179.      Resume MakeDynaset
  180.    End If
  181.    ShowError
  182.    Exit Sub
  183. SQLEnd:
  184. End Sub
  185. Private Sub Form_Load()
  186.   txtSQLStatement.Text = GetINIString("SQLStatement", gsNULL_STR, gsVISDATA4)
  187.   Me.Height = Val(GetINIString("SQLWindowHeight", "3000", gsVISDATA4))
  188.   Me.Width = Val(GetINIString("SQLWindowWidth", "5370", gsVISDATA4))
  189.   Me.Top = Val(GetINIString("SQLWindowTop", "0", gsVISDATA4))
  190.   Me.Left = Val(GetINIString("SQLWindowLeft", CStr(frmTables.Left + frmTables.Width), gsVISDATA4))
  191. End Sub
  192. Private Sub Form_Resize()
  193.   On Error Resume Next
  194.   If WindowState <> 1 Then
  195.     txtSQLStatement.Width = Me.Width - 320
  196.     txtSQLStatement.Height = Me.Height - 1150
  197.   End If
  198. End Sub
  199. Private Sub Form_Unload(Cancel As Integer)
  200.   Me.WindowState = 1
  201.   Cancel = True
  202. End Sub
  203. Private Sub txtSQLStatement_DragDrop(Source As Control, x As Single, Y As Single)
  204.   If Source = frmTables.lstQueryDefs Then
  205.     frmSQL.txtSQLStatement.Text = gdbCurrentDB.QueryDefs(frmTables.lstQueryDefs.Text).SQL
  206.   End If
  207. End Sub
  208.