1*cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?> 2*cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3*cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="DBMeta" script:language="StarBasic">REM ***** BASIC ***** 4*cdf0e10cSrcweirOption Explicit 5*cdf0e10cSrcweir 6*cdf0e10cSrcweir 7*cdf0e10cSrcweirPublic iCommandTypes() as Integer 8*cdf0e10cSrcweirPublic CurCommandType as Integer 9*cdf0e10cSrcweirPublic oDataSource as Object 10*cdf0e10cSrcweirPublic bEnableBinaryOptionGroup as Boolean 11*cdf0e10cSrcweir'Public bSelectContent as Boolean 12*cdf0e10cSrcweir 13*cdf0e10cSrcweir 14*cdf0e10cSrcweirFunction GetDatabaseNames(baddFirstListItem as Boolean) 15*cdf0e10cSrcweirDim sDatabaseList() 16*cdf0e10cSrcweir If oDBContext.HasElements Then 17*cdf0e10cSrcweir Dim LocDBList() as String 18*cdf0e10cSrcweir Dim MaxIndex as Integer 19*cdf0e10cSrcweir Dim i as Integer 20*cdf0e10cSrcweir LocDBList = oDBContext.ElementNames() 21*cdf0e10cSrcweir MaxIndex = Ubound(LocDBList()) 22*cdf0e10cSrcweir If baddfirstListItem Then 23*cdf0e10cSrcweir ReDim Preserve sDatabaseList(MaxIndex + 1) 24*cdf0e10cSrcweir sDatabaseList(0) = sSelectDatasource 25*cdf0e10cSrcweir a = 1 26*cdf0e10cSrcweir Else 27*cdf0e10cSrcweir ReDim Preserve sDatabaseList(MaxIndex) 28*cdf0e10cSrcweir a = 0 29*cdf0e10cSrcweir End If 30*cdf0e10cSrcweir For i = 0 To MaxIndex 31*cdf0e10cSrcweir sDatabaseList(a) = oDBContext.ElementNames(i) 32*cdf0e10cSrcweir a = a + 1 33*cdf0e10cSrcweir Next i 34*cdf0e10cSrcweir End If 35*cdf0e10cSrcweir GetDatabaseNames() = sDatabaseList() 36*cdf0e10cSrcweirEnd Function 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir 39*cdf0e10cSrcweirSub GetSelectedDBMetaData(sDBName as String) 40*cdf0e10cSrcweirDim OldsDBname as String 41*cdf0e10cSrcweirDim DBIndex as Integer 42*cdf0e10cSrcweirDim LocList() as String 43*cdf0e10cSrcweir' If bStartUp Then 44*cdf0e10cSrcweir' bStartUp = false 45*cdf0e10cSrcweir' Exit Sub 46*cdf0e10cSrcweir' End Sub 47*cdf0e10cSrcweir ToggleDatabasePage(False) 48*cdf0e10cSrcweir With DialogModel 49*cdf0e10cSrcweir If GetConnection(sDBName) Then 50*cdf0e10cSrcweir If GetDBMetaData() Then 51*cdf0e10cSrcweir LocList() = AddListToList(Array(sSelectDBTable), TableNames()) 52*cdf0e10cSrcweir .lstTables.StringItemList() = AddListToList(LocList(), QueryNames()) 53*cdf0e10cSrcweir' bSelectContent = True 54*cdf0e10cSrcweir .lstTables.SelectedItems() = Array(0) 55*cdf0e10cSrcweir iCommandTypes() = CreateCommandTypeList() 56*cdf0e10cSrcweir EmptyFieldsListboxes() 57*cdf0e10cSrcweir End If 58*cdf0e10cSrcweir End If 59*cdf0e10cSrcweir bEnableBinaryOptionGroup = False 60*cdf0e10cSrcweir .lstTables.Enabled = True 61*cdf0e10cSrcweir .lblTables.Enabled = True 62*cdf0e10cSrcweir' Else 63*cdf0e10cSrcweir' DialogModel.lstTables.StringItemList = Array(sSelectDBTable) 64*cdf0e10cSrcweir' EmptyFieldsListboxes() 65*cdf0e10cSrcweir' End If 66*cdf0e10cSrcweir ToggleDatabasePage(True) 67*cdf0e10cSrcweir End With 68*cdf0e10cSrcweirEnd Sub 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir 71*cdf0e10cSrcweirFunction GetConnection(sDBName as String) 72*cdf0e10cSrcweirDim oInteractionHandler as Object 73*cdf0e10cSrcweirDim bExitLoop as Boolean 74*cdf0e10cSrcweirDim bGetConnection as Boolean 75*cdf0e10cSrcweirDim iMsg as Integer 76*cdf0e10cSrcweirDim Nulllist() 77*cdf0e10cSrcweir If Not IsNull(oDBConnection) Then 78*cdf0e10cSrcweir oDBConnection.Dispose() 79*cdf0e10cSrcweir End If 80*cdf0e10cSrcweir oDataSource = oDBContext.GetByName(sDBName) 81*cdf0e10cSrcweir' If Not oDBContext.hasbyName(sDBName) Then 82*cdf0e10cSrcweir' GetConnection() = False 83*cdf0e10cSrcweir' Exit Function 84*cdf0e10cSrcweir' End If 85*cdf0e10cSrcweir If Not oDataSource.IsPasswordRequired Then 86*cdf0e10cSrcweir oDBConnection = oDBContext.GetByName(sDBName).GetConnection("","") 87*cdf0e10cSrcweir GetConnection() = True 88*cdf0e10cSrcweir Else 89*cdf0e10cSrcweir oInteractionHandler = createUnoService("com.sun.star.task.InteractionHandler") 90*cdf0e10cSrcweir oDataSource = oDBContext.GetByName(sDBName) 91*cdf0e10cSrcweir On Local Error Goto NOCONNECTION 92*cdf0e10cSrcweir Do 93*cdf0e10cSrcweir bExitLoop = True 94*cdf0e10cSrcweir oDBConnection = oDataSource.ConnectWithCompletion(oInteractionHandler) 95*cdf0e10cSrcweir NOCONNECTION: 96*cdf0e10cSrcweir bGetConnection = Err = 0 97*cdf0e10cSrcweir If bGetConnection Then 98*cdf0e10cSrcweir bGetConnection = Not IsNull(oDBConnection) 99*cdf0e10cSrcweir If Not bGetConnection Then 100*cdf0e10cSrcweir Exit Do 101*cdf0e10cSrcweir End If 102*cdf0e10cSrcweir End If 103*cdf0e10cSrcweir If Not bGetConnection Then 104*cdf0e10cSrcweir iMsg = Msgbox (sMsgNoConnection,32 + 2, sMsgWizardName) 105*cdf0e10cSrcweir bExitLoop = iMsg = SBCANCEL 106*cdf0e10cSrcweir Resume CLERROR 107*cdf0e10cSrcweir CLERROR: 108*cdf0e10cSrcweir End If 109*cdf0e10cSrcweir Loop Until bExitLoop 110*cdf0e10cSrcweir On Local Error Goto 0 111*cdf0e10cSrcweir If Not bGetConnection Then 112*cdf0e10cSrcweir DialogModel.lstTables.StringItemList() = Array(sSelectDBTable) 113*cdf0e10cSrcweir DialogModel.lstFields.StringItemList() = NullList() 114*cdf0e10cSrcweir DialogModel.lstSelFields.StringItemList() = NullList() 115*cdf0e10cSrcweir End If 116*cdf0e10cSrcweir GetConnection() = bGetConnection 117*cdf0e10cSrcweir End If 118*cdf0e10cSrcweirEnd Function 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir 121*cdf0e10cSrcweirFunction GetDBMetaData() 122*cdf0e10cSrcweir If oDBContext.HasElements Then 123*cdf0e10cSrcweir Tablenames() = oDBConnection.Tables.ElementNames() 124*cdf0e10cSrcweir Querynames() = oDBConnection.Queries.ElementNames() 125*cdf0e10cSrcweir GetDBMetaData = True 126*cdf0e10cSrcweir Else 127*cdf0e10cSrcweir MsgBox(sMsgErrNoDatabase, 64, sMsgWizardName) 128*cdf0e10cSrcweir GetDBMetaData = False 129*cdf0e10cSrcweir End If 130*cdf0e10cSrcweirEnd Function 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir 133*cdf0e10cSrcweirSub GetTableMetaData() 134*cdf0e10cSrcweirDim iType as Long 135*cdf0e10cSrcweirDim m as Integer 136*cdf0e10cSrcweirDim Found as Boolean 137*cdf0e10cSrcweirDim i as Integer 138*cdf0e10cSrcweirDim sFieldName as String 139*cdf0e10cSrcweirDim n as Integer 140*cdf0e10cSrcweirDim WidthIndex as Integer 141*cdf0e10cSrcweirDim oField as Object 142*cdf0e10cSrcweir MaxIndex = Ubound(DialogModel.lstSelFields.StringItemList()) 143*cdf0e10cSrcweir Dim ColumnMap(MaxIndex)as Integer 144*cdf0e10cSrcweir FieldNames() = DialogModel.lstSelFields.StringItemList() 145*cdf0e10cSrcweir ' Build a structure which maps the position of a selected field (within the selection) to the the column position within 146*cdf0e10cSrcweir ' the table. So we ensure that the controls are placed in the same order the according fields are selected. 147*cdf0e10cSrcweir For i = 0 To Ubound(FieldNames()) 148*cdf0e10cSrcweir sFieldName = FieldNames(i) 149*cdf0e10cSrcweir Found = False 150*cdf0e10cSrcweir n = 0 151*cdf0e10cSrcweir While (n< MaxIndex And (Not Found)) 152*cdf0e10cSrcweir If (FieldNames(n) = sFieldName) Then 153*cdf0e10cSrcweir Found = True 154*cdf0e10cSrcweir ColumnMap(n) = i 155*cdf0e10cSrcweir End If 156*cdf0e10cSrcweir n = n + 1 157*cdf0e10cSrcweir Wend 158*cdf0e10cSrcweir Next i 159*cdf0e10cSrcweir For n = 0 to MaxIndex 160*cdf0e10cSrcweir sFieldname = FieldNames(n) 161*cdf0e10cSrcweir oField = oColumns.GetByName(sFieldName) 162*cdf0e10cSrcweir iType = oField.Type 163*cdf0e10cSrcweir FieldMetaValues(n,0) = oField.Type 164*cdf0e10cSrcweir FieldMetaValues(n,1) = AssignFieldLength(oField.Precision) 165*cdf0e10cSrcweir FieldMetaValues(n,2) = GetValueoutofList(iType, WidthList(),1, WidthIndex) 166*cdf0e10cSrcweir FieldMetaValues(n,3) = WidthList(WidthIndex,3) 167*cdf0e10cSrcweir FieldMetaValues(n,4) = oField.FormatKey 168*cdf0e10cSrcweir FieldMetaValues(n,5) = oField.DefaultValue 169*cdf0e10cSrcweir FieldMetaValues(n,6) = oField.IsCurrency 170*cdf0e10cSrcweir FieldMetaValues(n,7) = oField.Scale 171*cdf0e10cSrcweir' If oField.Description <> "" Then 172*cdf0e10cSrcweir'' Todo: What's wrong with this line? 173*cdf0e10cSrcweir' Msgbox oField.Helptext 174*cdf0e10cSrcweir' End If 175*cdf0e10cSrcweir FieldMetaValues(n,8) = oField.Description 176*cdf0e10cSrcweir Next 177*cdf0e10cSrcweir ReDim oDBShapeList(MaxIndex) as Object 178*cdf0e10cSrcweir ReDim oTCShapeList(MaxIndex) as Object 179*cdf0e10cSrcweir ReDim oDBModelList(MaxIndex) as Object 180*cdf0e10cSrcweir ReDim oGroupShapeList(MaxIndex) as Object 181*cdf0e10cSrcweirEnd Sub 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir 184*cdf0e10cSrcweirFunction GetSpecificFieldNames() as Integer 185*cdf0e10cSrcweirDim n as Integer 186*cdf0e10cSrcweirDim m as Integer 187*cdf0e10cSrcweirDim s as Integer 188*cdf0e10cSrcweirDim iType as Integer 189*cdf0e10cSrcweirDim oField as Object 190*cdf0e10cSrcweirDim MaxIndex as Integer 191*cdf0e10cSrcweirDim EmptyList() 192*cdf0e10cSrcweir If Ubound(DialogModel.lstTables.StringItemList()) > -1 Then 193*cdf0e10cSrcweir FieldNames() = oColumns.GetElementNames() 194*cdf0e10cSrcweir MaxIndex = Ubound(FieldNames()) 195*cdf0e10cSrcweir If MaxIndex <> -1 Then 196*cdf0e10cSrcweir Dim ResultFieldNames(MaxIndex) 197*cdf0e10cSrcweir ReDim ImgFieldNames(MaxIndex) 198*cdf0e10cSrcweir m = 0 199*cdf0e10cSrcweir For n = 0 To MaxIndex 200*cdf0e10cSrcweir oField = oColumns.GetByName(FieldNames(n)) 201*cdf0e10cSrcweir iType = oField.Type 202*cdf0e10cSrcweir If GetIndexInMultiArray(WidthList(), iType, 0) <> -1 Then 203*cdf0e10cSrcweir ResultFieldNames(m) = FieldNames(n) 204*cdf0e10cSrcweir m = m + 1 205*cdf0e10cSrcweir End If 206*cdf0e10cSrcweir If GetIndexInMultiArray(ImgWidthList(), iType, 0) <> -1 Then 207*cdf0e10cSrcweir ImgFieldNames(s) = FieldNames(n) 208*cdf0e10cSrcweir s = s + 1 209*cdf0e10cSrcweir End If 210*cdf0e10cSrcweir Next n 211*cdf0e10cSrcweir If s <> 0 Then 212*cdf0e10cSrcweir Redim Preserve ImgFieldNames(s-1) 213*cdf0e10cSrcweir bEnableBinaryOptionGroup = True 214*cdf0e10cSrcweir Else 215*cdf0e10cSrcweir bEnableBinaryOptionGroup = False 216*cdf0e10cSrcweir End If 217*cdf0e10cSrcweir If (DialogModel.optBinariesasGraphics.State = 1) And (s <> 0) Then 218*cdf0e10cSrcweir ResultFieldNames() = AddListToList(ResultFieldNames(), ImgFieldNames()) 219*cdf0e10cSrcweir Else 220*cdf0e10cSrcweir Redim Preserve ResultFieldNames(m-1) 221*cdf0e10cSrcweir End If 222*cdf0e10cSrcweir FieldNames() = ResultFieldNames() 223*cdf0e10cSrcweir DialogModel.lstFields.StringItemList = FieldNames() 224*cdf0e10cSrcweir InitializeListboxProcedures(DialogModel, DialogModel.lstFields, DialogModel.lstSelFields) 225*cdf0e10cSrcweir End If 226*cdf0e10cSrcweir GetSpecificFieldNames = MaxIndex 227*cdf0e10cSrcweir Else 228*cdf0e10cSrcweir GetSpecificFieldNames = -1 229*cdf0e10cSrcweir End If 230*cdf0e10cSrcweirEnd Function 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir 233*cdf0e10cSrcweirSub CreateDBForm() 234*cdf0e10cSrcweir If oDrawPage.Forms.Count = 0 Then 235*cdf0e10cSrcweir oDBForm = oDocument.CreateInstance("com.sun.star.form.component.Form") 236*cdf0e10cSrcweir oDrawpage.Forms.InsertByIndex (0, oDBForm) 237*cdf0e10cSrcweir Else 238*cdf0e10cSrcweir oDBForm = oDrawPage.Forms.GetByIndex(0) 239*cdf0e10cSrcweir End If 240*cdf0e10cSrcweir oDBForm.Name = "Standard" 241*cdf0e10cSrcweir oDBForm.DataSourceName = sDBName 242*cdf0e10cSrcweir oDBForm.Command = TableName 243*cdf0e10cSrcweir oDBForm.CommandType = CurCommandType 244*cdf0e10cSrcweirEnd Sub 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir 247*cdf0e10cSrcweirSub AddOrRemoveBinaryFieldsToWidthList() 248*cdf0e10cSrcweirDim LocWidthList() 249*cdf0e10cSrcweirDim MaxIndex as Integer 250*cdf0e10cSrcweirDim OldMaxIndex as Integer 251*cdf0e10cSrcweirDim s as Integer 252*cdf0e10cSrcweirDim n as Integer 253*cdf0e10cSrcweirDim m as Integer 254*cdf0e10cSrcweir If Not bDebug Then 255*cdf0e10cSrcweir On Local Error GoTo WIZARDERROR 256*cdf0e10cSrcweir End If 257*cdf0e10cSrcweir If DialogModel.optBinariesasGraphics.State = 1 Then 258*cdf0e10cSrcweir OldMaxIndex = Ubound(WidthList(),1) 259*cdf0e10cSrcweir If OldMaxIndex = 15 Then 260*cdf0e10cSrcweir MaxIndex = Ubound(WidthList(),1) + Ubound(ImgWidthList(),1) + 1 261*cdf0e10cSrcweir ReDim Preserve WidthList(MaxIndex,4) 262*cdf0e10cSrcweir s = 0 263*cdf0e10cSrcweir For n = OldMaxIndex + 1 To MaxIndex 264*cdf0e10cSrcweir For m = 0 To 3 265*cdf0e10cSrcweir WidthList(n,m) = ImgWidthList(s,m) 266*cdf0e10cSrcweir Next m 267*cdf0e10cSrcweir s = s + 1 268*cdf0e10cSrcweir Next n 269*cdf0e10cSrcweir MergeList(DialogModel.lstFields, ImgFieldNames()) 270*cdf0e10cSrcweir End If 271*cdf0e10cSrcweir Else 272*cdf0e10cSrcweir ReDim Preserve WidthList(15, 4) 273*cdf0e10cSrcweir RemoveListItems(DialogModel.lstFields(), DialogModel.lstSelFields(), ImgFieldNames()) 274*cdf0e10cSrcweir End If 275*cdf0e10cSrcweir DialogModel.lstSelFields.Tag = True 276*cdf0e10cSrcweirWIZARDERROR: 277*cdf0e10cSrcweir If Err <> 0 Then 278*cdf0e10cSrcweir Msgbox(sMsgErrMsg, 16, GetProductName()) 279*cdf0e10cSrcweir Resume LOCERROR 280*cdf0e10cSrcweir LOCERROR: 281*cdf0e10cSrcweir End If 282*cdf0e10cSrcweirEnd Sub 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir 285*cdf0e10cSrcweirFunction CreateCommandTypeList() 286*cdf0e10cSrcweirDim MaxTableIndex as Integer 287*cdf0e10cSrcweirDim MaxQueryIndex as Integer 288*cdf0e10cSrcweirDim MaxIndex as Integer 289*cdf0e10cSrcweirDim i as Integer 290*cdf0e10cSrcweirDim a as Integer 291*cdf0e10cSrcweir MaxTableIndex = Ubound(TableNames() 292*cdf0e10cSrcweir MaxQueryIndex = Ubound(QueryNames() 293*cdf0e10cSrcweir MaxIndex = MaxTableIndex + MaxQueryIndex + 1 294*cdf0e10cSrcweir If MaxIndex > -1 Then 295*cdf0e10cSrcweir Dim LocCommandTypes(MaxIndex) as Integer 296*cdf0e10cSrcweir For i = 0 To MaxTableIndex 297*cdf0e10cSrcweir LocCommandTypes(i) = com.sun.star.sdb.CommandType.TABLE 298*cdf0e10cSrcweir Next i 299*cdf0e10cSrcweir a = i 300*cdf0e10cSrcweir For i = 0 To MaxQueryIndex 301*cdf0e10cSrcweir LocCommandTypes(a) = com.sun.star.sdb.CommandType.QUERY 302*cdf0e10cSrcweir a = a + 1 303*cdf0e10cSrcweir Next i 304*cdf0e10cSrcweir End If 305*cdf0e10cSrcweir CreateCommandTypeList() = LocCommandTypes() 306*cdf0e10cSrcweirEnd Function 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir 309*cdf0e10cSrcweirSub GetCurrentMetaValues(Index as Integer) 310*cdf0e10cSrcweir CurFieldType = FieldMetaValues(Index,0) 311*cdf0e10cSrcweir CurFieldLength = FieldMetaValues(Index,1) 312*cdf0e10cSrcweir CurControlType = FieldMetaValues(Index,2) 313*cdf0e10cSrcweir CurControlName = FieldMetaValues(Index,3) 314*cdf0e10cSrcweir CurFormatKey = FieldMetaValues(Index,4) 315*cdf0e10cSrcweir CurDefaultValue = FieldMetaValues(Index,5) 316*cdf0e10cSrcweir CurIsCurrency = FieldMetaValues(Index,6) 317*cdf0e10cSrcweir CurScale = FieldMetaValues(Index,7) 318*cdf0e10cSrcweir CurHelpText = FieldMetaValues(Index,8) 319*cdf0e10cSrcweir CurFieldName = FieldNames(Index) 320*cdf0e10cSrcweirEnd Sub 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir 323*cdf0e10cSrcweirFunction AssignFieldLength(FieldLength as Long) as Integer 324*cdf0e10cSrcweir If FieldLength >= 65535 Then 325*cdf0e10cSrcweir AssignFieldLength() = -1 326*cdf0e10cSrcweir Else 327*cdf0e10cSrcweir AssignFieldLength() = FieldLength 328*cdf0e10cSrcweir End If 329*cdf0e10cSrcweirEnd Function 330*cdf0e10cSrcweir</script:module>