ບໍລິການ SFDatabases.Database

ບໍລິການ Database ຊ່ວຍໃຫ້ສາມາດເຂົ້າເຖິງຖານຂໍ້ມູນ ທັງແບບທີ່ຝັງຢູ່ ຫຼື ແບບທີ່ຖືກອະທິບາຍໃນເອກະສານ Base. ບໍລິການນີ້ສະໜອງວິທີການຕ່າງໆເພື່ອ:

ແຕ່ລະອິນສະແຕນ (instance) ຂອງບໍລິການ Database ຈະສະແດງເຖິງຖານຂໍ້ມູນໜຶ່ງດຽວ ແລະ ຊ່ວຍໃຫ້ເຂົ້າເຖິງຕາຕະລາງ, ຄຳສັ່ງສອບຖາມ ແລະ ຂໍ້ມູນຂອງມັນ.

ບໍລິການນີ້ບໍ່ໄດ້ໃຫ້ການເຂົ້າເຖິງຟອມ ຫຼື ລາຍງານໃນເອກະສານ Base ທີ່ມີຖານຂໍ້ມູນນັ້ນຢູ່. ເພື່ອເຂົ້າເຖິງຟອມໃນເອກະສານ Base, ໃຫ້ອ້າງອີງເຖິງວິທີການ FormDocuments ຂອງບໍລິການ Base.

note

ການແລກປ່ຽນຂໍ້ມູນທັງໝົດລະຫວ່າງບໍລິການນີ້ ແລະ ຖານຂໍ້ມູນແມ່ນເຮັດຜ່ານ SQL ເທົ່ານັ້ນ.


ຄຳສັ່ງ SQL ອາດຈະຖືກເອີ້ນໃຊ້ໃນໂໝດ ໂດຍກົງ (direct) ຫຼື ໂດຍອ້ອມ (indirect). ໃນໂໝດໂດຍກົງ, ຄຳສັ່ງຈະຖືກສົ່ງໄປຫາເຄື່ອງຈັກຖານຂໍ້ມູນໂດຍກົງ ໂດຍບໍ່ມີການກວດສອບໄວຍາກອນ ຫຼື ການກວດທານໃດໆ.

ອິນເຕີເຟສທີ່ມີໃຫ້ ລວມມີລາຍການຕາຕະລາງ ແລະ ຄຳສັ່ງສອບຖາມແບບງ່າຍໆ, ລວມທັງການເຂົ້າເຖິງຂໍ້ມູນຖານຂໍ້ມູນ.

tip

ເພື່ອເຮັດໃຫ້ຄຳສັ່ງ SQL ອ່ານງ່າຍຂຶ້ນ, ທ່ານສາມາດໃຊ້ວົງເລັບຫຼ່ຽມ "[ ]" ເພື່ອຄອບຊື່ຕາຕະລາງ, ຄຳສັ່ງສອບຖາມ ແລະ ຟິວ (fields) ແທນການໃຊ້ຕົວອັກສອນອື່ນໆທີ່ອາດຈະໃຊ້ໄດ້ສະເພາະກັບບາງລະບົບຈັດການຖານຂໍ້ມູນ (RDBMS). ແຕ່ຕ້ອງລະວັງວ່າຕົວອັກສອນຄອບຊື່ເຫຼົ່ານີ້ແມ່ນຈຳເປັນຕ້ອງມີໃນບໍລິບົດນີ້.


ການຈັດການທຸລະກຳ (Transaction handling)

ໂດຍເລີ່ມຕົ້ນ, ຖານຂໍ້ມູນຈະຈັດການທຸລະກຳໃນໂໝດ auto-commit, ໝາຍຄວາມວ່າຈະມີການ commit ຫຼັງຈາກທຸກໆຄຳສັ່ງ SQL.

ໃຊ້ວິທີການ SetTransactionMode ເພື່ອປ່ຽນພຶດຕິກຳເລີ່ມຕົ້ນ, ເຊິ່ງຈະຊ່ວຍໃຫ້ສາມາດ commit ແລະ rollback ດ້ວຍຕົນເອງໄດ້.

