Andrew Cooke | Contents | Latest | RSS | Previous | Next


Welcome to my blog, which was once a mailing list of the same name and is still generated by mail. Please reply via the "comment" links.

Always interested in offers/projects/new ideas. Eclectic experience in fields like: numerical computing; Python web; Java enterprise; functional languages; GPGPU; SQL databases; etc. Based in Santiago, Chile; telecommute worldwide. CV; email.

Personal Projects

Choochoo Training Diary

Last 100 entries

[Computing] Okular and Postscript in OpenSuse; There's a fix!; [Computing] Fail2Ban on OpenSuse Leap 15.3 (NFTables); [Cycling, Computing] Power Calculation and Brakes; [Hardware, Computing] Amazing Pockit Computer; Bullying; How I Am - 3 Years Post Accident, 8+ Years With MS; Collaboration request; [USA Politics] In America's Uncivil War Republicans Are The Aggressors; [Programming] Selenium and Python; Better Walking Data; [Bike] How Fast Before Walking More Efficient Than Cycling?; [COVID] Coronavirus And Cycling; [Programming] Docker on OpenSuse; Cadence v Speed; [Bike] Gearing For Real Cyclists; [Programming] React plotting - visx; [Programming] React Leaflet; AliExpress Independent Sellers; Applebaum - Twilight of Democracy; [Politics] Back + US Elections; [Programming,Exercise] Simple Timer Script; [News] 2019: The year revolt went global; [Politics] The world's most-surveilled cities; [Bike] Hope Freehub; [Restaurant] Mama Chau's (Chinese, Providencia); [Politics] Brexit Podcast; [Diary] Pneumonia; [Politics] Britain's Reichstag Fire moment; install cairo; [Programming] GCC Sanitizer Flags; [GPU, Programming] Per-Thread Program Counters; My Bike Accident - Looking Back One Year; [Python] Geographic heights are incredibly easy!; [Cooking] Cookie Recipe; Efficient, Simple, Directed Maximisation of Noisy Function; And for argparse; Bash Completion in Python; [Computing] Configuring Github Jekyll Locally; [Maths, Link] The Napkin Project; You can Masquerade in Firewalld; [Bike] Servicing Budget (Spring) Forks; [Crypto] CIA Internet Comms Failure; [Python] Cute Rate Limiting API; [Causality] Judea Pearl Lecture; [Security, Computing] Chinese Hardware Hack Of Supermicro Boards; SQLAlchemy Joined Table Inheritance and Delete Cascade; [Translation] The Club; [Computing] Super Potato Bruh; [Computing] Extending Jupyter; Further HRM Details; [Computing, Bike] Activities in ch2; [Books, Link] Modern Japanese Lit; What ended up there; [Link, Book] Logic Book; Update - Garmin Express / Connect; Garmin Forerunner 35 v 230; [Link, Politics, Internet] Government Trolls; [Link, Politics] Why identity politics benefits the right more than the left; SSH Forwarding; A Specification For Repeating Events; A Fight for the Soul of Science; [Science, Book, Link] Lost In Math; OpenSuse Leap 15 Network Fixes; Update; [Book] Galileo's Middle Finger; [Bike] Chinese Carbon Rims; [Bike] Servicing Shimano XT Front Hub HB-M8010; [Bike] Aliexpress Cycling Tops; [Computing] Change to ssh handling of multiple identities?; [Bike] Endura Hummvee Lite II; [Computing] Marble Based Logic; [Link, Politics] Sanity Check For Nuclear Launch; [Link, Science] Entropy and Life; [Link, Bike] Cheap Cycling Jerseys; [Link, Music] Music To Steal 2017; [Link, Future] Simulated Brain Drives Robot; [Link, Computing] Learned Index Structures; Solo Air Equalization; Update: Higher Pressures; Psychology; [Bike] Exercise And Fuel; Continental Race King 2.2; Removing Lowers; Mnesiacs; [Maths, Link] Dividing By Zero; [Book, Review] Ray Monk - Ludwig Wittgenstein: The Duty Of Genius; [Link, Bike, Computing] Evolving Lacing Patterns; [Jam] Strawberry and Orange Jam; [Chile, Privacy] Biometric Check During Mail Delivery; [Link, Chile, Spanish] Article on the Chilean Drought; [Bike] Extended Gear Ratios, Shimano XT M8000 (24/36 Chainring); [Link, Politics, USA] The Future Of American Democracy; Mass Hysteria; [Review, Books, Links] Kazuo Ishiguro - Never Let Me Go; [Link, Books] David Mitchell's Favourite Japanese Fiction; [Link, Bike] Rear Suspension Geometry; [Link, Cycling, Art] Strava Artwork; [Link, Computing] Useful gcc flags; [Link] Voynich Manuscript Decoded; [Bike] Notes on Servicing Suspension Forks

