MySQL kurz & gut
MySQL kurz & gut
Das preiswerte Taschen- buch stellt MySQL-rele- vante Inhalte systematisch und knapp dar, sodass es sich optimal zum Nach- schlagen beim Pro- grammieren eignet. [Mehr Infos...]
Es sind Benutzer im FreeBASIC-Chat online.
(Stand:  )
FreeBASIC bei Twitter
Twitter FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!


Using mdTypes [EN]

von RedakteurMODSeite 9 von 12

mdTypes comes with another feature, which will make things a lot easier. With the persistence api one can simply save objects and whole collections into different databases.

Currently, mdTypes supports SQLite, MySQL and an own file based format. The classes are called:
- mdSQLitePersistence
- mdMySQLPersistence
- mdTypesPersistence

All classes extend the mdPersistence class. This class is pretty empty, so usually you won't use it. Nevertheless, if you plan to create an own persistence class for another database, just extend this class, too, and it will automatically work with all mdTypes classes and programs, which are using them.

To use the persistence api with your own classes, they have to be serializable/deserializable. Have another look at page 4 to see how to do it.

So, let's try to persist any serializable class. First of all, we will create some DEFINEs:

#Define PERSISTENCE_CLASS mdSQLitePersistence
#Define DB_NAME "MyApplicationDB_mdSQLitePersistence"

As the persistent api allows to switch classes, PERSISTENCE_CLASS is just a helper for later replacements. Here it's the SQLite persistence. DB_NAME is the name of the database.

Now, we have to prepare the tables. For this, just create a mdMap(String, String) and pass an object of your class together with a table name:

Dim As MyFoo tempFoo
Dim As String temp
Dim As mdMap(String, String) tables
temp = tables.put("MyFoo", tempFoo)

You can add as many tables as you wish. The columns will be automatically created with the information of your object. But so far we don't have anything, so we have to create the database:

sql.createDatabase(DB_NAME, tables)

If you want to delete the database, you can use sql.removeDatabase(DB_NAME), to update sql.updateDatabase(DB_NAME, tables). Updating a database will remove all tables, which are not passed in the list anymore, while new tables will be created. Existing tables with different columns will also be updated, if possible.

To create new objects in the database, you can do something like this:

Dim As MyFoo newFoo
'...fill newFoo with important information
sql.createObject("MyFoo", newFoo)


Gehe zu Seite Gehe zu Seite  1  2  3  4  5  6  7  8  9  10  11  12  
Zusätzliche Informationen und Funktionen
  • Das Tutorial wurde am 17.04.2014 von RedakteurMOD angelegt.
  • Die aktuellste Version wurde am 31.07.2019 von RedakteurMOD gespeichert.
  Bearbeiten Bearbeiten  

  Versionen Versionen