ວິທີການ Commit ແລະ Rollback ແມ່ນໃຊ້ເພື່ອບົ່ງບອກຂອບເຂດຂອງທຸລະກຳ.

ໃນ LibreOffice, ມີຮູບແບບການແຍກທຸລະກຳ (transaction isolation modes) ຫ້າປະເພດ, ຕາມທີ່ກຳນົດໃນກຸ່ມຄ່າຄົງທີ່ com.sun.star.sdbc.TransactionIsolation:

ຄ່າຄົງທີ່

ຄ່າ

ຄວາມໝາຍ

NONE

0

ການຈັດການທຸລະກຳຖືກປິດໃຊ້ງານ ແລະ ຖານຂໍ້ມູນຖືກຕັ້ງເປັນໂໝດ auto-commit ເລີ່ມຕົ້ນ.

READ_UNCOMMITTED

1

ອາດຈະເກີດ Dirty reads, non-repeatable reads ແລະ phantom reads.

ຖ້າແຖວໃດຖືກປ່ຽນແປງໂດຍທຸລະກຳໜຶ່ງ, ທຸລະກຳອື່ນຈະສາມາດອ່ານການປ່ຽນແປງເຫຼົ່ານີ້ໄດ້ ເຖິງແມ່ນວ່າມັນຍັງບໍ່ທັນຖືກ commit ກໍຕາມ.

READ_COMMITTED

2

ປ້ອງກັນ Dirty reads, ແຕ່ຍັງອາດເກີດ non-repeatable reads ແລະ phantom reads.

ລະດັບນີ້ປ້ອງກັນການອ່ານແຖວທີ່ມີການປ່ຽນແປງແຕ່ຍັງບໍ່ທັນໄດ້ commit.

REPEATABLE_READ

4

ປ້ອງກັນ Dirty reads ແລະ non-repeatable reads, ແຕ່ຍັງອາດເກີດ phantom reads.

ນອກຈາກການປ້ອງກັນບໍ່ໃຫ້ອ່ານຂໍ້ມູນທີ່ຍັງບໍ່ທັນ commit ແລ້ວ, ມັນຍັງປ້ອງກັນບໍ່ໃຫ້ການອ່ານຂໍ້ມູນສອງຄັ້ງໃນທຸລະກຳດຽວກັນໃຫ້ຜົນລັບທີ່ແຕກຕ່າງກັນ.

SERIALIZABLE

8

ປ້ອງກັນ Dirty reads, non-repeatable reads ແລະ phantom reads.

ນອກຈາກຂໍ້ກຳນົດຂອງລະດັບກ່ອນໜ້າແລ້ວ, ມັນຍັງຮັບປະກັນວ່າຊຸດຂອງຂໍ້ມູນ (records) ທີ່ກົງກັບເງື່ອນໄຂ WHERE ຈະບໍ່ມີການປ່ຽນແປງພາຍໃນທຸລະກຳດຽວກັນ.


tip

ອ່ານໜ້າ Wikipedia ກ່ຽວກັບ Isolation in Database Systems ເພື່ອຮຽນຮູ້ເພີ່ມເຕີມກ່ຽວກັບຄວາມຖືກຕ້ອງຄົບຖ້ວນຂອງທຸລະກຳ.


ການຮຽກໃຊ້ບໍລິການ

ກ່ອນທີ່ຈະໃຊ້ບໍລິການ Database, ຫ້ອງສະໝຸດ ScriptForge ຈຳເປັນຕ້ອງຖືກໂຫຼດ ຫຼື ນຳເຂົ້າມາກ່ອນ:

note

• ມາໂຄຣ Basic ຕ້ອງມີການໂຫຼດຄັງສຳນວນ ScriptForge ໂດຍໃຊ້ຄຳສັ່ງດັ່ງນີ້:
GlobalScope.BasicLibraries.loadLibrary("ScriptForge")

• ສະຄຣິບ Python ຕ້ອງມີການນຳເຂົ້າຈາກໂມດູນ scriptforge:
from scriptforge import CreateScriptService


ໄວຍາກອນ:

