Sorry Vincent I'm not sure what you're meaning. You've written GetColumns ($table). Does it return an array of column names as it should? ----- Original Message ----- From: "Vincent Lee" <[EMAIL PROTECTED]> To: "Rob" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Tuesday, October 15, 2002 11:05 PM Subject: RE: creating a string on the fly
> Rob, > > I've written a subroutine do the getColumns($table). The problem is that > it's passing the entire column set back and appending each one. > 'Passing the entire column set back' is surely what you want? 'Appending each one' what to what? > > I just do a select of the columns based on the table that is sent to the > subroutine. The code you sent me does the entire thing...any ideas? > Sounds like you just need to package the inner loop inside a subroutine: sub CreateView { $table = shift; print "CREATE VIEW_$table AS\n"; print "SELECT ("; $n = 0; foreach $column ( GetColumns ($table) ) { print ", " if $n++; print $column; } print ") FROM $table;\n"; } Am I reading you right? R > > -----Original Message----- > From: Rob [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, October 15, 2002 11:38 AM > To: [EMAIL PROTECTED] > Cc: [EMAIL PROTECTED] > Subject: Re: creating a string on the fly > > > Two problems here. > > 1/ Getting the tables' names and columns from the database. > > 2/ Constructing the SQL from that information. > > The second part is easy: > > foreach $table ( GetTables() ) > { > print "CREATE VIEW_$table AS\n"; > print "SELECT ("; > > $n = 0; > foreach $column ( GetColumns ($table) ) > { > print ", " if $n++; > print $column; > } > print ") FROM $table;\n"; > } > > Which may be enough for you. > > > GetTables() and GetColumns() are the first part, and I can't say any more > about what these might do without knowing more about what interface you have > with the database. > > HTH > > Rob > > ----- Original Message ----- > From: "Vincent Lee" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Cc: <[EMAIL PROTECTED]> > Sent: Tuesday, October 15, 2002 3:37 PM > Subject: Re: creating a string on the fly > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]