Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,
Well i thought of figuring out a way to write a Client program in C which takes an sql query as the user input and then fetches back the result to the screen.
Now if the database is on a remote machine, can i do the same thing through sockets to execute the query on the remote server and get back the results on the client screen.
Any programmatic examples on this that you could help me with.
Any sample example you could please provide me or any particular article which explicitly describes this scenario.

Thank you.
Posted
Comments
Richard MacCutchan 9-Jan-12 15:07pm    
In theory you could do this but it may be that the SQL response is in some sort of encoded format that you would need to disassemble. I think this may be a question for Google.
Sergey Alexandrovich Kryukov 9-Jan-12 20:14pm    
Only in theory. It's not clear why doing all that.
--SA
Richard MacCutchan 10-Jan-12 3:26am    
I agree it seems totally pointless, but OP did ask the question.
[no name] 10-Jan-12 10:03am    
i am trying to create a GUI tool in C which serves as a tool to access database in a GUI fashion. :)
Albert Holguin 10-Jan-12 13:37pm    
This isn't that difficult but it requires you to know a broad range of stuff... know how to make SQL queries, how to communicate over sockets, and know what the authentication process and application layer the server has set-up. Like I said, not that hard, but if you're just starting out, it's a handful.

You can get better help if you let us know what database you are using. Because most of the databases(all the databases I have already learned provide this, I don't know about those database which i didn't learn) provide API to connect with Database Server. So do the following:
1. Search on google for the instruction to connect with your database.
2. If you can find but still having problem then let us know.
3. If you cannot find the server based solution for your client then please communicate with your database provider.
4.If they dont provide at all, then you might need to create the socket based client. In that case, you would also have to learn about how to develop socket based client server application
 
Share this answer
 
You do not need sockets to do this. Database libraries have their own client interfaces that do the task for you. There are few abstraction layer that can be used if you are using different type of databases.
Well you can use any of the below libraries:
1. SOCI - Database Abstraction Library[^]
2. POCO Library Database abstraction layer[^]
These provide abstraction for dealing with different databases in a unified way from C++. I have used SOCI and it work great.
I have a windows build for SOCI using visual studio 2008 in the following location for my use. You can use it if you wish. It uses sqlite3 as database.
My SOCI 3.1 Build for Visual Studio 2008.[^]
Let me know if you need any help.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900