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.

MReed
  • 31
  • 5
  • 1
    http://stackoverflow.com/questions/660609/sql-parser-library-for-java http://stackoverflow.com/questions/1147212/sql-parser-in-c – Kev Aug 26 '11 at 22:45
  • 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? – MReed Aug 26 '11 at 22:52
  • There are parser generators out there, [such as Antlr](http://www.antlr.org/). 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. – Merlyn Morgan-Graham Aug 26 '11 at 23:03
  • These all seem like interesting places to start, thanks for the posts – MReed Aug 26 '11 at 23:55

1 Answers1

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 :)

asc99c
  • 3,815
  • 3
  • 31
  • 54
  • 1
    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... – MReed Aug 26 '11 at 23:01
  • 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! http://www.sqlite.org/ – asc99c Aug 26 '11 at 23:13
  • 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... – MReed Aug 26 '11 at 23:53
  • 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. – asc99c Aug 27 '11 at 00:58