gambas-source-code/main/lib/db/gb.db/.src/Connections.class
Benoît Minisini 25b8edfd44 [DEVELOPMENT ENVIRONMENT]
* NEW: Support for the help comments integrated into the *.info files by 
  the compiler.
* NEW: Use the help comments stored in libraries and display them in them
  help tooltips.
* BUG: Remove duplicates in the automatic completion list.
* BUG: The symbol syntax displayed in the help now correctly follows the
  "Keywords in uppercase" setting.
* NEW: Class help comments are now help comments located at the beginning
  of the source file that starts with three quotes and a space: `''' `.

[COMPILER]
* NEW: Support for help comments on public symbols. They are automatically 
  integrated into the *.info information files.


git-svn-id: svn://localhost/gambas/trunk@5311 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-11-10 00:19:53 +00:00

123 lines
2.3 KiB
Text

' Gambas class file
Export
Class Desktop
Static Property Read Key As String
Static Private $cConn As New Collection
Static Private $aConn As String[]
Static Private $sKey As String
Static Public Sub Exist(Name As String) As Boolean
If $cConn.Exist(Name) Or If Exist("../.connection" &/ Name & ".connection") Then Return True
End
Static Private Sub Init()
Dim sFile As String
If $aConn Then Return
$aConn = New String[]
For Each sFile In Dir("../.connection", "*.connection")
$aConn.Add(File.BaseName(sFile))
Next
End
Static Public Sub _get(Name As String) As Connection
Dim sPath As String
Dim hFile As File
Dim hConn As Connection
Dim sLine As String
Dim aLine As String[]
Dim bPassword As Boolean
Init()
If $cConn.Exist(Name) Then Return $cConn[Name]
sPath = "../.connection" &/ Name & ".connection"
If Not Exist(sPath) Then Return
hConn = New Connection
hFile = Open sPath
While Not Eof(hFile)
Line Input #hFile, sLine
If Left(sLine) = "#" Then Continue
If Left(sLine) = "[" Then Continue
aLine = Scan(sLine, "*=*")
If aLine.Count < 2 Then Continue
Select Case LCase(aLine[0])
Case "type"
hConn.Type = UnQuote(aLine[1])
Case "path", "host"
hConn.Host = UnQuote(aLine[1])
Case "port"
hConn.Port = UnQuote(aLine[1])
Case "database"
hConn.Name = UnQuote(aLine[1])
Case "ignorecharset"
hConn.IgnoreCharset = LCase(aLine[1]) = "true"
Case "user"
hConn.User = UnQuote(aLine[1])
Case "rememberpassword"
bPassword = LCase(aLine[1]) = "true"
End Select
Wend
Close #hFile
If bPassword Then
Try hConn.Password = Desktop.Passwords[Application.Name &/ Name]
If Error Then
Error "gb.db: warning: unable to retrieve connection password: "; Application.Name &/ Name & ": "; Error.Text
Endif
Endif
$cConn[Name] = hConn
Return hConn
End
Static Public Sub _next() As Connection
Init()
If Not Enum.Index Then Enum.Index = 0
If Enum.Index >= $aConn.Count Then
$sKey = ""
Enum.Stop
Else
Inc Enum.Index
$sKey = $aConn[Enum.Index - 1]
Return _get($sKey)
Endif
End
Static Private Function Key_Read() As String
Return $sKey
End