Re: how to assert into the db with rdbms

Thomas Russ <[email protected]> Fri, 18 May 2007 11:36:59 -0700
Newsgroups gmane.comp.ai.powerloom
Message-ID <[email protected]>
On May 18, 2007, at 8:29 AM, Kambiz Darabi wrote:

> Hello,
>
> I have just started to explore the possibilities of the RDBMS system.
>
> Querying the DB works with some minor problems using sbcl+clsql+mysql.
>
> But, how can I assert facts into the database?

This part of our database functionality is not yet completed.
We are having some technical difficulties with proper handling of  
Function assertions.

If you only use concepts and relations, we have something  
experimental that works, but it isn't released, not even in the new  
snapshots.

>
> I found create-sql-assertion-from-proposition and a
> db-relation-update-demon in the code, but cannot figure out, how they
> might be useful to store sth in the database.

What you found is some of the infrastructure that we will be using  
for this, but it isn't fully hooked up yet.

The method for assertions is quite simple.  Define the relations  
using DEFTABLE and then use the standard PowerLoom assert method.   
This would then write the assertions into the database.  One  
restriction is that you would have to make sure the PowerLoom  
relation mapped to the full database table, since otherwise the  
results would be a bit unpredictable.

>
> Another problem is: I can use defquery to define queries involving one
> single table, but I don't manage to define sql table joins correctly.
>
> Would you be so kind to provide an example for these two uses of
> rdbms:
>
> 1) asserting facts into the DB
>
> 2) defquery with an SQL join

Something like this should work:

Assume DB tables
   employees:  employeeName  employeeDepartment
   departments:  department  managerName

(DEFQUERY employeeBoss ((?employeeName STRING) (?bossName STRING))
   :QUERY-PATTERN
   (RDBMS/SQL-QUERY our-db
      "SELECT employeeName, managerName FROM employees, departments
WHERE #${employeeName='?employeeName'}
AND #${managerName='?managerName'}
AND employeeDepartment = department
"))

What are you trying that is failing?