Hans Hagen <[EMAIL PROTECTED]> writes:
> At 04:48 PM 3/18/2002 +0100, you wrote:
> >Hans Hagen <[EMAIL PROTECTED]> writes:
> >
> > > As part of context-on-demand support i'm looking into / playing with
> > > interfacing to (my)sql (from xfdf to start with). I wonder if it is
> > > possible to use patterns for field names? Say that i have v_1
> > > ... v_20, is it possible to select v_5..v_10?
> >
> >I suggest a course data base design would be useful here :-)
>
> i'm definitely no database guru but was wondering (looking back at
> using spss) if there was a way to do it that way, now i have to
> reconstruct some xml; actually, i have been playing with just pushing
> xml into such a database, but so far i haven't seen easy solutions
> (i.e. without the need to install all kind of extra stuff, compiling,
> hacking, etc).
There is, sort of, a way. Most of the time when you use SQL it's from
another environment. The environment where I've done most SQL stuff
is perl. In perl it is easy to write, e.g., a perl subroutine that
generates the SQL you need. You can collect a small bunch of
subroutines to generate the kind of SQL you work with most frequently.
The most amazing example of using perl as an extra level in language
abstraction is in openssl, where there's a bunch of perl code that
generates *assembly* code that does the cryptographic operations!
This demo that just prints the SQL instead of using DBI and executing
it:
#! /usr/bin/perl -w
use strict;
&demo;
sub select_col_range {
my ($base, $lower, $upper) = @_;
my @fields;
for my $n ($lower .. $upper) {
push @fields, "${base}_$n";
}
return "select " . (join ", ", @fields);
}
sub demo {
print(&select_col_range("v", 5, 10), " from tablename\n");
}
--
--Ed L Cashin | PGP public key:
[EMAIL PROTECTED] | http://noserose.net/e/pgp/