DataDef.xba 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
  3. <script:module xmlns:script="http://openoffice.org/2000/script" script:name="DataDef" script:language="StarBasic">
  4. REM =======================================================================================================================
  5. REM === The Access2Base library is a part of the LibreOffice project. ===
  6. REM === Full documentation is available on http://www.access2base.com ===
  7. REM =======================================================================================================================
  8. Option Compatible
  9. Option ClassModule
  10. Option Explicit
  11. REM -----------------------------------------------------------------------------------------------------------------------
  12. REM --- CLASS ROOT FIELDS ---
  13. REM -----------------------------------------------------------------------------------------------------------------------
  14. Private _Type As String &apos; Must be TABLEDEF or QUERYDEF
  15. Private _This As Object &apos; Workaround for absence of This builtin function
  16. Private _Parent As Object
  17. Private _Name As String &apos; For tables: [[Catalog.]Schema.]Table
  18. Private _ParentDatabase As Object
  19. Private _ReadOnly As Boolean
  20. Private Table As Object &apos; com.sun.star.sdb.dbaccess.ODBTable
  21. Private CatalogName As String
  22. Private SchemaName As String
  23. Private TableName As String
  24. Private Query As Object &apos; com.sun.star.sdb.dbaccess.OQuery
  25. Private TableDescriptor As Object &apos; com.sun.star.sdb.dbaccess.ODBTable
  26. Private TableFieldsCount As Integer
  27. Private TableKeysCount As Integer
  28. REM -----------------------------------------------------------------------------------------------------------------------
  29. REM --- CONSTRUCTORS / DESTRUCTORS ---
  30. REM -----------------------------------------------------------------------------------------------------------------------
  31. Private Sub Class_Initialize()
  32. _Type = &quot;&quot;
  33. Set _This = Nothing
  34. Set _Parent = Nothing
  35. _Name = &quot;&quot;
  36. Set _ParentDatabase = Nothing
  37. _ReadOnly = False
  38. Set Table = Nothing
  39. CatalogName = &quot;&quot;
  40. SchemaName = &quot;&quot;
  41. TableName = &quot;&quot;
  42. Set Query = Nothing
  43. Set TableDescriptor = Nothing
  44. TableFieldsCount = 0
  45. TableKeysCount = 0
  46. End Sub &apos; Constructor
  47. REM -----------------------------------------------------------------------------------------------------------------------
  48. Private Sub Class_Terminate()
  49. On Local Error Resume Next
  50. Call Class_Initialize()
  51. End Sub &apos; Destructor
  52. REM -----------------------------------------------------------------------------------------------------------------------
  53. Public Sub Dispose()
  54. Call Class_Terminate()
  55. End Sub &apos; Explicit destructor
  56. REM -----------------------------------------------------------------------------------------------------------------------
  57. REM --- CLASS GET/LET/SET PROPERTIES ---
  58. REM -----------------------------------------------------------------------------------------------------------------------
  59. Property Get Name() As String
  60. Name = _PropertyGet(&quot;Name&quot;)
  61. End Property &apos; Name (get)
  62. REM -----------------------------------------------------------------------------------------------------------------------
  63. Property Get ObjectType() As String
  64. ObjectType = _PropertyGet(&quot;ObjectType&quot;)
  65. End Property &apos; ObjectType (get)
  66. REM -----------------------------------------------------------------------------------------------------------------------
  67. Property Get SQL() As Variant
  68. SQL = _PropertyGet(&quot;SQL&quot;)
  69. End Property &apos; SQL (get)
  70. Property Let SQL(ByVal pvValue As Variant)
  71. Call _PropertySet(&quot;SQL&quot;, pvValue)
  72. End Property &apos; SQL (set)
  73. REM -----------------------------------------------------------------------------------------------------------------------
  74. Public Function pType() As Integer
  75. pType = _PropertyGet(&quot;Type&quot;)
  76. End Function &apos; Type (get)
  77. REM -----------------------------------------------------------------------------------------------------------------------
  78. REM --- CLASS METHODS ---
  79. REM -----------------------------------------------------------------------------------------------------------------------
  80. Public Function CreateField(ByVal Optional pvFieldName As Variant _
  81. , ByVal optional pvType As Variant _
  82. , ByVal optional pvSize As Variant _
  83. , ByVal optional pvAttributes As Variant _
  84. ) As Object
  85. &apos;Return a Field object
  86. Const cstThisSub = &quot;TableDef.CreateField&quot;
  87. Utils._SetCalledSub(cstThisSub)
  88. If _ErrorHandler() Then On Local Error Goto Error_Function
  89. Dim oTable As Object, oNewField As Object, oKeys As Object, oPrimaryKey As Object, oColumn As Object
  90. Const cstMaxKeyLength = 30
  91. CreateField = Nothing
  92. If _ParentDatabase._DbConnect &lt;&gt; DBCONNECTBASE Then Goto Error_NotApplicable
  93. If IsMissing(pvFieldName) Then Call _TraceArguments()
  94. If Not Utils._CheckArgument(pvFieldName, 1, vbString) Then Goto Exit_Function
  95. If pvFieldName = &quot;&quot; Then Call _TraceArguments()
  96. If IsMissing(pvType) Then Call _TraceArguments()
  97. If Not Utils._CheckArgument(pvType, 1, Utils._AddNumeric( _
  98. dbInteger, dbLong, dbBigInt, dbFloat, vbSingle, dbDouble _
  99. , dbNumeric, dbDecimal, dbText, dbChar, dbMemo _
  100. , dbDate, dbTime, dbTimeStamp _
  101. , dbBinary, dbVarBinary, dbLongBinary, dbBoolean _
  102. )) Then Goto Exit_Function
  103. If IsMissing(pvSize) Then pvSize = 0
  104. If pvSize &lt; 0 Then pvSize = 0
  105. If Not Utils._CheckArgument(pvSize, 1, Utils._AddNumeric()) Then Goto Exit_Function
  106. If IsMissing(pvAttributes) Then pvAttributes = 0
  107. If Not Utils._CheckArgument(pvAttributes, 1, Utils._AddNumeric(), Array(0, dbAutoIncrField)) Then Goto Exit_Function
  108. If _Type &lt;&gt; OBJTABLEDEF Then Goto Error_NotApplicable
  109. If IsNull(Table) And IsNull(TableDescriptor) Then Goto Error_NotApplicable
  110. If _ReadOnly Then Goto Error_NoUpdate
  111. Set oNewField = New Field
  112. With oNewField
  113. ._This = oNewField
  114. ._Name = pvFieldName
  115. ._ParentName = _Name
  116. ._ParentType = OBJTABLEDEF
  117. If IsNull(Table) Then Set oTable = TableDescriptor Else Set oTable = Table
  118. Set .Column = oTable.Columns.createDataDescriptor()
  119. End With
  120. With oNewField.Column
  121. .Name = pvFieldName
  122. Select Case pvType
  123. Case dbInteger : .Type = com.sun.star.sdbc.DataType.TINYINT
  124. Case dbLong : .Type = com.sun.star.sdbc.DataType.INTEGER
  125. Case dbBigInt : .Type = com.sun.star.sdbc.DataType.BIGINT
  126. Case dbFloat : .Type = com.sun.star.sdbc.DataType.FLOAT
  127. Case dbSingle : .Type = com.sun.star.sdbc.DataType.REAL
  128. Case dbDouble : .Type = com.sun.star.sdbc.DataType.DOUBLE
  129. Case dbNumeric, dbCurrency : .Type = com.sun.star.sdbc.DataType.NUMERIC
  130. Case dbDecimal : .Type = com.sun.star.sdbc.DataType.DECIMAL
  131. Case dbText : .Type = com.sun.star.sdbc.DataType.CHAR
  132. Case dbChar : .Type = com.sun.star.sdbc.DataType.VARCHAR
  133. Case dbMemo : .Type = com.sun.star.sdbc.DataType.LONGVARCHAR
  134. Case dbDate : .Type = com.sun.star.sdbc.DataType.DATE
  135. Case dbTime : .Type = com.sun.star.sdbc.DataType.TIME
  136. Case dbTimeStamp : .Type = com.sun.star.sdbc.DataType.TIMESTAMP
  137. Case dbBinary : .Type = com.sun.star.sdbc.DataType.BINARY
  138. Case dbVarBinary : .Type = com.sun.star.sdbc.DataType.VARBINARY
  139. Case dbLongBinary : .Type = com.sun.star.sdbc.DataType.LONGVARBINARY
  140. Case dbBoolean : .Type = com.sun.star.sdbc.DataType.BOOLEAN
  141. End Select
  142. .Precision = Int(pvSize)
  143. If pvType = dbNumeric Or pvType = dbDecimal Or pvType = dbCurrency Then .Scale = Int(pvSize * 10) - Int(pvSize) * 10
  144. .IsNullable = com.sun.star.sdbc.ColumnValue.NULLABLE
  145. If Utils._hasUNOProperty(oNewField.Column, &quot;CatalogName&quot;) Then .CatalogName = CatalogName
  146. If Utils._hasUNOProperty(oNewField.Column, &quot;SchemaName&quot;) Then .SchemaName = SchemaName
  147. If Utils._hasUNOProperty(oNewField.Column, &quot;TableName&quot;) Then .TableName = TableName
  148. If Not IsNull(TableDescriptor) Then TableFieldsCount = TableFieldsCount + 1
  149. If pvAttributes = dbAutoIncrField Then
  150. If Not IsNull(Table) Then Goto Error_Sequence &apos; Do not accept adding an AutoValue field when table exists
  151. Set oKeys = oTable.Keys
  152. Set oPrimaryKey = oKeys.createDataDescriptor()
  153. Set oColumn = oPrimaryKey.Columns.createDataDescriptor()
  154. oColumn.Name = pvFieldName
  155. oColumn.CatalogName = CatalogName
  156. oColumn.SchemaName = SchemaName
  157. oColumn.TableName = TableName
  158. oColumn.IsAutoIncrement = True
  159. oColumn.IsNullable = com.sun.star.sdbc.ColumnValue.NO_NULLS
  160. oPrimaryKey.Columns.appendByDescriptor(oColumn)
  161. oPrimaryKey.Name = Left(&quot;PK_&quot; &amp; Join(Split(TableName, &quot; &quot;), &quot;_&quot;) &amp; &quot;_&quot; &amp; Join(Split(pvFieldName, &quot; &quot;), &quot;_&quot;), cstMaxKeyLength)
  162. oPrimaryKey.Type = com.sun.star.sdbcx.KeyType.PRIMARY
  163. oKeys.appendByDescriptor(oPrimaryKey)
  164. .IsAutoIncrement = True
  165. .IsNullable = com.sun.star.sdbc.ColumnValue.NO_NULLS
  166. oColumn.dispose()
  167. Else
  168. .IsAutoIncrement = False
  169. End If
  170. End With
  171. oTable.Columns.appendByDescriptor(oNewfield.Column)
  172. Set CreateField = oNewField
  173. Exit_Function:
  174. Utils._ResetCalledSub(cstThisSub)
  175. Exit Function
  176. Error_Function:
  177. TraceError(TRACEABORT, Err, cstThisSub, Erl)
  178. GoTo Exit_Function
  179. Error_NotApplicable:
  180. TraceError(TRACEFATAL, ERRMETHOD, Utils._CalledSub(), 0, 1, cstThisSub)
  181. Goto Exit_Function
  182. Error_Sequence:
  183. TraceError(TRACEFATAL, ERRFIELDCREATION, Utils._CalledSub(), 0, 1, pvFieldName)
  184. Goto Exit_Function
  185. Error_NoUpdate:
  186. TraceError(TRACEFATAL, ERRNOTUPDATABLE, Utils._CalledSub(), 0)
  187. Goto Exit_Function
  188. End Function &apos; CreateField V1.1.0
  189. REM -----------------------------------------------------------------------------------------------------------------------
  190. Public Function Execute(ByVal Optional pvOptions As Variant) As Boolean
  191. &apos;Execute a stored query. The query must be an ACTION query.
  192. Dim cstThisSub As String
  193. cstThisSub = Utils._PCase(_Type) &amp; &quot;.Execute&quot;
  194. Utils._SetCalledSub(cstThisSub)
  195. On Local Error Goto Error_Function
  196. Const cstNull = -1
  197. Execute = False
  198. If _Type &lt;&gt; OBJQUERYDEF Then Goto Trace_Method
  199. If IsMissing(pvOptions) Then
  200. pvOptions = cstNull
  201. Else
  202. If Not Utils._CheckArgument(pvOptions, 1, Utils._AddNumeric(), dbSQLPassThrough) Then Goto Exit_Function
  203. End If
  204. &apos;Check action query
  205. Dim oStatement As Object, vResult As Variant
  206. Dim iType As Integer, sSql As String
  207. iType = pType
  208. If ( (iType And DBQAction) = 0 ) And ( (iType And DBQDDL) = 0 ) Then Goto Trace_Action
  209. &apos;Execute action query
  210. Set oStatement = _ParentDatabase.Connection.createStatement()
  211. sSql = Query.Command
  212. If pvOptions = dbSQLPassThrough Then oStatement.EscapeProcessing = False _
  213. Else oStatement.EscapeProcessing = Query.EscapeProcessing
  214. On Local Error Goto SQL_Error
  215. vResult = oStatement.executeUpdate(_ParentDatabase._ReplaceSquareBrackets(sSql))
  216. On Local Error Goto Error_Function
  217. Execute = True
  218. Exit_Function:
  219. Utils._ResetCalledSub(cstThisSub)
  220. Exit Function
  221. Trace_Method:
  222. TraceError(TRACEFATAL, ERRMETHOD, cstThisSub, 0, , cstThisSub)
  223. Goto Exit_Function
  224. Trace_Action:
  225. TraceError(TRACEFATAL, ERRNOTACTIONQUERY, cstThisSub, 0, , _Name)
  226. Goto Exit_Function
  227. SQL_Error:
  228. TraceError(TRACEFATAL, ERRSQLSTATEMENT, Utils._CalledSub(), 0, , sSql)
  229. Goto Exit_Function
  230. Error_Function:
  231. TraceError(TRACEABORT, Err, cstThisSub, Erl)
  232. GoTo Exit_Function
  233. End Function &apos; Execute V1.1.0
  234. REM -----------------------------------------------------------------------------------------------------------------------
  235. Public Function Fields(ByVal Optional pvIndex As Variant) As Object
  236. If _ErrorHandler() Then On Local Error Goto Error_Function
  237. Dim cstThisSub As String
  238. cstThisSub = Utils._PCase(_Type) &amp; &quot;.Fields&quot;
  239. Utils._SetCalledSub(cstThisSub)
  240. Set Fields = Nothing
  241. If Not IsMissing(pvIndex) Then
  242. If Not Utils._CheckArgument(pvIndex, 1, Utils._AddNumeric(vbString)) Then Goto Exit_Function
  243. End If
  244. Dim sObjects() As String, sObjectName As String, oObject As Object
  245. Dim i As Integer, bFound As Boolean, oFields As Object
  246. If _Type = OBJTABLEDEF Then Set oFields = Table.getColumns() Else Set oFields = Query.getColumns()
  247. sObjects = oFields.ElementNames()
  248. Select Case True
  249. Case IsMissing(pvIndex)
  250. Set oObject = New Collect
  251. Set oObject._This = oObject
  252. oObject._CollType = COLLFIELDS
  253. Set oObject._Parent = _This
  254. oObject._Count = UBound(sObjects) + 1
  255. Goto Exit_Function
  256. Case VarType(pvIndex) = vbString
  257. bFound = False
  258. &apos; Check existence of object and find its exact (case-sensitive) name
  259. For i = 0 To UBound(sObjects)
  260. If UCase(pvIndex) = UCase(sObjects(i)) Then
  261. sObjectName = sObjects(i)
  262. bFound = True
  263. Exit For
  264. End If
  265. Next i
  266. If Not bFound Then Goto Trace_NotFound
  267. Case Else &apos; pvIndex is numeric
  268. If pvIndex &lt; 0 Or pvIndex &gt; UBound(sObjects) Then Goto Trace_IndexError
  269. sObjectName = sObjects(pvIndex)
  270. End Select
  271. Set oObject = New Field
  272. Set oObject._This = oObject
  273. oObject._Name = sObjectName
  274. Set oObject.Column = oFields.getByName(sObjectName)
  275. oObject._ParentName = _Name
  276. oObject._ParentType = _Type
  277. Set oObject._ParentDatabase = _ParentDatabase
  278. Exit_Function:
  279. Set Fields = oObject
  280. Set oObject = Nothing
  281. Utils._ResetCalledSub(cstThisSub)
  282. Exit Function
  283. Error_Function:
  284. TraceError(TRACEABORT, Err, cstThisSub, Erl)
  285. GoTo Exit_Function
  286. Trace_NotFound:
  287. TraceError(TRACEFATAL, ERROBJECTNOTFOUND, Utils._CalledSub(), 0, , Array(_GetLabel(&quot;FIELD&quot;), pvIndex))
  288. Goto Exit_Function
  289. Trace_IndexError:
  290. TraceError(TRACEFATAL, ERRCOLLECTION, Utils._CalledSub(), 0)
  291. Goto Exit_Function
  292. End Function &apos; Fields
  293. REM -----------------------------------------------------------------------------------------------------------------------
  294. Public Function getProperty(Optional ByVal pvProperty As Variant) As Variant
  295. &apos; Return property value of psProperty property name
  296. Dim cstThisSub As String
  297. cstThisSub = Utils._PCase(_Type) &amp; &quot;.getProperty&quot;
  298. Utils._SetCalledSub(cstThisSub)
  299. If IsMissing(pvProperty) Then Call _TraceArguments()
  300. getProperty = _PropertyGet(pvProperty)
  301. Utils._ResetCalledSub(cstThisSub)
  302. End Function &apos; getProperty
  303. REM -----------------------------------------------------------------------------------------------------------------------
  304. Public Function hasProperty(ByVal Optional pvProperty As Variant) As Boolean
  305. &apos; Return True if object has a valid property called pvProperty (case-insensitive comparison !)
  306. Dim cstThisSub As String
  307. cstThisSub = Utils._PCase(_Type) &amp; &quot;.hasProperty&quot;
  308. Utils._SetCalledSub(cstThisSub)
  309. If IsMissing(pvProperty) Then hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList()) Else hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList(), pvProperty)
  310. Utils._ResetCalledSub(cstThisSub)
  311. Exit Function
  312. End Function &apos; hasProperty
  313. REM -----------------------------------------------------------------------------------------------------------------------
  314. Public Function OpenRecordset(ByVal Optional pvType As Variant, ByVal Optional pvOptions As Variant, ByVal Optional pvLockEdit As Variant) As Object
  315. &apos;Return a Recordset object based on current table- or querydef object
  316. Dim cstThisSub As String
  317. cstThisSub = Utils._PCase(_Type) &amp; &quot;.OpenRecordset&quot;
  318. Utils._SetCalledSub(cstThisSub)
  319. Const cstNull = -1
  320. Dim lCommandType As Long, sCommand As String, oObject As Object,bPassThrough As Boolean
  321. Dim iType As Integer, iOptions As Integer, iLockEdit As Integer
  322. Set oObject = Nothing
  323. If VarType(pvType) = vbError Then
  324. iType = cstNull
  325. ElseIf IsMissing(pvType) Then
  326. iType = cstNull
  327. Else
  328. If Not Utils._CheckArgument(pvType, 1, Utils._AddNumeric(), Array(cstNull, dbOpenForwardOnly)) Then Goto Exit_Function
  329. iType = pvType
  330. End If
  331. If VarType(pvOptions) = vbError Then
  332. iOptions = cstNull
  333. ElseIf IsMissing(pvOptions) Then
  334. iOptions = cstNull
  335. Else
  336. If Not Utils._CheckArgument(pvOptions, 2, Utils._AddNumeric(), Array(cstNull, dbSQLPassThrough)) Then Goto Exit_Function
  337. iOptions = pvOptions
  338. End If
  339. If VarType(pvLockEdit) = vbError Then
  340. iLockEdit = cstNull
  341. ElseIf IsMissing(pvLockEdit) Then
  342. iLockEdit = cstNull
  343. Else
  344. If Not Utils._CheckArgument(pvLockEdit, 3, Utils._AddNumeric(), Array(cstNull, dbReadOnly)) Then Goto Exit_Function
  345. iLockEdit = pvLockEdit
  346. End If
  347. Select Case _Type
  348. Case OBJTABLEDEF
  349. lCommandType = com.sun.star.sdb.CommandType.TABLE
  350. sCommand = _Name
  351. Case OBJQUERYDEF
  352. lCommandType = com.sun.star.sdb.CommandType.QUERY
  353. sCommand = _Name
  354. If iOptions = dbSQLPassThrough Then bPassThrough = True Else bPassThrough = Not Query.EscapeProcessing
  355. End Select
  356. Set oObject = New Recordset
  357. With oObject
  358. ._CommandType = lCommandType
  359. ._Command = sCommand
  360. ._ParentName = _Name
  361. ._ParentType = _Type
  362. ._ForwardOnly = ( iType = dbOpenForwardOnly )
  363. ._PassThrough = bPassThrough
  364. ._ReadOnly = ( (iLockEdit = dbReadOnly) Or _ReadOnly )
  365. Set ._ParentDatabase = _ParentDatabase
  366. Set ._This = oObject
  367. Call ._Initialize()
  368. End With
  369. With _ParentDatabase
  370. .RecordsetMax = .RecordsetMax + 1
  371. oObject._Name = Format(.RecordsetMax, &quot;0000000&quot;)
  372. .RecordsetsColl.Add(oObject, UCase(oObject._Name))
  373. End With
  374. If Not ( oObject._BOF And oObject._EOF ) Then oObject.MoveFirst() &apos; Do nothing if resultset empty
  375. Exit_Function:
  376. Set OpenRecordset = oObject
  377. Set oObject = Nothing
  378. Utils._ResetCalledSub(cstThisSub)
  379. Exit Function
  380. Error_Function:
  381. TraceError(TRACEABORT, Err, cstThisSub, Erl)
  382. Set oObject = Nothing
  383. GoTo Exit_Function
  384. End Function &apos; OpenRecordset V1.1.0
  385. REM -----------------------------------------------------------------------------------------------------------------------
  386. Public Function Properties(ByVal Optional pvIndex As Variant) As Variant
  387. &apos; Return
  388. &apos; a Collection object if pvIndex absent
  389. &apos; a Property object otherwise
  390. Dim vProperty As Variant, vPropertiesList() As Variant, sObject As String
  391. Dim cstThisSub As String
  392. cstThisSub = Utils._PCase(_Type) &amp; &quot;.Properties&quot;
  393. Utils._SetCalledSub(cstThisSub)
  394. vPropertiesList = _PropertiesList()
  395. sObject = Utils._PCase(_Type)
  396. If IsMissing(pvIndex) Then
  397. vProperty = PropertiesGet._Properties(sObject, _This, vPropertiesList)
  398. Else
  399. vProperty = PropertiesGet._Properties(sObject, _This, vPropertiesList, pvIndex)
  400. vProperty._Value = _PropertyGet(vPropertiesList(pvIndex))
  401. End If
  402. Set vProperty._ParentDatabase = _ParentDatabase
  403. Exit_Function:
  404. Set Properties = vProperty
  405. Utils._ResetCalledSub(cstThisSub)
  406. Exit Function
  407. End Function &apos; Properties
  408. REM -----------------------------------------------------------------------------------------------------------------------
  409. Public Function setProperty(ByVal Optional psProperty As String, ByVal Optional pvValue As Variant) As Boolean
  410. &apos; Return True if property setting OK
  411. Dim cstThisSub As String
  412. cstThisSub = Utils._PCase(_Type) &amp; &quot;.setProperty&quot;
  413. Utils._SetCalledSub(cstThisSub)
  414. setProperty = _PropertySet(psProperty, pvValue)
  415. Utils._ResetCalledSub(cstThisSub)
  416. End Function
  417. REM -----------------------------------------------------------------------------------------------------------------------
  418. REM --- PRIVATE FUNCTIONS ---
  419. REM -----------------------------------------------------------------------------------------------------------------------
  420. REM -----------------------------------------------------------------------------------------------------------------------
  421. Private Function _PropertiesList() As Variant
  422. Select Case _Type
  423. Case OBJTABLEDEF
  424. _PropertiesList = Array(&quot;Name&quot;, &quot;ObjectType&quot;)
  425. Case OBJQUERYDEF
  426. _PropertiesList = Array(&quot;Name&quot;, &quot;ObjectType&quot;, &quot;SQL&quot;, &quot;Type&quot;)
  427. Case Else
  428. End Select
  429. End Function &apos; _PropertiesList
  430. REM -----------------------------------------------------------------------------------------------------------------------
  431. Private Function _PropertyGet(ByVal psProperty As String) As Variant
  432. &apos; Return property value of the psProperty property name
  433. If _ErrorHandler() Then On Local Error Goto Error_Function
  434. Dim cstThisSub As String
  435. cstThisSub = Utils._PCase(_Type)
  436. Utils._SetCalledSub(cstThisSub &amp; &quot;.get&quot; &amp; psProperty)
  437. Dim sSql As String, sVerb As String, iType As Integer
  438. _PropertyGet = EMPTY
  439. If Not hasProperty(psProperty) Then Goto Trace_Error
  440. Select Case UCase(psProperty)
  441. Case UCase(&quot;Name&quot;)
  442. _PropertyGet = _Name
  443. Case UCase(&quot;ObjectType&quot;)
  444. _PropertyGet = _Type
  445. Case UCase(&quot;SQL&quot;)
  446. _PropertyGet = Query.Command
  447. Case UCase(&quot;Type&quot;)
  448. iType = 0
  449. sSql = Utils._Trim(UCase(Query.Command))
  450. sVerb = Split(sSql, &quot; &quot;)(0)
  451. If sVerb = &quot;SELECT&quot; Then iType = iType + dbQSelect
  452. If sVerb = &quot;SELECT&quot; And InStr(sSql, &quot; INTO &quot;) &gt; 0 _
  453. Or sVerb = &quot;CREATE&quot; And InStr(sSql, &quot; TABLE &quot;) &gt; 0 _
  454. Then iType = iType + dbQMakeTable
  455. If sVerb = &quot;SELECT&quot; And InStr(sSql, &quot; UNION &quot;) &gt; 0 Then iType = iType + dbQSetOperation
  456. If Not Query.EscapeProcessing Then iType = iType + dbQSQLPassThrough
  457. If sVerb = &quot;INSERT&quot; Then iType = iType + dbQAppend
  458. If sVerb = &quot;DELETE&quot; Then iType = iType + dbQDelete
  459. If sVerb = &quot;UPDATE&quot; Then iType = iType + dbQUpdate
  460. If sVerb = &quot;CREATE&quot; _
  461. Or sVerb = &quot;ALTER&quot; _
  462. Or sVerb = &quot;DROP&quot; _
  463. Or sVerb = &quot;RENAME&quot; _
  464. Or sVerb = &quot;TRUNCATE&quot; _
  465. Then iType = iType + dbQDDL
  466. &apos; dbQAction implied by dbQMakeTable, dbQAppend, dbQDelete and dbQUpdate
  467. &apos; To check Type use: If (iType And dbQxxx) &lt;&gt; 0 Then ...
  468. _PropertyGet = iType
  469. Case Else
  470. Goto Trace_Error
  471. End Select
  472. Exit_Function:
  473. Utils._ResetCalledSub(cstThisSub &amp; &quot;.get&quot; &amp; psProperty)
  474. Exit Function
  475. Trace_Error:
  476. TraceError(TRACEWARNING, ERRPROPERTY, Utils._CalledSub(), 0, , psProperty)
  477. _PropertyGet = EMPTY
  478. Goto Exit_Function
  479. Error_Function:
  480. TraceError(TRACEABORT, Err, cstThisSub &amp; &quot;._PropertyGet&quot;, Erl)
  481. _PropertyGet = EMPTY
  482. GoTo Exit_Function
  483. End Function &apos; _PropertyGet
  484. REM -----------------------------------------------------------------------------------------------------------------------
  485. Private Function _PropertySet(ByVal psProperty As String, ByVal pvValue As Variant) As Boolean
  486. &apos; Return True if property setting OK
  487. If _ErrorHandler() Then On Local Error Goto Error_Function
  488. Dim cstThisSub As String
  489. cstThisSub = Utils._PCase(_Type)
  490. Utils._SetCalledSub(cstThisSub &amp; &quot;.set&quot; &amp; psProperty)
  491. &apos;Execute
  492. Dim iArgNr As Integer
  493. _PropertySet = True
  494. Select Case UCase(_A2B_.CalledSub)
  495. Case UCase(&quot;setProperty&quot;) : iArgNr = 3
  496. Case UCase(cstThisSub &amp; &quot;.setProperty&quot;) : iArgNr = 2
  497. Case UCase(cstThisSub &amp; &quot;.set&quot; &amp; psProperty) : iArgNr = 1
  498. End Select
  499. If Not hasProperty(psProperty) Then Goto Trace_Error
  500. If _ReadOnly Then Goto Error_NoUpdate
  501. Select Case UCase(psProperty)
  502. Case UCase(&quot;SQL&quot;)
  503. If Not Utils._CheckArgument(pvValue, iArgNr, vbString, , False) Then Goto Trace_Error_Value
  504. Query.Command = pvValue
  505. Case Else
  506. Goto Trace_Error
  507. End Select
  508. Exit_Function:
  509. Utils._ResetCalledSub(cstThisSub &amp; &quot;.set&quot; &amp; psProperty)
  510. Exit Function
  511. Trace_Error:
  512. TraceError(TRACEFATAL, ERRPROPERTY, Utils._CalledSub(), 0, , psProperty)
  513. _PropertySet = False
  514. Goto Exit_Function
  515. Trace_Error_Value:
  516. TraceError(TRACEFATAL, ERRPROPERTYVALUE, Utils._CalledSub(), 0, 1, Array(pvValue, psProperty))
  517. _PropertySet = False
  518. Goto Exit_Function
  519. Error_NoUpdate:
  520. TraceError(TRACEFATAL, ERRNOTUPDATABLE, Utils._CalledSub(), 0)
  521. Goto Exit_Function
  522. Error_Function:
  523. TraceError(TRACEABORT, Err, cstThisSub &amp; &quot;._PropertySet&quot;, Erl)
  524. _PropertySet = False
  525. GoTo Exit_Function
  526. End Function &apos; _PropertySet
  527. </script:module>