Category Archives: General

Challenge: can you implement your own small database engine ?

A Simple and Efficient Implementation for Small Databases by Andrew D. Birreil Michael B. Jones Edward P. Wobber*

http://birrell.org/andrew/papers/024-DatabasesPaper-SOSP.pdf

Based on that paper, you can write a small database engine. I suggest you to add a CLI tool,  a SQL parser and executor .. for example!

You could take a look at the SQLite code source to get ideas how this is implemented. By doing that, you get a better understanding how databases work.

If you did, please comment 🙂

Postgresql-Get the number of rows affected

You will find a way below to get the number of rows affected by an UPDATE or a DELETE statement.

 
CREATE FUNCTION update_foobar(id INT, field1 VARCHAR(40))
RETURNS INTEGER
LANGUAGE plpgsql
AS $$
DECLARE
    -- some variables declarations
BEGIN
    -- UPDATE or DELETE
    -- then 
    GET DIAGNOSTICS ru := ROW_COUNT;
    RETURN ru;
END;
$$ ;

shell – code de retour par une commande

Comment lire le code de retour d’une commande comme pwd ?

chaque commande executée vous renverra un code d’erreur situé entre 0 et 255. 0 pour opération réussie, sinon toute autre chiffre signifiera qu’une erreur s’est déroulée lors de l’exécution.

Le code de retour est disponible dans cette variable:

$?

Pour exemple

~ pwd toto
pwd: too many arguments
~ echo $?
~ 1

~ pwd
~ /home/user
~ echo $?
~ 0

Stay tuned