     dup prepare-query dup bind-query dup retrieve finalize-query ;
 
 : get-results ( query -- results )
-    dup query-results [ nip ] [ dup run-query query-results ] if* ;
-
-: with-query ( quot -- results )
-    [
-        <query> query set
-        call
-        query get get-results
-    ] with-scope ;
+    dup results>> [ nip ] [ dup run-query results>> ] if* ;
 
 ! nodes and arcs
 

! Copyright (C) 2007, 2008 Alex Chapman
! See http://factorcode.org/license.txt for BSD license.
USING: arrays assocs kernel math namespaces sequences sqlite ;
IN: semantic-db.db

! sqlite utils

    query construct-boa ;

: invalidate-query ( query -- query )
    f >>results ;

: add-field ( field query -- query )
    dup invalidate-query fields>> push ;

: add-table ( table query -- query )
    dup invalidate-query tables>> push ;

: add-condition ( condition query -- query )
    tuck invalidate-query conditions>> push ;

: add-arg ( arg key query -- query )
    [ invalidate-query args>> set-at ] keep ;

<PRIVATE

: field-sql ( field -- sql )
    [ dup table>> % CHAR: . , name>> % ] "" make ;

: fields-sql ( query -- sql )
    fields>> dup length [
        [ field-sql ] map ", " join
    ] [
        drop "*"
    ] if ;

: tables-sql ( query -- sql )
    tables>> ", " join ;

: conditions-sql ( query -- sql )
    conditions>> dup length [
        " and " join "where " swap append
    ] [
        drop ""
