date_test_01.bmx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. SuperStrict
  2. Framework Database.PostgreSQL
  3. Import BRL.filesystem
  4. Import brl.standardio
  5. Local db:TDBConnection = LoadDatabase("POSTGRESQL", "maxtest", "localhost", 0, "user", "pass")
  6. If db.hasError() Then
  7. errorAndClose(db)
  8. End If
  9. Local names:String[][] = [ ..
  10. [ "Alfred", "Aho" ], ..
  11. [ "Brian", "Kernighan" ], ..
  12. [ "Peter", "Weinberger" ] ]
  13. If db.isOpen() Then
  14. db.executeQuery("DROP TABLE person")
  15. db.executeQuery("DROP SEQUENCE person_id")
  16. ' create the auto-incrementing field
  17. db.executeQuery("CREATE SEQUENCE person_id INCREMENT 1 START 1")
  18. ' id field assigned to sequence
  19. Local s:String = "CREATE TABLE person (id integer primary key DEFAULT NEXTVAL('person_id'), " + ..
  20. " forename varchar(30)," + ..
  21. " surname varchar(30), bday date, thetime time, exact timestamp )"
  22. db.executeQuery(s)
  23. If db.hasError() Then
  24. errorAndClose(db)
  25. End If
  26. For Local i:Int = 0 Until names.length
  27. db.executeQuery("INSERT INTO person (forename, surname, bday, thetime, exact) values ('" + names[i][0] + "', '" + ..
  28. names[i][1] + "', '200" + i + "-01-01', '04:01:45', '2007-03-04 13:20:13')")
  29. If db.hasError() Then
  30. errorAndClose(db)
  31. End If
  32. Next
  33. Local query:TDatabaseQuery = db.executeQuery("SELECT * from person")
  34. If db.hasError() Then
  35. errorAndClose(db)
  36. End If
  37. While query.nextRow()
  38. Local record:TQueryRecord = query.rowRecord()
  39. ' displays the String representation of date/times.
  40. ' You can also get record.value(index) and cast to the appropriate type, and call getDate() to retrieve the real Long value.
  41. Print("Name = " + record.getString(1) + " " + record.getString(2) + " - " + ..
  42. record.getString(3) + " - " + record.getString(4) + " - " + record.getString(5))
  43. Wend
  44. db.close()
  45. End If
  46. Function errorAndClose(db:TDBConnection)
  47. Print(db.error().toString())
  48. db.close()
  49. End
  50. End Function