© 2006-2017 Andrew Cooke (site) / post authors (content).

Very First Steps to C-ORM

From: andrew cooke <andrew@...>

Date: Sat, 23 Feb 2013 17:24:45 -0300

I will post something mor epolished to the work blog eventually, but here 
is a quick example that I finally have working.

This example directory is included in the C-ORM sources.  This is the
contents after running configure for the package:

  > ls
  example_foo.c  foo.h  Makefile

And this is the struct that we want "ORM" for (in C):

  > cat foo.h
  #ifndef FOO_H
  #define FOO_H

  typedef struct foo {
    int id;
    int bar;
    char *baz;
  } foo;


And this is the file used to populate the database:

  > cat
  rm -f example_foo.db
  sqlite3 example_foo.db < foo.corm.sql
  sqlite3 example_foo.db <<EOF
  insert into foo (id,bar,baz) values (1,42,'towel');

(note that uses a file that doesn't exist yet - foo.corm.sql).

And this is the example program itself (again, including a file that does not
exist yet).

  > cat example_foo.c

  #include <stdio.h>

  #include "isti.h"
  #include "isti_flow.h"
  #include "isti_sql.h"
  #include "isti_sqlite.h"

  #include "foo.corm.h"


  int main()

    // Obtain a connection to the database.  This uses an SQLite database, but
    // the handle returned is a generic API.

    isti_db *db = NULL;
    CHECK(sqlite.connect(&db, "example_foo.db", 60));

    // Construct a selector.  This does the work of extracting a value from the
    // database.

    corm_foo_select *s = NULL;
    CHECK(, &s));

    // Call the selector, filtering the database entries, and extracting a
    // single instance of the `foo` struct.

    foo *f = NULL;
    CHECK(s->where(s)->bar(s, 42)->and(s)->\
	_bra(s)->baz(s, "towel")->or(s)->baz(s, "fish")->_ket(s)->\
	one(s, &f));
    printf("found foo instance with bar=%d and baz=%s\n", f->bar, f->baz);


    if (f) free(f);
    if (s) status =, status);
    if (db) status = db->close(db, status);

    if (status) fprintf(stderr, "error: %d\n", status);


Now, when I run make:

  > make
  PYTHONPATH=../../cgen/src python ../../cgen/src/isti/cgen/ foo.h
  gcc -std=gnu99 -DHAVE_CONFIG_H -I. -I../..   -I../../clib/src  -g -O0 -MT
  foo.corm.o -MD -MP -MF .deps/foo.corm.Tpo -c -o foo.corm.o foo.corm.c
  mv -f .deps/foo.corm.Tpo .deps/foo.corm.Po
  gcc -std=gnu99 -DHAVE_CONFIG_H -I. -I../..   -I../../clib/src  -g -O0 -MT
  example_foo.o -MD -MP -MF .deps/example_foo.Tpo -c -o example_foo.o
  mv -f .deps/example_foo.Tpo .deps/example_foo.Po
  /bin/bash ../../libtool --tag=CC   --mode=link gcc -std=gnu99  -g -O0
  -L../../clib/src/.libs -o example_foo foo.corm.o example_foo.o -lcorm
  libtool: link: gcc -std=gnu99 -g -O0 -o .libs/example_foo foo.corm.o
  example_foo.o  -L../../clib/src/.libs

    to run the example from the example/src directory:
      LD_LIBRARY_PATH=../../clib/src/.libs ./example_foo

And let's follow the instructions:

  > LD_LIBRARY_PATH=../../clib/src/.libs ./example_foo
  select id,bar,baz from foo where bar=? and ( baz=? or baz=? )
  found foo instance with bar=42 and baz=towel



Updated Syntax

From: andrew cooke <andrew@...>

Date: Sun, 24 Feb 2013 02:01:53 -0300

I've changed the syntax for restricting queries.  As a consequence you have
several options:

This is verbose, but parameters are strongly typed and the compiler can detect
spelling mistakes.  "bra" and "ket" are particularly kludgy.

  s->_where(s)->bar(s, "=", 42)->_and(s)->\
  _bra(s)->baz(s, "like", "towel")->_or(s)->baz(s, "like", "fish")->_ket(s)->\
  _one(s, &f)

This is equivalentm, but much more compact and with much less checking:

  s->_(s ,"where bar=%d and (baz like %s or baz like %s)", 42, "towel", "fish")->\
  _one(s, &f)

For simple queries, the verbose approach has implicit "and":

  s->bar(s, "=", 42)->baz(s, "like", "towel")->_one(s, &f)

Literals are allowed anywhere:

  s->_(s, "where")->bar(s, "=", 42)->baz(s, "like", "towel")->\
  _(s, "limit 1")->_one(s, &f)


Comment on this post