ເພື່ອສ້າງອິນສະແຕນ (instance) ຂອງບໍລິການ Database, ທ່ານສາມາດໃຊ້ວິທີການ CreateScriptService:

CreateScriptService("SFDatabases.Database", [filename: str], [registrationname], [readonly], [user, [password]]): svc

note

ໃນໄວຍາກອນທີ່ອະທິບາຍຂ້າງເທິງ, ທ່ານສາມາດໃຊ້ທັງ "SFDatabases.Database" ຫຼື ພຽງແຕ່ "Database" ເປັນອາຄິວເມນທຳອິດຂອງວິທີການ CreateScriptService.


ພາຣາມິເຕີ:

filename: ຊື່ຂອງໄຟລ໌ Base. ຕ້ອງລະບຸໂດຍໃຊ້ຮູບແບບຂອງ SF_FileSystem.FileNaming.

registrationname: ຊື່ຂອງຖານຂໍ້ມູນທີ່ລົງທະບຽນໄວ້. ຖ້າມີການກຳນົດ filename ແລ້ວ, ບໍ່ຄວນໃຊ້ອາຄິວເມນນີ້.

ໃນທາງກົງກັນຂ້າມ, ຖ້າກຳນົດ registrationname ແລ້ວ, ພາລາມິເຕີ filename ກໍບໍ່ຄວນຖືກກຳນົດ.

readonly: ກຳນົດວ່າຈະເປີດຖານຂໍ້ມູນແບບອ່ານຢ່າງດຽວຫຼືບໍ່ (ຄ່າເລີ່ມຕົ້ນ = True).

user, password: ພາລາມິເຕີເພີ່ມເຕີມສຳລັບການເຊື່ອມຕໍ່ກັບເຊີບເວີຖານຂໍ້ມູນ.

ຕົວຢ່າງ:

ໃນ Basic

      GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
      Dim myDatabase as Object
      Set myDatabase = CreateScriptService("Database", "/home/user/Documents/myDB.odb")
      ' ເອີ້ນໃຊ້ຄຳສັ່ງສອບຖາມ, ຄຳສັ່ງ SQL, ...
      myDatabase.CloseDatabase()
    
ໃນ Python

      from scriptforge import CreateScriptService
      myDatabase = CreateScriptService("Database", "/home/user/Documents/myDB.odb")
      # ເອີ້ນໃຊ້ຄຳສັ່ງສອບຖາມ, ຄຳສັ່ງ SQL, ...
      myDatabase.CloseDatabase()
    

ການເຂົ້າເຖິງຖານຂໍ້ມູນດ້ວຍບໍລິການ UI

ນອກຈາກນັ້ນຍັງສາມາດເຂົ້າເຖິງຖານຂໍ້ມູນທີ່ກ່ຽວຂ້ອງກັບເອກະສານ Base ໂດຍໃຊ້ບໍລິການ ScriptForge.UI, ດັ່ງທີ່ສະແດງໃນຕົວຢ່າງຂ້າງລຸ່ມນີ້:

ໃນ Basic

      Dim myDoc As Object, myDatabase As Object, ui As Object
      Set ui = CreateScriptService("UI")
      Set myDoc = ui.OpenBaseDocument("/home/user/Documents/myDB.odb")
      ' ລະບຸຊື່ຜູ້ໃຊ້ ແລະ ລະຫັດຜ່ານຂ້າງລຸ່ມນີ້ ຖ້າຈຳເປັນ
      Set myDatabase = myDoc.GetDatabase()
      ' ເອີ້ນໃຊ້ຄຳສັ່ງສອບຖາມ, ຄຳສັ່ງ SQL, ...
      myDatabase.CloseDatabase()
      myDoc.CloseDocument()
    
ໃນ Python

      ui = CreateScriptService("UI")
      doc = ui.OpenBaseDocument("/home/user/Documents/myDB.odb")
      # ລະບຸຊື່ຜູ້ໃຊ້ ແລະ ລະຫັດຜ່ານຂ້າງລຸ່ມນີ້ ຖ້າຈຳເປັນ
      myDatabase = doc.GetDatabase()
      # ເອີ້ນໃຊ້ຄຳສັ່ງສອບຖາມ, ຄຳສັ່ງ SQL, ...
      myDatabase.CloseDatabase()
      doc.CloseDocument()
    
