1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
4 * This file is part of the LibreOffice project.
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 * This file incorporates work covered by the following license notice:
12 * Licensed to the Apache Software Foundation (ASF) under one or more
13 * contributor license agreements. See the NOTICE file distributed
14 * with this work for additional information regarding copyright
15 * ownership. The ASF licenses this file to you under the Apache
16 * License, Version 2.0 (the "License"); you may not use this file
17 * except in compliance with the License. You may obtain a copy of
18 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 <script:module xmlns:
script=
"http://openoffice.org/2000/script" script:
name=
"DBMeta" script:
language=
"StarBasic">REM ***** BASIC *****
24 Public iCommandTypes() as Integer
25 Public CurCommandType as Integer
26 Public oDataSource as Object
27 Public bEnableBinaryOptionGroup as Boolean
28 'Public bSelectContent as Boolean
31 Function GetDatabaseNames(baddFirstListItem as Boolean)
33 If oDBContext.HasElements Then
34 Dim LocDBList() as String
35 Dim MaxIndex as Integer
37 LocDBList = oDBContext.ElementNames()
38 MaxIndex = Ubound(LocDBList())
39 If baddfirstListItem Then
40 ReDim Preserve sDatabaseList(MaxIndex +
1)
41 sDatabaseList(
0) = sSelectDatasource
44 ReDim Preserve sDatabaseList(MaxIndex)
48 sDatabaseList(a) = oDBContext.ElementNames(i)
52 GetDatabaseNames() = sDatabaseList()
56 Sub GetSelectedDBMetaData(sDBName as String)
57 Dim OldsDBname as String
58 Dim DBIndex as Integer
59 Dim LocList() as String
60 ' If bStartUp Then
61 ' bStartUp = false
64 ToggleDatabasePage(False)
66 If GetConnection(sDBName) Then
67 If GetDBMetaData() Then
68 LocList() = AddListToList(Array(sSelectDBTable), TableNames())
69 .lstTables.StringItemList() = AddListToList(LocList(), QueryNames())
70 ' bSelectContent = True
71 .lstTables.SelectedItems() = Array(
0)
72 iCommandTypes() = CreateCommandTypeList()
73 EmptyFieldsListboxes()
76 bEnableBinaryOptionGroup = False
77 .lstTables.Enabled = True
78 .lblTables.Enabled = True
80 ' DialogModel.lstTables.StringItemList = Array(sSelectDBTable)
81 ' EmptyFieldsListboxes()
83 ToggleDatabasePage(True)
88 Function GetConnection(sDBName as String)
89 Dim oInteractionHandler as Object
90 Dim bExitLoop as Boolean
91 Dim bGetConnection as Boolean
94 If Not IsNull(oDBConnection) Then
95 oDBConnection.Dispose()
97 oDataSource = oDBContext.GetByName(sDBName)
98 ' If Not oDBContext.hasbyName(sDBName) Then
99 ' GetConnection() = False
102 If Not oDataSource.IsPasswordRequired Then
103 oDBConnection = oDBContext.GetByName(sDBName).GetConnection(
"",
"")
104 GetConnection() = True
106 oInteractionHandler = createUnoService(
"com.sun.star.task.InteractionHandler
")
107 oDataSource = oDBContext.GetByName(sDBName)
108 On Local Error Goto NOCONNECTION
111 oDBConnection = oDataSource.ConnectWithCompletion(oInteractionHandler)
113 bGetConnection = Err =
0
114 If bGetConnection Then
115 bGetConnection = Not IsNull(oDBConnection)
116 If Not bGetConnection Then
120 If Not bGetConnection Then
121 iMsg = Msgbox (sMsgNoConnection,
32 +
2, sMsgWizardName)
122 bExitLoop = iMsg = SBCANCEL
127 On Local Error Goto
0
128 If Not bGetConnection Then
129 DialogModel.lstTables.StringItemList() = Array(sSelectDBTable)
130 DialogModel.lstFields.StringItemList() = NullList()
131 DialogModel.lstSelFields.StringItemList() = NullList()
133 GetConnection() = bGetConnection
138 Function GetDBMetaData()
139 If oDBContext.HasElements Then
140 Tablenames() = oDBConnection.Tables.ElementNames()
141 Querynames() = oDBConnection.Queries.ElementNames()
144 MsgBox(sMsgErrNoDatabase,
64, sMsgWizardName)
145 GetDBMetaData = False
150 Sub GetTableMetaData()
155 Dim sFieldName as String
157 Dim WidthIndex as Integer
159 MaxIndex = Ubound(DialogModel.lstSelFields.StringItemList())
160 Dim ColumnMap(MaxIndex)as Integer
161 FieldNames() = DialogModel.lstSelFields.StringItemList()
162 ' Build a structure which maps the position of a selected field (within the selection) to the column position within
163 ' the table. So we ensure that the controls are placed in the same order the according fields are selected.
164 For i =
0 To Ubound(FieldNames())
165 sFieldName = FieldNames(i)
168 While (n
< MaxIndex And (Not Found))
169 If (FieldNames(n) = sFieldName) Then
176 For n =
0 to MaxIndex
177 sFieldname = FieldNames(n)
178 oField = oColumns.GetByName(sFieldName)
180 FieldMetaValues(n,
0) = oField.Type
181 FieldMetaValues(n,
1) = AssignFieldLength(oField.Precision)
182 FieldMetaValues(n,
2) = GetValueoutofList(iType, WidthList(),
1, WidthIndex)
183 FieldMetaValues(n,
3) = WidthList(WidthIndex,
3)
184 FieldMetaValues(n,
4) = oField.FormatKey
185 FieldMetaValues(n,
5) = oField.DefaultValue
186 FieldMetaValues(n,
6) = oField.IsCurrency
187 FieldMetaValues(n,
7) = oField.Scale
188 ' If oField.Description
<> "" Then
189 '' Todo: What
's wrong with this line?
190 ' Msgbox oField.Helptext
192 FieldMetaValues(n,
8) = oField.Description
194 ReDim oDBShapeList(MaxIndex) as Object
195 ReDim oTCShapeList(MaxIndex) as Object
196 ReDim oDBModelList(MaxIndex) as Object
197 ReDim oGroupShapeList(MaxIndex) as Object
201 Function GetSpecificFieldNames() as Integer
207 Dim MaxIndex as Integer
209 If Ubound(DialogModel.lstTables.StringItemList())
> -
1 Then
210 FieldNames() = oColumns.GetElementNames()
211 MaxIndex = Ubound(FieldNames())
212 If MaxIndex
<> -
1 Then
213 Dim ResultFieldNames(MaxIndex)
214 ReDim ImgFieldNames(MaxIndex)
216 For n =
0 To MaxIndex
217 oField = oColumns.GetByName(FieldNames(n))
219 If GetIndexInMultiArray(WidthList(), iType,
0)
<> -
1 Then
220 ResultFieldNames(m) = FieldNames(n)
223 If GetIndexInMultiArray(ImgWidthList(), iType,
0)
<> -
1 Then
224 ImgFieldNames(s) = FieldNames(n)
229 Redim Preserve ImgFieldNames(s-
1)
230 bEnableBinaryOptionGroup = True
232 bEnableBinaryOptionGroup = False
234 If (DialogModel.optBinariesasGraphics.State =
1) And (s
<> 0) Then
235 ResultFieldNames() = AddListToList(ResultFieldNames(), ImgFieldNames())
237 Redim Preserve ResultFieldNames(m-
1)
239 FieldNames() = ResultFieldNames()
240 DialogModel.lstFields.StringItemList = FieldNames()
241 InitializeListboxProcedures(DialogModel, DialogModel.lstFields, DialogModel.lstSelFields)
243 GetSpecificFieldNames = MaxIndex
245 GetSpecificFieldNames = -
1
251 If oDrawPage.Forms.Count =
0 Then
252 oDBForm = oDocument.CreateInstance(
"com.sun.star.form.component.Form
")
253 oDrawpage.Forms.InsertByIndex (
0, oDBForm)
255 oDBForm = oDrawPage.Forms.GetByIndex(
0)
257 oDBForm.Name =
"Standard
"
258 oDBForm.DataSourceName = sDBName
259 oDBForm.Command = TableName
260 oDBForm.CommandType = CurCommandType
264 Sub AddOrRemoveBinaryFieldsToWidthList()
266 Dim MaxIndex as Integer
267 Dim OldMaxIndex as Integer
272 On Local Error GoTo WIZARDERROR
274 If DialogModel.optBinariesasGraphics.State =
1 Then
275 OldMaxIndex = Ubound(WidthList(),
1)
276 If OldMaxIndex =
15 Then
277 MaxIndex = Ubound(WidthList(),
1) + Ubound(ImgWidthList(),
1) +
1
278 ReDim Preserve WidthList(MaxIndex,
4)
280 For n = OldMaxIndex +
1 To MaxIndex
282 WidthList(n,m) = ImgWidthList(s,m)
286 MergeList(DialogModel.lstFields, ImgFieldNames())
289 ReDim Preserve WidthList(
15,
4)
290 RemoveListItems(DialogModel.lstFields(), DialogModel.lstSelFields(), ImgFieldNames())
292 DialogModel.lstSelFields.Tag = True
294 If Err
<> 0 Then
295 Msgbox(sMsgErrMsg,
16, GetProductName())
302 Function CreateCommandTypeList()
303 Dim MaxTableIndex as Integer
304 Dim MaxQueryIndex as Integer
305 Dim MaxIndex as Integer
308 MaxTableIndex = Ubound(TableNames()
309 MaxQueryIndex = Ubound(QueryNames()
310 MaxIndex = MaxTableIndex + MaxQueryIndex +
1
311 If MaxIndex
> -
1 Then
312 Dim LocCommandTypes(MaxIndex) as Integer
313 For i =
0 To MaxTableIndex
314 LocCommandTypes(i) = com.sun.star.sdb.CommandType.TABLE
317 For i =
0 To MaxQueryIndex
318 LocCommandTypes(a) = com.sun.star.sdb.CommandType.QUERY
322 CreateCommandTypeList() = LocCommandTypes()
326 Sub GetCurrentMetaValues(Index as Integer)
327 CurFieldType = FieldMetaValues(Index,
0)
328 CurFieldLength = FieldMetaValues(Index,
1)
329 CurControlType = FieldMetaValues(Index,
2)
330 CurControlName = FieldMetaValues(Index,
3)
331 CurFormatKey = FieldMetaValues(Index,
4)
332 CurDefaultValue = FieldMetaValues(Index,
5)
333 CurIsCurrency = FieldMetaValues(Index,
6)
334 CurScale = FieldMetaValues(Index,
7)
335 CurHelpText = FieldMetaValues(Index,
8)
336 CurFieldName = FieldNames(Index)
340 Function AssignFieldLength(FieldLength as Long) as Integer
341 If FieldLength
>=
65535 Then
342 AssignFieldLength() = -
1
344 AssignFieldLength() = FieldLength