2

I am developing an application completely written in C. I have to save data permanently somewhere. I tried file storage but I feel its really a primitive manner to do the job and I don't want to save my sensitive data in a simple text file. How can i save my data and access it back in an easy manner? I come from JavaScript background and would prefer something like jsons. I will be happy with something like postgreSQL also. Give me some suggestions. I am using gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3.

1

6 Answers 6

4

sqlite seems to meet your requirements.

SQLite is an embedded SQL database engine. Unlike most other SQL databases, SQLite does not have a separate server process. SQLite reads and writes directly to ordinary disk files. A complete SQL database with multiple tables, indices, triggers, and views, is contained in a single disk file. The database file format is cross-platform - you can freely copy a database between 32-bit and 64-bit systems or between big-endian and little-endian architectures. These features make SQLite a popular choice as an Application File Format. Think of SQLite not as a replacement for Oracle but as a replacement for fopen()

Check out the quickstart

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

1 Comment

Thanks for the quickstart link
2

http://www.postgresql.org/docs/8.1/static/libpq.html

libpq is the C application programmer's interface to PostgreSQL. libpq is a set of library functions that allow client programs to pass queries to the PostgreSQL backend server and to receive the results of these queries.

1 Comment

Thanks for the info.. My application requires to save only a small amount of data and it needs something really light. I think i will go for sqlite this time.
1

I would recommend SQLite. I think it is a great way of storing local data.

There are C library bindings, and its API is quite simple.

Its main advantage is that all you need is the library. You don't need a complex database server setup (as you would with PostgreSQL). Also, its footprint is quite small (it's also used a lot in mobile development world {iOS, android, others}).

Its drawback is that it doesn't handle concurrency that well. But if it is a local, simple, single-threaded application, then I guess it won't be a problem.

MySQL embedded or BerkeleyDB are other options you might want to take a look at.

3 Comments

Best resources are on the link I already provided. Take a look at it. SQLite documentation is pretty decent.
App will have to handle multi threaded situations :( I am making a small chat server in c.
Then I would recommend serializing access to database file with only one thread handling all of it, or using a more robust product (MySQL, PostgreSQL, Firebird, BerkeleyDB).
1

SQLite is a lightweight database. This page describes the C language interface:

SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. SQLite is the most widely deployed SQL database engine in the world. The source code for SQLite is in the public domain.

1 Comment

Okey, seems like this is the right option.. Digging on it already
1

SQLite is a popular choice because it's light-weight and speedy. It also offers a C/C++ interface (including a bunch of other languages).

Comments

0

Everyone else has already mentioned SQLite, so I'll counter with dbm:

http://linux.die.net/man/3/dbm_open

It's not quite as fancy as SQLite (e.g, it's not a full SQL database), but it's often easier to work with from C, as it requires less setup.

1 Comment

I need the simplest option available.. Dont really care about the performance since application size is small.

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.