Prev | Current Page 318 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

.. -resource config.xml@config_xml
The file config.xml is now embedded in the compiled output and can be accessed in code using the
identifier config_xml .
The parameters for MySQL and SQLite are not the same; to account for those differences they are stored
in a variable of type Dynamic . They can be cast to their relative typedef to get access to them in a
strictly typed manner.
164
Part I: The Core Language
// content of file Config.hx
typedef MySqlParams = {
database : String,
host : String,
port : Int,
user : String,
pass : String,
socket : String
}
typedef SqliteParams = String
typedef DbInfo = {
name : String,
type : String,
isdefault : Bool,
params : Dynamic
}
class Config
{
private static var xml = Xml.parse(Std.resource(???config_xml???)).firstChild();
private static var dbElement = xml.elementsNamed(???db???).next();
public static function getDatabase(?name : String) : DbInfo
{
// if no name is passed to the function, use the default db name
if(name == null)
{
name = getDefaultDatabaseName();
}
for(el in dbElement.


Pages:
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330