Buchempfehlung
Visual Basic 6 Kochbuch
Visual Basic 6 Kochbuch
Viele praktische Tipps zum Programmieren mit Visual Basic 6, die sich oft auch auf FB übertragen lassen. [Mehr Infos...]
FreeBASIC-Chat
Es sind Benutzer im FreeBASIC-Chat online.
(Stand:  )
FreeBASIC bei Twitter
Twitter FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!

Tutorial

Using mdTypes [EN]

von RedakteurMODSeite 10 von 12

You can also fetch data:

Dim As mdList(mdMapStringString) resultList
resultList = sql.getObjectsBy("MyFoo", "id", "2")

This will return a list of mdMap(String, String) from the table "MyFoo" where "id" equals "2". The maps represents an object of your class, so you can simply deserialize the map into your class.

Since this will allow you to get objects ony by one value, there's another getter method called getObjects(table, object). As this doesn't make sense except if you want to know, if this object already exists, it's better to use a serialized object with only the fields you want to use. The easiest way is to build the string by hand:

Dim As mdList(mdMapStringString) temp
temp = sql.getObjects("MyFoo", "{value=28.79, name=SuperFoo}")

This code will sarch for any object in table "MyFoo" with "value" equals "28.79" and "name" equals "SuperFoo".

Of course, you can also update and delete objects. These are the methods available:
- updateObject(table, oldObject, newObject)
- updateObjectsBy(table, columnName, value, newObject)
- deleteObjecttable, objectString)
- deleteAllObjects(table)
- deleteObjectsBy(table, columnName, value)

As MySQL and SQLite are "real" databases, they provide another method called dynamicQuery. Using this, you can do everything, that can be done with the database using queries. Basically, you will use it like this:

Dim As mdList(mdMapStringString) temp
temp = sql.dynamicQuery("/*any sql statement*/")

It's possible, that something "happens" while doing database operations. With sql.getLastErrorMessage() you can get the last error message as string. Usually, this should return an empty string.
Most of the methods will also return a mdPersistenceError object. The default value is mdPersistenceError.NO_ERROR.


Using MySQL you will need some more parameters to use a database. Besides the database name you will have to pass the url, a user name and the password. Here's an example, how to initialize the MySQL persistence:

Dim As mdMySQLPersistence sql = Type<mdMySQLPersistence>("MyApplicationDB", "localhost", "root", "pwd")

You can instantiate all persistence classes the same way, but the host, the user and the password will be ignored as mdMySQLPersistence is the only one, which uses them at the moment.

Check out the examples and test files, too, to gain a better understanding of how to use the api.

 

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