tip

ວິທີການ GetDatabase ທີ່ໃຊ້ໃນຕົວຢ່າງຂ້າງເທິງ ແມ່ນສ່ວນໜຶ່ງຂອງບໍລິການ Base ຂອງ ScriptForge.


ຄຸນສົມບັດ

ຊື່

ອ່ານຢ່າງດຽວ

ປະເພດ

ຄຳອະທິບາຍ

Queries

ແມ່ນ

ອາເຣຂອງສະຕຣິງ

ລາຍຊື່ຂອງຄຳສັ່ງສອບຖາມທີ່ເກັບໄວ້.

Tables

ແມ່ນ

ອາເຣຂອງສະຕຣິງ

ລາຍຊື່ຂອງຕາຕະລາງທີ່ເກັບໄວ້.

XConnection

ແມ່ນ

XConnection

ອັອບເຈັກ UNO ທີ່ສະແດງເຖິງການເຊື່ອມຕໍ່ຖານຂໍ້ມູນປັດຈຸບັນ.

XMetaData

ແມ່ນ

XDatabaseMetaData

ອັອບເຈັກ UNO ທີ່ສະແດງເຖິງເມຕາເດຕາ (metadata) ທີ່ອະທິບາຍຄຸນລັກສະນະຂອງລະບົບຖານຂໍ້ມູນ.


ລາຍຊື່ວິທີການໃນບໍລິການ Database

CloseDatabase
Commit
CreateDataset
DAvg
DCount
DMin

DMax
DSum
DLookup
GetRows
OpenFormDocument
OpenQuery

OpenSql
OpenTable
Rollback
RunSql
SetTransactionMode


CloseDatabase

ປິດການເຊື່ອມຕໍ່ຖານຂໍ້ມູນປັດຈຸບັນ.

ໄວຍາກອນ:

db.CloseDatabase()

ຕົວຢ່າງ:


    myDatabase.CloseDatabase() ' Basic
  

    myDatabase.CloseDatabase() # Python
  

Commit

Commit ການອັບເດດທັງໝົດທີ່ເຮັດຕັ້ງແຕ່ການເອີ້ນໃຊ້ Commit ຫຼື Rollback ຄັ້ງກ່ອນໜ້າ.

note

ວິທີການນີ້ຈະຖືກລະເລີຍຖ້າມີການ commit ອັດຕະໂນມັດຫຼັງຈາກທຸກຄຳສັ່ງ SQL, ນັ້ນຄືຖານຂໍ້ມູນຖືກຕັ້ງເປັນໂໝດ auto-commit ເລີ່ມຕົ້ນ.


ໄວຍາກອນ:

db.Commit()

ຕົວຢ່າງ:

ໃນ Basic

      ' ຕັ້ງລະດັບທຸລະກຳເປັນ REPEATABLE_READ
      myDB.SetTransactionMode(4)
      myDB.RunSql("UPDATE ...")
      myDB.Commit()
      myDB.RunSql("DELETE ...")
      ' ທົດສອບບາງເງື່ອນໄຂກ່ອນການ commit
      If bSomeCondition Then
          myDB.Commit()
      Else
          myDB.Rollback()
      End If
      ' ກັບຄືນສູ່ໂໝດ auto-commit
      myDB.SetTransactionMode()
    
ໃນ Python

      myDB.SetTransactionMode(4)
      myDB.RunSql("UPDATE ...")
      myDB.Commit()
      myDB.RunSql("DELETE ...")
      if some_condition:
          myDB.Commit()
      else:
          myDB.Rollback()
      myDB.SetTransactionMode()
    

CreateDataset

ສ້າງອິນສະແຕນ (instance) ຂອງບໍລິການ Dataset ໂດຍອີງຕາມຕາຕະລາງ, ຄຳສັ່ງສອບຖາມ ຫຼື ຄຳສັ່ງ SQL SELECT.

