User Tools

Site Tools


k22:k22.4:k22.4.4:start

22.4.4 Database class (gb.db)

The class represents an (existing) database. All properties can only be read.

22.4.4.1 Properties

The Database class has three properties:

PropertyData typeDescription
ConnectionConnectionReturns the parent DB connection object, whose properties and methods you can then use.
NameStringReturns the name of the database.
SystemBooleanReturns whether the database is a system database or not. The property returns True if the database is a system database.

Table 22.4.4.1.1 : Properties of the Database class

System databases are used to operate a DB server (PostgreSQL, MySQL) or when using the DB library in SQLite. The database `mysql ` is used in MySQL, for example, to manage all log system tables.

22.4.4.2 Methods

The Database.Delete( ) method deletes a database.

22.4.4.3 Example

The following source code snippet shows the use of all properties and the single method of the Database class:

    Dim hConnection As Connection
    Dim hDataBase As Database
    Dim sMessage As String
 
    For Each hDataBase In DBCS.DBConnection.Databases
 
      hConnection = hDataBase.Connection
 
      Print "Connection Host: "; hConnection.Host
      Print "DBName: "; hDataBase.Name 
      If hDataBase.System Then 
         Print "The database is a system DB"
      Else
         Print "The database is not a system DB"
      Endif
 
'-- Attention: The following instructions require attention!
'-- When a database is deleted, all tables with the data they contain are also deleted!
'-- Be sure to create a (complete) database backup (dump) beforehand.
 
      If hDataBase.Name = "contacts.sqlite" Then
         sMessage = "<center><h4><font color='red'>Achtung!<br>Should the database '"
         sMessage &= hDataBase.Name
         sMessage &= "' be completely deleted?</font color='red'></center></h3>"
         If Message.Question(sMessage, "Yes", "No - no way!") = 1 Then
            hDBDataBase.Delete()
         Endif
      Endif
 
    Next

The following output is produced in the console of the IDE. A delete query is then generated:

Connection Host: /home/hans/.local/share/gambasbook/dbplayground/data/databases
DBName: contacts.sqlite
The database is not a system DB

Remove

Figure 22.4.4.3.1: Query to delete a selected database

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.
k22/k22.4/k22.4.4/start.txt · Last modified: by 127.0.0.1