home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / dbmsg / sql / vbsql / authors.bas < prev    next >
Encoding:
BASIC Source File  |  1996-04-03  |  4.1 KB  |  113 lines

  1. Option Explicit
  2.  
  3. Function AlterAuthors (pChannel As Integer)
  4. '
  5. ' This routine alters the Authors table with
  6. ' a TIMESTAMP column. Then it sends a 'dummy' update
  7. ' statement so that every row in the table
  8. ' gets a value in the TIMESTAMP column.
  9.  
  10. Dim lCmd$, lRetValue As Integer, lInfoText As String, Res%
  11.  
  12.     lRetValue = False
  13.     lInfoText = mdiMA.panInfo.Caption
  14.     mdiMA.panInfo.Caption = " Altering the authors table with a TIMESTAMP column."
  15.     lCmd$ = "alter table authors add timestamp timestamp NULL "
  16.     Res% = SQLComm%(pChannel, lCmd$)
  17.     If Res% = SUCCEED% Then
  18.         mdiMA.panInfo.Caption = " Every row in the authors table is now being updated."
  19.         lCmd$ = "update authors set au_fname = au_fname"
  20.         Res% = SQLComm%(pChannel, lCmd$)
  21.         If Res% = SUCCEED% Then lRetValue = True
  22.     End If
  23.     mdiMA.panInfo.Caption = lInfoText
  24.     AlterAuthors = lRetValue
  25.  
  26. End Function
  27.  
  28. Function AskifAlter ()
  29. '
  30. ' This routine asks if the user wants to
  31. ' alter the Authors table with a TIMESTAMP
  32. ' column.
  33.  
  34. Dim lMsg$, Res%, lRetValue As Integer
  35.  
  36.     lMsg$ = "This sample application needs a column with "
  37.     lMsg$ = lMsg$ + " the name TIMESTAMP and the datatype "
  38.     lMsg$ = lMsg$ + " TIMESTAMP in the authors table." + NEWLINE$
  39.     lMsg$ = lMsg$ + NEWLINE$ + "The reason is that this application "
  40.     lMsg$ = lMsg$ + "uses Browse Mode and Optimistic Concurrency "
  41.     lMsg$ = lMsg$ + "Control." + NEWLINE$ + NEWLINE$
  42.     lMsg$ = lMsg$ + "There is no TIMESTAMP column in your authors "
  43.     lMsg$ = lMsg$ + "table at this moment!" + NEWLINE$ + NEWLINE$
  44.     lMsg$ = lMsg$ + "If you click on the OK button the application "
  45.     lMsg$ = lMsg$ + "will create the column for you. If you click "
  46.     lMsg$ = lMsg$ + "on the cancel button you won't be able to run "
  47.     lMsg$ = lMsg$ + "this sample until the column is there."
  48.     Beep
  49.     Res% = MsgBox(lMsg$, 17, "Alter table authors")
  50.     If Res% = IDOK Then
  51.         lRetValue = True
  52.     Else
  53.         lRetValue = False
  54.     End If
  55.     AskifAlter = lRetValue
  56.  
  57. End Function
  58.  
  59. Function CheckifTimestamp (pChannel As Integer)
  60. '
  61. ' This routine checks if there is a TIMESTAMP column
  62. ' for the table Authors.
  63.  
  64. Dim lCmd$, lRetValue As Integer, Res%
  65.  
  66.     lRetValue = False
  67.     lCmd$ = "select count(*) from sysobjects so, syscolumns "
  68.     lCmd$ = lCmd$ + "sc where so.id = sc.id "
  69.     lCmd$ = lCmd$ + "and so.name = 'authors' "
  70.     lCmd$ = lCmd$ + "and sc.name = 'timestamp' "
  71.     lCmd$ = lCmd$ + "and sc.type = 37"
  72.     Res% = SQLComm%(pChannel, lCmd$)
  73.     If Res% = SUCCEED% Then
  74.         Res% = SQLNextRow(pChannel)
  75.         If Res% = REGROW Then
  76.             If Val(SQLData(pChannel, 1)) > 0 Then
  77.                 lRetValue = True
  78.             End If
  79.         End If
  80.     End If
  81.     CheckifTimestamp = lRetValue
  82.  
  83. End Function
  84.  
  85. Function EmptyQualString ()
  86. '
  87. ' This routine lets the user know that some condition
  88. ' for using Concurrency Control with Browse Mode is
  89. ' not fullfilled.
  90.  
  91. Dim lRetValue As String
  92.  
  93.     lRetValue = "The qual string is empty, which is not acceptable."
  94.     lRetValue = lRetValue + NEWLINE$ + NEWLINE$
  95.     lRetValue = lRetValue + "There are three mandatory preconditions for using "
  96.     lRetValue = lRetValue + "Concurrency Control with Browse Mode."
  97.     lRetValue = lRetValue + NEWLINE$ + NEWLINE$
  98.     lRetValue = lRetValue + "1 - You must have a unique index."
  99.     lRetValue = lRetValue + NEWLINE$ + NEWLINE$
  100.     lRetValue = lRetValue + "2 - You must have a column named TIMESTAMP with the "
  101.     lRetValue = lRetValue + " datatype TIMESTAMP in the specific table."
  102.     lRetValue = lRetValue + NEWLINE$ + NEWLINE$
  103.     lRetValue = lRetValue + "3 - You must add 'FOR BROWSE' to your SQL select statement "
  104.     lRetValue = lRetValue + NEWLINE$ + NEWLINE$
  105.     lRetValue = lRetValue + "Check to see if the unique index on the authors table "
  106.     lRetValue = lRetValue + "has been dropped. That might be the problem."
  107.     lRetValue = lRetValue + NEWLINE$ + NEWLINE$
  108.     lRetValue = lRetValue + "This operation will not go through to SQL Server."
  109.     EmptyQualString = lRetValue
  110.     
  111. End Function
  112.  
  113.