ໄວຍາກອນ:

db.CreateDataset(sqlcommand: str, opt directsql: bool, opt filter: str, opt orderby: str): svc

ພາຣາມິເຕີ:

sqlcommand: ຊື່ຕາຕະລາງ, ຊື່ຄຳສັ່ງສອບຖາມ ຫຼື ຄຳສັ່ງ SQL SELECT ທີ່ຖືກຕ້ອງ. ຊື່ຕ່າງໆອາດຈະຖືກຄອບດ້ວຍວົງເລັບຫຼ່ຽມ. ອາຄິວເມນນີ້ຕ້ອງກົງກັນທັງຕົວພິມໃຫຍ່ ແລະ ຕົວພິມນ້ອຍ (case-sensitive).

directsql: ຕັ້ງອາຄິວເມນນີ້ເປັນ True ເພື່ອສົ່ງຄຳສັ່ງໄປຫາເຄື່ອງຈັກຖານຂໍ້ມູນໂດຍກົງ ໂດຍບໍ່ຜ່ານການປະມວນຜົນເບື້ອງຕົ້ນຈາກ LibreOffice (ຄ່າເລີ່ມຕົ້ນ = False).

filter: ກຳນົດເງື່ອນໄຂທີ່ຂໍ້ມູນ (records) ຕ້ອງກົງກັນເພື່ອໃຫ້ລວມຢູ່ໃນຊຸດຂໍ້ມູນທີ່ສົ່ງຄືນ. ອາຄິວເມນນີ້ຖືກຂຽນໃນຮູບແບບຄຳສັ່ງ SQL WHERE ໂດຍບໍ່ຕ້ອງມີຄຳສຳຄັນ "WHERE".

orderby: ກຳນົດການຈັດລຽງຂອງຊຸດຂໍ້ມູນໃນຮູບແບບຄຳສັ່ງ SQL ORDER BY ໂດຍບໍ່ຕ້ອງມີຄຳສຳຄັນ "ORDER BY".

ຕົວຢ່າງ:

ຕົວຢ່າງຕໍ່ໄປນີ້ໃນ Basic ແລະ Python ຈະສົ່ງຄືນຊຸດຂໍ້ມູນທີ່ມີຂໍ້ມູນຈາກຕາຕະລາງຊື່ "Customers".

ໃນ Basic

      oDataset = myDatabase.CreateDataset("Customers", Filter := "[Name] LIKE 'A'")
    
ໃນ Python

      dataset = myDatabase.CreateDataset("Customers", Filter = "[Name] LIKE 'A'")
    

DAvg, DCount, DMin, DMax, DSum

ຄິດໄລ່ຟັງຊັນການຄິດໄລ່ກຸ່ມຂໍ້ມູນ (aggregate function) ທີ່ກຳນົດໃຫ້ໃນຟິວ (field) ຫຼື ນິພົດ (expression) ຂອງຕາຕະລາງ.

ນອກຈາກນັ້ນ, ຍັງສາມາດກຳນົດເງື່ອນໄຂ SQL WHERE ເປັນຕົວຕອງທີ່ຈະຖືກນຳໃຊ້ກ່ອນການຄິດໄລ່ຟັງຊັນກຸ່ມຂໍ້ມູນ.

ໄວຍາກອນ:

db.DAvg(expression: str, tablename: str, [criteria: str]): any

db.DCount(expression: str, tablename: str, [criteria: str]): any

db.DMin(expression: str, tablename: str, [criteria: str]): any

db.DMax(expression: str, tablename: str, [criteria: str]): any

db.DSum(expression: str, tablename: str, [criteria: str]): any

ພາຣາມິເຕີ:

expression: ນິພົດ SQL ທີ່ຊື່ຟິວຖືກຄອບດ້ວຍວົງເລັບຫຼ່ຽມ.

tablename: ຊື່ຕາຕະລາງ (ໂດຍບໍ່ຕ້ອງມີວົງເລັບຫຼ່ຽມ).

