Databases in C

Alright, I'm writing some file syncing software in c, and well I need to create a database of some kind to keep track of differences in the server's and host's files. The thing is I have not the slightest clue where to even start with working with something like that in c. So do you guys have any ideas or suggestions?

Attached: photo5224633304345586329.jpg (481x604, 37.11K)

fucking newfags out

Attached: 8ef875808a51a139cac4e7c4fc8c84c65fb894dffc4b24eee2d8017e4d6ff2c6.jpg (1280x1440, 110.24K)

This site is broken. He's not nesesarily new. Blame codemonkey

i don't buy it, I know the site is fugged but posting multiple breads usually happens when newfags don't know that on bigger boards it takes a while for it to go through so they keep reloading the page and pressing new thread again, I know because it happened to me too back in the day

Attached: 519dc9508c7852fa01b93f0769420571943d376002c6c9c46e562b950160059e.jpg (640x640, 38.75K)

You dun goofed.

sqlite?

You don't need to create a database from scratch, neither does it have to be in C, as long as you can talk to it in C. There are decades proven solutions, big and lightweight.

Search first based on need, not restriction. You aren't looking for a C database. First and foremost you are looking for an east to work with database and a tutorial on how to interface with a database. There are many great tutorials around. Do that first, it will narrow down what you actually want and need.
You can't make decisions if you don't know what you need, neither can someone here truly recommend something without knowing what your project looks like.

You need to actually create a database. Sounds like you don't need a relational one, so something like NoSQL will work. Although be aware that basically any non-relational is called a "nosql" database but that NoSQL is actually a particular implementation of one as well.
Once you have a database that is suited for your needs, you'll need to interact with it.
The easiest solution is to find a header-only library that makes interacting with it easy; just point it to a database and start doing operations.
If none exists, you're going to need to build your own bindings.
Since it's C and you can't just make a class to use as an interface, you'll probably just want to write some macros to make common tasks easy to do.
Frankly, explaining how to do that is beyond the scope of what I can reasonably fit in a post, and if you can't do it yourself (and I suspect you can't) then I'd recommend just selecting a database, any database, that has a header-only library available.

I haven't needed to use a database with C before, but I imagine C++ has a number of libraries available. Finding ones which are C compatible may be difficult.

Attached: 1457987534394.png (630x600, 154.56K)

You're overthinking this, it's just a list of checksums.

Don't bother with this guy OP. These worry warts litter these threads with "don't try to write it yourself user!" hysteria.

You can write your own functional db in C, its quite easy in fact since C gives you nearly all the tools you need to succeed.

Just start small, basically just a data store with simple set/get methods and expand from there. The benefit you will have is something that performs much faster than the bloated solutions normally mentioned (e.g. sqlite, etc). Also remember that writing it yourself is oftentimes faster than trying to slave away at learning some poorly documented API (e.g. postgresql).

Based. Who needs ACID anyways?
/thread btw

I was kicking myself so fucking hard when I realized it. sorry for being a tard lol.

Alright, thanks for the serious feedback I'll probably post the source on here once I get it somewhat functional.

Decent bait.

He's not baiting, its the truth. I once wrote a fully-functional SMTP server in an afternoon by just glancing over the RFC spec.
True there were a couple of hairy parts, like I had to just hardcode the SSL certificate stuff like just returning 'true' in certain functions no matter what otherwise I couldn't get it connect via SSL.
However, the fact remains that it is a fully-functional SMTP server that is spec-compliant.

...

...

sorry bud, but I don't think Xenon gas is a pronoun

Yee of little faith.

That's why you use the far-superior MySQL.

Transactions are for pussies. Just make sure you only do 1 thing at a time and don't be a bad programmer so your program and operating system doesn't crash. Make sure you use a UPS too so you don't have to worry about the power going out.
t. Ctard

26?

...

SQLite.

