MySQL source code

I have to make a project in c++ and i wanted to create a basic version of MySQL such that the user enters SQL commands on the screen. What I wanted to know was whether and how can you create a program to interpret and compile the commands, and if it is out of the level of CBSE class 12th.
If you just want to write an interpreter, I'd choose a more manageable language. My head spins just thinking all the stuff you'd have to implement just for SELECT/INSERT/UPDATE.
So MySQL is a bad idea. But if it is built on C/C++ , then there has to be a way, right?
Any other possible suggestions for a project, I definitely don't want to make another file handling project.
If you want to access Database using C++, I can help you out with that. User can enter SQL commnads and it will apply to your database. you will need Admin username, password, port and database name. Let me know, if is that what u want ? I have created a function that would execute SQL command.
Hi I would like connect C++ with MySQL as well can not find good information how to do in internet.
My database works on localhost. Have got compiler Borland C++ 6. What I need is how to configure compiler and how to connect to database and make first query. With PHP do not have any problem.
Thanks :)
@FiftyEight
http://dev.mysql.com/tech-resources/articles/mysql-connector-cpp.html
you might find this link helpful (Read it all I'm too lazy to summarize). Tell me if you are really a class XII student..??
Well when working with SQL, you don't really do anything with the language, except relay that information tot he Driver that is present for the SQL server. The C++ aspect of it is essentially the "View" component of such application. With that being said, interpreting SQL does not require compilation. If you are looking to create a simple databasing application, I would reccommend looking into string parsing and searching algorithms. The storage median can then be acquired for data processing and then you will ahve to look into optimized searching algorithms for database entry search.

Essentially, connecting to an SQL server consists of initalizinf the Driver class, connecting to the server through credentials specified performing a statement on that server to receive a resultset. You then process that result based on the query for the query type (int, array, BLOB, etc...)

C++'s role in this is the recipient on the user input, transacting with the SQL server to execute and receive the result, then processing that result. You don't have to interpret the SQL statement itself.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
void SQL_XML::connect ( MYSQL* connection )
{
	/*****************************************************************************
	*	This function will connect this program to remote Database. It is using  *
	*	mysql_real_connect (...) function and print appropriate message.		 *
	*	It is important to connect successfully to access any of mysql functions.*
	*****************************************************************************/
	
	if (mysql_real_connect(
							connection,				// MySQL obeject
							host.c_str(),				// Server Host
							username.c_str(),			// User name of your database
							password.c_str(),			// Password of the database
							db.c_str(),				// Database name
							port,						// port number
							NULL,					// Unix socket  ( for us it is Null )
							0)== NULL)
   {
      cout << "Error" << mysql_error(connection) << "\n";	// Printing an Error Message
	  connect(connection);
   }
   else 
   {
	   cout << "DBS is connected." <<endl;						// Printing connection messege.
   }
}


This function will connect to database and following one will execute SQL command. You will require to send a string in that function.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
string execute_command ( MYSQL* connection, string command )
{
	/******************************************************************************
	*	This function take MYSQL obeject and command ( string ) and perform the   *
	*	Query and also print the result if there is any out put.				  *
	*******************************************************************************/
	 
	if (mysql_query(
					connection,							// MySQL object
					command.c_str()						// SQL Command String
					) != 0)
   {
      cout << "ERROR" << endl << mysql_error(connection)  // Printing error message
			<< endl ;	
      return  "";
   }

   MYSQL_RES* result = mysql_store_result(connection);	//Storing the result into MYSQL_RES object
  
   if (result == NULL)
	   return ""; 
   else 
   {
	   string prnt="";
	   int rows = mysql_num_rows(result);					// Getting number of rows in result
	   int fields = mysql_num_fields(result);				// Getting number of fields in rows
	   for (int i = 1; i <= rows; i++)
	   {
		  MYSQL_ROW row = mysql_fetch_row(result);			// Separating rows and storing into MYSQL_ROW object

		  for (int j = 0; j < fields; j++)
		  {
			 string field(row[j]);
			 
			 if (j > 0) 
			 {
				 prnt = prnt +  ",";
			 }
			prnt = prnt +  field ;							// adding the attribute
		  }
		  prnt = prnt + "\n";								// separating lines in output
	   }
	   mysql_free_result(result);							// releasing memory   
	   return prnt;
	} 
}
Yes, I am a class XII student.
@mcrist- so what you're saying is that if i connect c++ with the SQL server, it automatically compiles? So my program would consist of parsing string and sending them to the server, and receiving the result to execute? Foe eg: if i just type "create table student;" will it automatically display "table created" or am i just getting everything wrong?!

what exactly does a mysql-c++-connector do?
I have instaled mysql-c++-connector and still can not manage to connect C++ with MySQL. Did try connect C# and it was positive. Can someone discribe step by step what to do pleasse I think there is a problem with configuration.

Many Thanks
@FiftyEight

Everyone is taking your project wrong what you are planning to make is a MySQL king of Database Management System of Small level.
but let me make yo clear that MySQL kind of software packages are developed in thousands of man years of coding and its smallest version will be a headache for you.

So you better focus yourself in small project of your level.

I am not saying that you cannot make this thing but it will takes years for you to work on this.

Try to work on c++ using platforms like UNIX / Linux.

All the best.

Ashish
@ FiftyEight

No, you got it right...but to compile this code you will need to download MySQL connector for C++ from
http://dev.mysql.com/downloads/connector/net/6.3.html
and I wrote that code in Windows 7.
Yeah, right. Thanks ashish.
But I'll try out the c++ myql connector thing, just to see :)
Topic archived. No new replies allowed.