criteria: ເງື່ອນໄຂ WHERE ໂດຍບໍ່ຕ້ອງມີຄຳສຳຄັນ "WHERE", ເຊິ່ງຊື່ຟິວຕ້ອງຖືກຄອບດ້ວຍວົງເລັບຫຼ່ຽມ.

ຕົວຢ່າງ:

ຕົວຢ່າງຂ້າງລຸ່ມນີ້ສົມມຸດວ່າໄຟລ໌ Employees.odb ມີຕາຕະລາງຊື່ EmployeeData.

ໃນ Basic

      GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
      Dim myDB as Variant
      Set myDB = CreateScriptService("Database", "/home/user/Databases/Employees.odb")
      ' ນັບຈຳນວນພະນັກງານໃນຕາຕະລາງ
      MsgBox myDB.DCount("[ID]", "EmployeeData")
      ' ສົ່ງຄືນຍອດລວມຂອງເງິນເດືອນທັງໝົດໃນຕາຕະລາງ
      MsgBox myDB.DSum("[Salary]", "EmployeeData")
      ' ຂ້າງລຸ່ມນີ້ແມ່ນບາງຕົວຢ່າງຂອງວິທີການຕອງ (filter) ຕາຕະລາງ
      MsgBox myDB.DCount("[ID]", "EmployeeData", "[Position] = 'Manager'")
      MsgBox myDB.DCount("[ID]", "EmployeeData", "[Position] = 'Sales' AND [City] = 'Chicago'")
      MsgBox myDB.DCount("[ID]", "EmployeeData", "[FirstName] LIKE 'Paul%'")
    
ໃນ Python

      myDB = CreateScriptService("Database", "/home/user/Databases/Employees.odb")
      bas = CreateScriptService("Basic")
      bas.MsgBox(myDB.DCount("[ID]", "EmployeeData"))
      bas.MsgBox(myDB.DSum("[Salary]", "EmployeeData"))
      bas.MsgBox(myDB.DCount("[ID]", "EmployeeData", "[Position] = 'Manager'"))
      bas.MsgBox(myDB.DCount("[ID]", "EmployeeData", "[Position] = 'Sales' AND [City] = 'Chicago'"))
      bas.MsgBox(myDB.DCount("[ID]", "EmployeeData", "[FirstName] LIKE 'Paul%'"))
    

DLookup

ຄິດໄລ່ນິພົດ SQL ໃນຂໍ້ມູນ (record) ດຽວທີ່ຖືກສົ່ງຄືນໂດຍເງື່ອນໄຂ WHERE ທີ່ກຳນົດໂດຍພາລາມິເຕີ Criteria.

ຖ້າຄຳສັ່ງສອບຖາມສົ່ງຄືນຂໍ້ມູນຫຼາຍລາຍການ, ຈະພິຈາລະນາພຽງແຕ່ລາຍການທຳອິດເທົ່ານັ້ນ. ໃຊ້ພາລາມິເຕີ OrderClause ເພື່ອກຳນົດວ່າຜົນລັບຂອງຄຳສັ່ງສອບຖາມຈະຖືກຈັດລຽງແນວໃດ.

ໄວຍາກອນ:

db.DLookup(expression: str, tablename: str, [criteria:str], [orderclause: str]): any

ພາຣາມິເຕີ:

expression: A SQL expression in which the field names are surrounded with square brackets.

tablename: A table name (without square brackets).

criteria: A WHERE clause without the "WHERE" keyword, in which field names are surrounded with square brackets.

orderclause: An ORDER BY clause without the "ORDER BY" keywords. Field names should be surrounded with square brackets.

ຕົວຢ່າງ:

ໃນ Basic

      MsgBox myDB.DLookup("[FirstName]", "EmployeeData", Criteria := "[LastName] LIKE 'Smith'", OrderClause := "[FirstName] DESC")
      MsgBox myDB.DLookup("[Salary]", "EmployeeData", Criteria := "[ID] = '3'")
      MsgBox myDB.DLookup("[Quantity] * [Value]", "Sales", Criteria := "[SaleID] = '5014'")
    