Look into D.#! /usr/bin/env rdmdimport std.stdio;@propertyref int bump(ref int n) { return ++n; }void main() { int k = 42; k.bump.bump.bump; writeln(k);}output: 45. And that shebang? yeah you can run this as a script. An executable will be compiled whenever needed and that executable will be run in place of the script, but you get the benefit that an admin can trivially look into your file syncing software to troubleshoot a problem or adapt it to some new situation, without having to go on the epic quest a typical opaque binary needs.

It happens SCREEEEE FIX THIS NIGA SHIZ

wat

SQLite3 is really the best option.
You may be thinking, "I don't need a relational database engine. All I want to do is store some stuff." I used to think the same thing until I decided to just try it on an insignificant project.
Try it yourself though; when you want to add functionality beyond just ejaculating some key/value pairs onto the disc you'll be thankful. And if you get down the road and find that you really don't like sqlite you can replace it. The refactoring would be good for your code anyways. The only downside is that SQL is boring and won't net you meme-points like Rust or D will.

What kind of differences are you trying to track anyways? mtime? hash? unified diff? If it's just mtime you could have a schema like...
CREATE TABLE files(id INTEGER PRIMARY KEY, name TEXT, mtime INTEGER);CREATE TABLE local(fileid REFERENCES files);CREATE TABLE server(fileid REFERENCES files);CREATE VIEW localmtime(name, mtime) AS SELECT name, mtime FROM files, local WHERE files.id = local.fileid;CREATE VIEW servermtime(name, mtime) AS SELECT name, mtime FROM files, server WHERE files.id = server.fileid;
And finding all the newer files on the server would be something as simple as:
SELECT * FROM localmtime AS l, servermtime AS sWHERE l.name = s.name AND l.mtime < s.mtime;

do as rsync does and use mtime+filesize, with optional md5sum

Good idea. I was just giving a simplified example for OP. There's tons of ways the data can be represented in relational databases depending on needs.
CREATE TABLE files(location TEXT, name TEXT, mtime INTEGER, size INTEGER, sum TEXT, UNIQUE (location, name));CREATE VIEW local AS select name,mtime,size,sum from files where location = 'local';CREATE VIEW server AS select name,mtime,size,sum from files where location = 'server';SELECT * FROM local AS l, server AS s WHERE l.name = s.name AND l.size != s.size;
I'm no sql guy though; can't vouch for how good/bad my tables/queries are.

...

OP here

Ya I did some research and came to the same conclusion
the only necessary data would be file path/location, but mtime size and maybe hashes would be nice.
Thanks for the code snippets btw that helps.

This how you'd do it?
CREATE VIEW IF NOT EXISTS localmtime(name, mtime) AS SELECT name, mtime FROM files INNER JOIN local ON files.id = local.fileid;CREATE VIEW IF NOT EXISTS servermtime(name, mtime) AS SELECT name, mtime FROM files INNER JOIN server ON files.id = server.fileid;SELECT * FROM localmtime AS l JOIN servermtime AS sUSING (name)WHERE l.mtime < s.mtime;

But muh GC

usually I don't mind GC. It's also easy to use the stack with D's structs (vs. D's classes).
and D is actually such a good language that -betterC is no joke, even though you lose all the normal libraries. Just import core.stdc and pretend that you're writing in ANSI C from the year 3033

Same retardation as Rust.

fputc
fgetc

Attached: clownmath.jpg (481x604, 53.26K)

I need retards and manchildren to leave this board immediately.

>using kibibytes or similar for any reason ever

You mad cause your DB engine is a 46 MiB clusterfuck made in Java.
Also, I just copied and pasted the size from their website.
Also, the smallest version is the Win32 version. Eat shit, Librefags.

HAPAS ARE SUPERIOR TO WHITES

HAPAS ARE SUPERIOR TO WHITES

HAPAS ARE SUPERIOR TO WHITES

HAPAS ARE SUPERIOR TO WHITES

Whatcha sliding MOSHE?

Whatcha sliding mordecai?

Shut up chaim.

I smell rats.

Whatcha sliding MOSHE?

Europeons need to burn in a tar-pit. Disgusting