test_01.bmx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. SuperStrict
  2. Framework Database.SQLite
  3. Import BRL.filesystem
  4. Import brl.standardio
  5. DeleteFile("maxtest.db")
  6. Local db:TDBConnection = LoadDatabase("SQLITE", "maxtest.db")
  7. If Not db Then
  8. Print("Didn't work...")
  9. End
  10. End If
  11. Local names:String[][] = [ ..
  12. [ "Alfred", "Aho" ], ..
  13. [ "Brian", "Kernighan" ], ..
  14. [ "Peter", "Weinberger" ] ]
  15. If db.isOpen() Then
  16. Local s:String = "CREATE TABLE person (id integer primary key AUTOINCREMENT, " + ..
  17. " forename varchar(30)," + ..
  18. " surname varchar(30) )"
  19. db.executeQuery(s)
  20. If db.hasError() Then
  21. errorAndClose(db)
  22. End If
  23. ' transaction test :-)
  24. db.StartTransaction()
  25. If db.hasError() Then
  26. errorAndClose(db)
  27. End If
  28. For Local i:Int = 0 Until names.length
  29. db.executeQuery("INSERT INTO person values (NULL, '" + names[i][0] + "', '" + names[i][1] + "')")
  30. If db.hasError() Then
  31. errorAndClose(db)
  32. End If
  33. Next
  34. ' commit our changes :-)
  35. db.Commit()
  36. If db.hasError() Then
  37. errorAndClose(db)
  38. End If
  39. Local query:TDatabaseQuery = db.executeQuery("SELECT * from person")
  40. If db.hasError() Then
  41. errorAndClose(db)
  42. End If
  43. While query.nextRow()
  44. Local record:TQueryRecord = query.rowRecord()
  45. Print("Name = " + TDBString(record.value(1)).value + " " + TDBString(record.value(2)).value)
  46. Wend
  47. db.close()
  48. End If
  49. Function errorAndClose(db:TDBConnection)
  50. Print(db.error().toString())
  51. db.close()
  52. End
  53. End Function