in reply to Query database in Prolog

[Added: Prolog SQL has some good info. You should definately avoid re-inventing a wheel. The real Prolog people have already been hacking on this problem.]


I was thinking about this yesterday. It seemed most natural that you'd patch AI::Prolog to be able to query this stuff. You might want to introduce a new built-in function to represent joins. You've got a problem in that SQL relations have no order to columns so you'll either need to ignore that or instruct AI::Prolog in what order to read columns when querying the database.

% A "normal" lookup city('New York', Cityid), usr(Cityid, Name, Id). % An id-less query. Maybe the engine notices the join and transforms t +his into the prior behind the scenes. % Maybe an invented built-in like references/4 cause the transformatio +n. :- references( 'USR', 'CITY_ID', 'USR', 'CITY_ID' ). usr( city( 'New York' ), Name ).

⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Replies are listed 'Best First'.
Re^2: Query database in Prolog
by zby (Vicar) on Dec 29, 2005 at 20:16 UTC
    I plan to patch DBIx::Class to retain the order, but I think about other possibilities as well.

      "Retain" the order? The db provides no order!

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

        You have some order in the CREATE clause and most databases would retain that when you issue * in a SELECT.