ໃນ Python

      bas = CreateScriptService("Basic")
      bas.MsgBox(myDB.DLookup("[FirstName]", "EmployeeData", criteria = "[LastName] LIKE 'Smith'", orderclause = "[FirstName] DESC"))
      bas.MsgBox(myDB.DLookup("[Salary]", "EmployeeData", criteria = "[ID] = '3'"))
      bas.MsgBox(myDB.DLookup("[Quantity] * [Value]", "Sales", criteria = "[SaleID] = '5014'"))
    

GetRows

Stores the contents of a table or the results of a SELECT query or of an SQL statement in a two-dimensional array. The first index in the array corresponds to the rows and the second index refers to the columns.

An upper limit can be specified to the number of returned rows. Optionally column names may be inserted in the first row of the array.

The returned array will be empty if no rows are returned and the column headers are not required.

ໄວຍາກອນ:

db.GetRows(sqlcommand: str, directsql: bool = False, header: bool = False, maxrows: int = 0): any

ພາຣາມິເຕີ:

sqlcommand: A table or query name (without square brackets) or a SELECT SQL statement.

directsql: When True, the SQL command is sent to the database engine without pre-analysis. Default is False. This argument is ignored for tables. For queries, the applied option is the one set when the query was defined.

header: When True, the first row of the returned array contains the column headers.

maxrows: The maximum number of rows to return. The default is zero, meaning there is no limit to the number of returned rows.

ຕົວຢ່າງ:

Below are a few examples of how the GetRows method can be used:

ໃນ Basic

      Dim queryResults as Variant
      ' Returns all rows in the table with column headers
      queryResults = myDB.GetRows("EmployeeData", Header := True)
      ' Returns the first 50 employee records ordered by the 'FirstName' field
      queryResults = myDB.GetRows("SELECT * FROM EmployeeData ORDER BY [FirstName]", MaxRows := 50)
    
ໃນ Python

      queryResults = myDB.GetRows("EmployeeData", header = True)
      queryResults = myDB.GetRows("SELECT * FROM EmployeeData ORDER BY [FirstName]", maxrows = 50)
    

OpenFormDocument

Opens the specified form document in normal mode. This method returns a FormDocument service instance corresponding to the specified form document.

If the form document is already open, the form document window is activated.

If the specified form document does not exist, then Nothing is returned.

ໄວຍາກອນ:

svc.OpenFormDocument(formdocument: str): svc

ພາຣາມິເຕີ:

formdocument: The name of the FormDocument to be opened, as a case-sensitive string.

ຕົວຢ່າງ:

ໃນ Basic

Most form documents are stored in the root of the Base document and they can be opened simply using their names, as in the example below:


    Dim oFormDoc As Object
    oFormDoc = myDB.OpenFormDocument("myFormDocument")
  

If form documents are organized in folders, it becomes necessary to include the folder name to specify the form document to be opened, as illustrated in the following example:


    oFormDoc = myDB.OpenFormDocument("myFolder/myFormDocument")
  
ໃນ Python

    formDoc = myDB.OpenFormDocument("myFormDocument")
  

    formDoc = myDB.OpenFormDocument("myFolder/myFormDocument")
  

OpenQuery

Opens the Data View window of the specified query and returns an instance of the Datasheet service.

If the query could not be opened, then Nothing is returned.

ໄວຍາກອນ:

db.OpenQuery(queryname: str): obj

ພາຣາມິເຕີ:

queryname: The name of an existing query as a case-sensitive String.

ຕົວຢ່າງ:

ໃນ Basic

      myDatabase.OpenQuery("MyQuery")
    
ໃນ Python

      myDatabase.OpenQuery("MyQuery")
    

OpenSql

Runs a SQL SELECT command, opens a Data View window with the results and returns an instance of the Datasheet service.

ໄວຍາກອນ:

db.OpenSql(sql: str, directsql: bool): obj

ພາຣາມິເຕີ:

sql: A string containing a valid SQL SELECT statement. Identifiers may be enclosed by square brackets.

directsql: When True, the SQL command is sent to the database engine without pre-analysis (Default = False).

ຕົວຢ່າງ:

