1

As a personal project, I have been developing my own database software in C#. Many current database systems can use SQL commands for queries. Is there anyone here that could point me in the right direction of implementing such a system in a database software written completely from scratch? For example a user familiar with SQL could enter a statement as a string into an application, that statement will be analyzed by my application and the proper query will be run. Does anyone have any experience with something like that here? This is probably a very unusual questions haha. Basically what I am asking, are there any tools available out there that can dissect SQL statements or will I have to write my own from scratch for that?

Thanks in advance for any help!

(I may transfer some of my stuff to Python and Java, so any potential answers need not be limited to C#)

ALSO: I am not using any current SQL database or anything like that, my system is completely from scratch, I hope my question makes sense. Basically I want my application to be able to interface with programs that send SQL commands.

5
  • 1
  • It needs to read a SQL command, lookup the data in its own way, and return it in a way as any other SQL application would. I am still learning SQL at the moment so I am not entirely familiar yet. I want to create a set of functions fro my application that allow SQL statements to be entered, it will understand the SQL statement entered, then it will run the proper code that can get the output, then structure the output in such a way that adheres to SQL. The part that I need more understanding for is the 'understanding' SQL statements part. Does that make any sense? Commented Aug 26, 2011 at 22:52
  • There are parser generators out there, such as Antlr. Those tools take a grammar and generate lexer and parser code. You can then feed text to that code to get in-memory objects that you can use to drive your DB. Commented Aug 26, 2011 at 23:03
  • These all seem like interesting places to start, thanks for the posts Commented Aug 26, 2011 at 23:55
  • Maybe this project can be used: github.com/FriendlyCSharp/B-tree , but it's not clear if it's RAM-only. I'm in a similar boat, as I'm pondering a prototype of "Dynamic Relational" as a hobby and learning tool. It's kind of like the "JSON columns" of PostgreSQL, but doesn't need to make an SQL distinction between dynamic and static columns (assuming a table has static or required columns). I'm also looking for a C# SQL parsing library for it. Commented Sep 28, 2023 at 20:07

1 Answer 1

3

A full-on database engine is a pretty serious undertaking. You're not going to sit down and have a complete engine next week, so I'd have thought you would want to write the SQL parser piecemeal: adding features to the parser as the features are supported in the engine.

I'm guessing this is just something fun to do, rather than something you want working ASAP. Given that, I'd have thought writing an SQL parser is one of the best bits of the project! I've done lots of work with flat file database engines, because the response times required for queries don't allow a RDBMS. One of the most enjoyable bits has been adding support for SQL fragments in e.g. the UI, where response time isn't quite as vital.

The implementation I work on is plain old C, but in fact from what I've seen, most relational databases are still written primarily in C. And there is something satisfying about writing these things in a really low level language :)

Sign up to request clarification or add additional context in comments.

4 Comments

Yea, those are pretty much my intentions. However, I thought that looking at some previous work could give me some ideas on how to go about doing it. I am fairly new to the programming game so I've never used plain C, although I like the idea of not being dependent on the .NET Framework - that is a lot of work though...
Possibly a decent place to look is at SQLite, which provides one of the simplest relational database implementations around. Be warned though, it's still a very very long way from simple! sqlite.org
Well simple isn't necessarily what I'm looking for. I have a unique approach to the relational database idea and am planning on making it a full system with time. This is actually my second iteration of it, I completely started over from scratch again... May I ask what your approach is? Is there a forum where people discuss matters such as this? I haven't found it lol...
As I mentioned, it's flat file and likely not exactly what you're looking for. The base database is actually just an array of C structures in shared memory segments. Reads can therefore be extremely quick - barely more than a couple of CPU cycles to get to the address. There is a library to load from file, and secure records to disc. There is also a pre-compiler which deals with providing meta-data, and allowing conversions if the structures are changed. A code generator deals with b-tree indexes and chaining related records, and general data access routines.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.