Posted to tcl by aspect at Sun Sep 14 10:43:31 GMT 2014view raw

  1. # FIXME:
  2. # - table names are not armoured (because different backends require different armouring!)
  3. # - column names need to be in [a-zA-Z0-9_] for tdbc's binding syntax to work
  4. proc copy_table {fromdb fromtable todb totable} {
  5. set sst [$fromdb prepare "select * from $fromtable"]
  6. set srs [$sst execute]
  7. set cols [$srs columns]
  8. set dst [$todb prepare "insert into $totable ([join $cols ,]) values (:[join $cols ,:])"]
  9. $dst transaction {
  10. $srs foreach rec $sql {
  11. $dst execute $rec
  12. }
  13. }
  14. $sst destroy
  15. $dst destroy
  16. }
  17.  
  18.