MySQL

Started by
16 comments, last by BeanDog 16 years, 5 months ago
I thank you all for the information. It seems that there are some advantages as far as the speed, integration with VS, and saving to a single file rather than a server but none of you have said that MySQL is slow, I installed a component which allows me to use MySQL.Data.MySQLClient which has worked well so far, possibly similar to System.Data.SQLite and even though the single file feature seems like a great thing the mention of it not being free sways me back to MySQL. I am trying to make this game with little to no $, it is meant as a learning experience and not too much more.

Again, i appreciate your inputs but with my current information i think that i will stay with MySQL. Please post more reasons for me to switch if you feel it has a large enough benefit.
Advertisement
Quote:Original post by dhammer
...even though the single file feature seems like a great thing the mention of it not being free sways me back to MySQL. I am trying to make this game with little to no $, it is meant as a learning experience and not too much more.

...

Please post more reasons for me to switch if you feel it has a large enough benefit.

SQLite and System.Data.SQLite are absolutely free in every sense--more free than MySQL (you can distribute it without source, etc.) as SQLite is in the public domain.
So what do i need to use SQLite? Just the use System.Data.SQLite statement in VS?
Yes! Just download and install the System.Data.SQLite library, add a reference to the assembly to your project (right-click the project, click Add Reference, go to the .NET tab, and find System.Data.SQLite), and start using the statements directly in your code. As an example, here's how you would open an existing database (or create it if it didn't exist):

        void OpenDB() {            if (!System.IO.File.Exists(Filename))                CreateDB();            m_Connection = new SQLiteConnection("Data Source=" + Filename + ";");            m_Connection.Open();        }        void CreateDB() {            if (System.IO.File.Exists(Filename))                System.IO.File.Delete(Filename);            m_Connection = new SQLiteConnection("Data Source=" + Filename + ";New=True;");            m_Connection.Open();            //Create all the tables for your database here.        }


A simple query against the database might look like this:
SQLiteCommand cmd = new SQLiteCommand("delete from Include where FileId=@p0", m_Connection);cmd.Parameters.Add(new SQLiteParameter("@p0", iFileId));cmd.ExecuteNonQuery();


Getting the results of select queries is a bit more complicated, but not too bad. You use the SQLiteDataReader class that's returned from ExecuteReader. Don't forget to Close() the SQLiteDataReader, or your next query will fail. Only one reader can be open per database at a time (for any ADO.NET data connection).
SQLiteCommand cmd = new SQLiteCommand("select Name from Variable where ClassId = @p0 order by upper(Name)", m_Connection);                cmd.Parameters.Add(new SQLiteParameter("@p0", iClassId));                SQLiteDataReader r = cmd.ExecuteReader();                List<string> ret = new List<string>();                while (r.Read())                    ret.Add((string)r["Name"]);                r.Close();                return (ret);
So is SQLite only for locally stored databases or does it also have features to connect to a remote source?
as an extension question to this one, how would you go about accessing the mySQL command line? just out of curiousity
--------------------------------------Not All Martyrs See Divinity, But At Least You Tried
-Download the MySQL server from www.mysql.com
-Install and configure an instance of the server using the configuration wizard which will start after you install or from Start Menu -> Programs -> MySQL 5.0 -> MySQL Config Wizard
-Once the server is installed it should auto-start.
-If on the server computer you can use the MySQL Command Line Client from the start menu (if you checked the box during install to add it) or Start -> Run -> cmd which will open the command prompt

If you are using the MySQL Command Line Client, you should be prompted to enter a password, this default logs you in as root.
If you are using the command prompt continue with the instructions.

-Logging into the mysql server requires that you bring command prompt down to 'C:\', use cd .. to move back 1 directory, cd ..\.. with as many instances of .. for each step if you want to do it in a single command line.
-Once at 'C:\' (or whatever your harddrive letter is) type mysql -h localhost -u root -p
-This is assuming you want to connect to yourself (substitute an ip for localhost if you are connecting to a remote host), that you are logging in as root (substitute a username for root), and that you have a password (remove -p from the end if there is no password, it might work either way but it will skip the prompt for a pw if you remove it).
-Then you will get a prompt saying something like "Enter Password:"
-Enter your password now.
Quote:Original post by dhammer
So is SQLite only for locally stored databases or does it also have features to connect to a remote source?

It only accesses locally-stored databases.

This is not perfect for all situations, but if you're programming a MUD, you're going to want to program your own server application as well as the client application. Allowing client applications to directly access the database opens up a whole host (no pun intended) of security/cheating issues.

This topic is closed to new replies.

Advertisement