ໃນ Basic

      myDatabase.OpenSql("SELECT * FROM [Customers] ORDER BY [CITY]")
    
ໃນ Python

      myDatabase.OpenSql("SELECT * FROM [Customers] ORDER BY [CITY]")
    

OpenTable

Opens the Data View window of the specified table and returns an instance of the Datasheet service.

ໄວຍາກອນ:

db.OpenTable(tablename: str): obj

ພາຣາມິເຕີ:

tablename: The name of an existing table as a case-sensitive String.

ຕົວຢ່າງ:

ໃນ Basic

      myDatabase.OpenTable("MyTable")
    
ໃນ Python

      myDatabase.OpenTable("MyTable")
    

Rollback

Cancels all changes made to the database since the last Commit or Rollback call.

ໄວຍາກອນ:

db.Rollback()

ຕົວຢ່າງ:

ໃນ Basic

      myDB.SetTransactionMode(1)
      myDB.RunSql("UPDATE ...")
      ' ...
      If bSomeCondition Then
          myDB.Rollback()
      End If
    
ໃນ Python

      myDB.SetTransactionMode(1)
      myDB.RunSql("UPDATE ...")
      # ...
      if bSomeCondition:
          myDB.Rollback()
    

RunSql

Executes an action query of an SQL statement such as creating a table, as well as inserting, updating and deleting records.

The method returns True when successful.

tip

The RunSql method is rejected with an error message in case the database was previously opened in read-only mode.


ໄວຍາກອນ:

db.RunSql(sqlcommand: str, directsql: bool = False): bool

ພາຣາມິເຕີ:

sqlcommand: A query name (without square brackets) or a SQL statement.

directsql: When True, the SQL command is sent to the database engine without pre-analysis. (Default = False). For queries, the applied option is the one set when the query was defined.

ຕົວຢ່າງ:

ໃນ Basic

      myDatabase.RunSql("INSERT INTO [EmployeeData] VALUES(25, 'Smith', 'John')", DirectSQL := True)
    
ໃນ Python

      myDatabase.RunSql("INSERT INTO [EmployeeData] VALUES(25, 'Smith', 'John')", directsql = True)
    

SetTransactionMode

Defines the level of isolation in database transactions.

By default databases manage transactions in auto-commit mode, which means that a Commit is automatically performed after every SQL statement.

Use this method to manually determine the isolation level of transactions. When a transaction mode other than NONE is set, the script has to explicitly call the Commit method to apply the changes to the database.

This method returns True when successful.

warning

Changing the transaction mode closes all Dataset instances created from the current database.


ໄວຍາກອນ:

db.SetTransactionMode(transactionmode: int = 0): bool

ພາຣາມິເຕີ:

transactionmode: Specifies the transaction mode. This argument must be one of the constants defined in com.sun.star.sdbc.TransactionIsolation (Default = NONE)

note

Read the section Transaction handling above to learn more about the transaction isolation levels used in LibreOffice.


ຕົວຢ່າງ:

ໃນ Basic

      myDB.SetTransactionMode(com.sun.star.sdbc.TransactionIsolation.REPEATABLE_READ)
      oDataset = myDB.CreateDataset("SELECT ...")
      ' ...
      ' Reset the transaction mode to default
      myDB.SetTransactionMode()
    
ໃນ Python

      from com.sun.star.sdbc import TransactionIsolation
      myDB.SetTransactionMode(TransactionIsolation.REPEATABLE_READ)
      dataset = myDB.CreateDataset("SELECT ...")
      # ...
      myDB.SetTransactionMode()
    
warning

ຣູທີນ ຫຼື ຕົວລະບຸ Basic ຂອງ ScriptForge ທັງໝົດທີ່ຂຶ້ນຕົ້ນດ້ວຍເຄື່ອງໝາຍຂີດກ້ອງ "_" ແມ່ນສະຫງວນໄວ້ສຳລັບໃຊ້ພາຍໃນ. ພວກມັນບໍ່ໄດ້ມີໄວ້ໃຫ້ໃຊ້ໃນມາໂຄຣ Basic ຫຼື ສະຄຣິບ Python.