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=
"DBMeta" script:
language=
"StarBasic">REM ***** BASIC *****
7 Public iCommandTypes() as Integer
8 Public CurCommandType as Integer
9 Public oDataSource as Object
10 Public bEnableBinaryOptionGroup as Boolean
11 'Public bSelectContent as Boolean
14 Function GetDatabaseNames(baddFirstListItem as Boolean)
16 If oDBContext.HasElements Then
17 Dim LocDBList() as String
18 Dim MaxIndex as Integer
20 LocDBList = oDBContext.ElementNames()
21 MaxIndex = Ubound(LocDBList())
22 If baddfirstListItem Then
23 ReDim Preserve sDatabaseList(MaxIndex +
1)
24 sDatabaseList(
0) = sSelectDatasource
27 ReDim Preserve sDatabaseList(MaxIndex)
31 sDatabaseList(a) = oDBContext.ElementNames(i)
35 GetDatabaseNames() = sDatabaseList()
39 Sub GetSelectedDBMetaData(sDBName as String)
40 Dim OldsDBname as String
41 Dim DBIndex as Integer
42 Dim LocList() as String
43 ' If bStartUp Then
44 ' bStartUp = false
47 ToggleDatabasePage(False)
49 If GetConnection(sDBName) Then
50 If GetDBMetaData() Then
51 LocList() = AddListToList(Array(sSelectDBTable), TableNames())
52 .lstTables.StringItemList() = AddListToList(LocList(), QueryNames())
53 ' bSelectContent = True
54 .lstTables.SelectedItems() = Array(
0)
55 iCommandTypes() = CreateCommandTypeList()
56 EmptyFieldsListboxes()
59 bEnableBinaryOptionGroup = False
60 .lstTables.Enabled = True
61 .lblTables.Enabled = True
63 ' DialogModel.lstTables.StringItemList = Array(sSelectDBTable)
64 ' EmptyFieldsListboxes()
66 ToggleDatabasePage(True)
71 Function GetConnection(sDBName as String)
72 Dim oInteractionHandler as Object
73 Dim bExitLoop as Boolean
74 Dim bGetConnection as Boolean
77 If Not IsNull(oDBConnection) Then
78 oDBConnection.Dispose()
80 oDataSource = oDBContext.GetByName(sDBName)
81 ' If Not oDBContext.hasbyName(sDBName) Then
82 ' GetConnection() = False
85 If Not oDataSource.IsPasswordRequired Then
86 oDBConnection = oDBContext.GetByName(sDBName).GetConnection(
"",
"")
87 GetConnection() = True
89 oInteractionHandler = createUnoService(
"com.sun.star.sdb.InteractionHandler
")
90 oDataSource = oDBContext.GetByName(sDBName)
91 On Local Error Goto NOCONNECTION
94 oDBConnection = oDataSource.ConnectWithCompletion(oInteractionHandler)
96 bGetConnection = Err =
0
97 If bGetConnection Then
98 bGetConnection = Not IsNull(oDBConnection)
99 If Not bGetConnection Then
103 If Not bGetConnection Then
104 iMsg = Msgbox (sMsgNoConnection,
32 +
2, sMsgWizardName)
105 bExitLoop = iMsg = SBCANCEL
110 On Local Error Goto
0
111 If Not bGetConnection Then
112 DialogModel.lstTables.StringItemList() = Array(sSelectDBTable)
113 DialogModel.lstFields.StringItemList() = NullList()
114 DialogModel.lstSelFields.StringItemList() = NullList()
116 GetConnection() = bGetConnection
121 Function GetDBMetaData()
122 If oDBContext.HasElements Then
123 Tablenames() = oDBConnection.Tables.ElementNames()
124 Querynames() = oDBConnection.Queries.ElementNames()
127 MsgBox(sMsgErrNoDatabase,
64, sMsgWizardName)
128 GetDBMetaData = False
133 Sub GetTableMetaData()
138 Dim sFieldName as String
140 Dim WidthIndex as Integer
142 MaxIndex = Ubound(DialogModel.lstSelFields.StringItemList())
143 Dim ColumnMap(MaxIndex)as Integer
144 FieldNames() = DialogModel.lstSelFields.StringItemList()
145 ' Build a structure which maps the position of a selected field (within the selection) to the the column position within
146 ' the table. So we ensure that the controls are placed in the same order the according fields are selected.
147 For i =
0 To Ubound(FieldNames())
148 sFieldName = FieldNames(i)
151 While (n
< MaxIndex And (Not Found))
152 If (FieldNames(n) = sFieldName) Then
159 For n =
0 to MaxIndex
160 sFieldname = FieldNames(n)
161 oField = oColumns.GetByName(sFieldName)
163 FieldMetaValues(n,
0) = oField.Type
164 FieldMetaValues(n,
1) = AssignFieldLength(oField.Precision)
165 FieldMetaValues(n,
2) = GetValueoutofList(iType, WidthList(),
1, WidthIndex)
166 FieldMetaValues(n,
3) = WidthList(WidthIndex,
3)
167 FieldMetaValues(n,
4) = oField.FormatKey
168 FieldMetaValues(n,
5) = oField.DefaultValue
169 FieldMetaValues(n,
6) = oField.IsCurrency
170 FieldMetaValues(n,
7) = oField.Scale
171 ' If oField.Description
<> "" Then
172 '' Todo: What
's wrong with this line?
173 ' Msgbox oField.Helptext
175 FieldMetaValues(n,
8) = oField.Description
177 ReDim oDBShapeList(MaxIndex) as Object
178 ReDim oTCShapeList(MaxIndex) as Object
179 ReDim oDBModelList(MaxIndex) as Object
180 ReDim oGroupShapeList(MaxIndex) as Object
184 Function GetSpecificFieldNames() as Integer
190 Dim MaxIndex as Integer
192 If Ubound(DialogModel.lstTables.StringItemList())
> -
1 Then
193 FieldNames() = oColumns.GetElementNames()
194 MaxIndex = Ubound(FieldNames())
195 If MaxIndex
<> -
1 Then
196 Dim ResultFieldNames(MaxIndex)
197 ReDim ImgFieldNames(MaxIndex)
199 For n =
0 To MaxIndex
200 oField = oColumns.GetByName(FieldNames(n))
202 If GetIndexInMultiArray(WidthList(), iType,
0)
<> -
1 Then
203 ResultFieldNames(m) = FieldNames(n)
206 If GetIndexInMultiArray(ImgWidthList(), iType,
0)
<> -
1 Then
207 ImgFieldNames(s) = FieldNames(n)
212 Redim Preserve ImgFieldNames(s-
1)
213 bEnableBinaryOptionGroup = True
215 bEnableBinaryOptionGroup = False
217 If (DialogModel.optBinariesasGraphics.State =
1) And (s
<> 0) Then
218 ResultFieldNames() = AddListToList(ResultFieldNames(), ImgFieldNames())
220 Redim Preserve ResultFieldNames(m-
1)
222 FieldNames() = ResultFieldNames()
223 DialogModel.lstFields.StringItemList = FieldNames()
224 InitializeListboxProcedures(DialogModel, DialogModel.lstFields, DialogModel.lstSelFields)
226 GetSpecificFieldNames = MaxIndex
228 GetSpecificFieldNames = -
1
234 If oDrawPage.Forms.Count =
0 Then
235 oDBForm = oDocument.CreateInstance(
"com.sun.star.form.component.Form
")
236 oDrawpage.Forms.InsertByIndex (
0, oDBForm)
238 oDBForm = oDrawPage.Forms.GetByIndex(
0)
240 oDBForm.Name =
"Standard
"
241 oDBForm.DataSourceName = sDBName
242 oDBForm.Command = TableName
243 oDBForm.CommandType = CurCommandType
247 Sub AddOrRemoveBinaryFieldsToWidthList()
249 Dim MaxIndex as Integer
250 Dim OldMaxIndex as Integer
255 On Local Error GoTo WIZARDERROR
257 If DialogModel.optBinariesasGraphics.State =
1 Then
258 OldMaxIndex = Ubound(WidthList(),
1)
259 If OldMaxIndex =
15 Then
260 MaxIndex = Ubound(WidthList(),
1) + Ubound(ImgWidthList(),
1) +
1
261 ReDim Preserve WidthList(MaxIndex,
4)
263 For n = OldMaxIndex +
1 To MaxIndex
265 WidthList(n,m) = ImgWidthList(s,m)
269 MergeList(DialogModel.lstFields, ImgFieldNames())
272 ReDim Preserve WidthList(
15,
4)
273 RemoveListItems(DialogModel.lstFields(), DialogModel.lstSelFields(), ImgFieldNames())
275 DialogModel.lstSelFields.Tag = True
277 If Err
<> 0 Then
278 Msgbox(sMsgErrMsg,
16, GetProductName())
285 Function CreateCommandTypeList()
286 Dim MaxTableIndex as Integer
287 Dim MaxQueryIndex as Integer
288 Dim MaxIndex as Integer
291 MaxTableIndex = Ubound(TableNames()
292 MaxQueryIndex = Ubound(QueryNames()
293 MaxIndex = MaxTableIndex + MaxQueryIndex +
1
294 If MaxIndex
> -
1 Then
295 Dim LocCommandTypes(MaxIndex) as Integer
296 For i =
0 To MaxTableIndex
297 LocCommandTypes(i) = com.sun.star.sdb.CommandType.TABLE
300 For i =
0 To MaxQueryIndex
301 LocCommandTypes(a) = com.sun.star.sdb.CommandType.QUERY
305 CreateCommandTypeList() = LocCommandTypes()
309 Sub GetCurrentMetaValues(Index as Integer)
310 CurFieldType = FieldMetaValues(Index,
0)
311 CurFieldLength = FieldMetaValues(Index,
1)
312 CurControlType = FieldMetaValues(Index,
2)
313 CurControlName = FieldMetaValues(Index,
3)
314 CurFormatKey = FieldMetaValues(Index,
4)
315 CurDefaultValue = FieldMetaValues(Index,
5)
316 CurIsCurrency = FieldMetaValues(Index,
6)
317 CurScale = FieldMetaValues(Index,
7)
318 CurHelpText = FieldMetaValues(Index,
8)
319 CurFieldName = FieldNames(Index)
323 Function AssignFieldLength(FieldLength as Long) as Integer
324 If FieldLength
>=
65535 Then
325 AssignFieldLength() = -
1
327 AssignFieldLength() = FieldLength