Arc Forumnew | comments | leaders | submitlogin
2 points by almkglor 6111 days ago | link | parent

I suggest you use real tables, and iterate using ontable:

  (= tbl
    (fill-table (table)
      (list
        ''name 'Study ; to avoid polluting the field namespace
        'StudyId '(int pk studyseq)
        'StudyCode '(string 25)
        'StartData '(datetime 8)
        'Description '(string 25))))

  ;I assume you want a string to be passed elsewhere later?
  (tostring
   (pr "insert into " (tbl ''name) " ")
   (with (fields nil pk-fields nil pk-values)
     (ontable field type tbl
      (when (alist type)
       (if (some 'pk type)
         (do
           (push field pk-fields)
           (push (last type) pk-values))
         (push field fields))))
     ; push creates the list in reverse order, so
     ; zap the lists with our rev-stick
     (zap rev pk-fields)
     (zap rev pk-values)
     (zap rev fields)
     (pr " ( ")
     (when fields
       (prall fields) (pr ","))
     (prall pk-fields)
     (pr " ) ")
     (pr "values ( ")
     (when fields
       (prall (map [string ":" _] fields)) (pr ","))
     (prall (map [string _ ".nextval"] pk-values))
     (pr " ) ")
     (pr " returning " (car pk-fields) " into :" (car pk-fields))))
I also suggest you get nex-3's arc-wiki.git:

http://arclanguage.com/item?id=833

Among the amenities is a "not-bad" (help ...) function which will probably also help you explore the non-pg-documented parts of the language.