Xml Database Structure

02/28/2012 10:43 I don't have a username#1
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>
Code:
MYSQL,
MSSQL
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)
[Only registered and activated users can see links. Click Here To Register...]

Enjoy :).
02/28/2012 10:44 PretendTime#2
Like always your releases amaze me =D thanks
02/28/2012 10:59 pro4never#3
Maybe I'm just dumb but if you're going to xml structure your database.... why not just use nhibernate? Same idea except you get a fully managed database solution which works phenomenally well.
02/28/2012 11:02 Korvacs#4
I'm failing to see the point to be honest, all the downsides of flat file with no advantages beyond the fact that your able to use the framework's classes to manage it?
02/28/2012 11:34 I don't have a username#5
Quote:
Originally Posted by pro4never View Post
Maybe I'm just dumb but if you're going to xml structure your database.... why not just use nhibernate? Same idea except you get a fully managed database solution which works phenomenally well.
Because I will learn more by trying to do things myself, I know nhibernate, this is more like a fun project I did.

Quote:
Originally Posted by Korvacs View Post
I'm failing to see the point to be honest, all the downsides of flat file with no advantages beyond the fact that your able to use the framework's classes to manage it?
I don't get your question exactly, maybe it's just me being dumb.
02/28/2012 11:57 Korvacs#6
Whats the point, is basically what i was getting at..
02/28/2012 12:00 I don't have a username#7
Quote:
Originally Posted by Korvacs View Post
Whats the point, is basically what i was getting at..
Read what I said @ pros quote.
02/28/2012 12:06 Korvacs#8
So its entirely pointless as releases go >.<
02/28/2012 12:30 I don't have a username#9
Quote:
Originally Posted by Korvacs View Post
So its entirely pointless as releases go >.<
Maybe some would be interesting in it.
02/28/2012 16:17 _DreadNought_#10
That someone would be me, has anybody ever checked which is fastest? ini or xml?

If your like me, and simply wont touch MySQL or any of the sort... :P, flatfile is the next option.

Might rewrite my base to read xml vs ini, not sure though.
02/28/2012 16:33 Korvacs#11
Quote:
Originally Posted by _DreadNought_ View Post
That someone would be me, has anybody ever checked which is fastest? ini or xml?

If your like me, and simply wont touch MySQL or any of the sort... :P, flatfile is the next option.

Might rewrite my base to read xml vs ini, not sure though.
Your right!

If your thick and refuse to accept that managed database solutions scale 100s of times better under load and are 10 fold more flexible then this is the article for you.

Although technically the performance gain from xml over ini is minimal as your still parsing data at the end of the day, the advantage comes with the fact that xml is actually supported natively by .net and you dont have to hack together old methods using pinvoke to read a file.
02/28/2012 20:26 _DreadNought_#12
Meh, my computer is pretty old and shitty, and ever since my reformat mysql hasnt worked for shit.

I attempted MsSQL once and failed epicly.

I just dont feel making MySQL work on my computer is worth the effort, so why did Hybrid use INI(And bin) over all the other database options on his latest source?