Alright, this is still unfinished, At the moment it only supports MYSQL, but I will finish rest later, if I get time. It's untested so far and so, but looks like it would work.
Anyways, when I get home I will test it and fix whatever I find of bugs etc.
It also still contains the xml converter as it's under solution.
The XmlLib is a DLL, which you just add as reference to your project, however there is some major things you need to do, before you actually use it.
First of all you have to initialize the dbconfig.
The extension of all xml files using this library should be ".db.xml" as well.
Config.db.xml example
Code:
<?xml version="1.0" encoding="utf-8" ?>
<dbconfig>
<dblanguage>MYSQL</dblanguage>
<dbconnectionstring>HOST;USER;PASS;DATABASE</dbconnectionstring>
</dbconfig>
Now that the config has been created you have to initialize it.
Code:
XmlDbConfig.Initialize();//This will initialize the config.
XmlDbConfig.InitializeDbConnection();//This will initialize the database connection.
Now that the config is initialized, then you will need to intialize the different database structures. A good idea would be to do a dictionary with the tablename as key and the database structure as value.
Code:
Dictionary<string, XmlDbStruct> DatabaseStructures;//The collection of the database structures.
To Initialize a dbstruct you call Read().
An example on how a dbstruct could be initialized.
Code:
XmlDbStruct strct = new XmlDbStruct();//Initializing the xmldbstruct.
strct.Read("accounts.db.xml");//Reading the database structure.
DatabaseStructures.Add("Accounts", strct);//Adding the structure to the dictionary.
There is an example in the debug folder called example.db.xml.
It looks like following:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<Accounts Primarykey="UID">
<UID datatype="UInt32">
1000000
</UID>
<AccountName datatype="String" datasize="16">
Error
</AccountName>
<Password datatype="String">
1234
</Password>
</Accounts>
Note: datasize is only available for strings.
The Get() will get a XmlDbList out of the database, which is the dblist containing all values you want to insert/update/read. You have to update the XmlDbList, whenver you want to, but only call Get() on load and Insert()/Fill() on logout or whenever you want to save.
Insert() will insert a new column to the table, out of a XmlDbList.
Fill() will fill (update) a column to the table, out of a XmlDbList.
Library Members
AlreadyReadDbException: <Class>
Code:
AlreadyReadDbException();
ConfigLoad: <Enum>
Code:
None,
DatabaseLanguage,
ConnectionString
DataType: <Enum>
Code:
Char,
String,
SByte,
Int16,
Int32,
Int64,
Byte,
UInt16,
UInt32,
UInt64,
Double,
Float,
Boolean
DBLanguage: <Enum>
DBValue: <Struct>
Code:
DataType dataType;
object Value;
EmptyDbStructException: <Class>
Code:
EmptyDbStructException();
InvalidColumnException: <Class>
Code:
InvalidColumnException(string column);
InvalidDbFileException: <Class>
Code:
InvalidDbFileException();
XmlDbConfig: <Class>
Code:
Initialize(string configfile);
InitializeDbConnection();
DBLanguage DBLanguage;
string ConnectString;
XmlDbList: <Class>
Code:
XmlDbList(object PrimaryKey);
string PrimaryKey;
void AddOrUpdate(string column, object value);
KeyValuePair<string, object>[] GetDbStruct();
XmlDbStruct: <Class>
Code:
XmlDbStruct();
string TableName;
void Read(string DbFile);
void Fill(XmlDbList dblist);
void Insert(XmlDbList dblist);
XmlDbList Get(object PrimaryKey);
I think that's it at the moment.
Download: (Includes the whole solution! ini to xml converter & the xml library)
Enjoy

.