On 1/4/07, etoom etoom <[EMAIL PROTECTED]> wrote:
On 1/4/07, Ammar Ibrahim <[EMAIL PROTECTED]> wrote:
> ......
> What I would do, is create an abstract validation class, and have some
sort
> of a factory for every rule.
>
> $colDelimiter = ',';
> $recordDelimiter = "\n";
> $escapeChar = '\\';
> $cols = 5;
> $col[0] = new CsvValidator('int', array('min'=>1, 'max' => 10) );//min &
max
> are optional
> $col[1] = new CsvValidator('string', array('minLength' => 10,
'maxLength' =>
> 20) );
> $col[2] = new CsvValidator('alphanum'); //e.g. Alphanumeric
> $col[3] = new CsvValidator('date', array('MM/DD/YY') );//Supply the mask
> $col[4] = new CsvValidator('regex', array('[a-zA-Z0-9]{,5}') );
> //etc
very flexible, but over complicates things for my tiny program, I'll
probably use a more flexible design later, maybe when I get it to work
with all the data types I want.
> You could also simplify the API by not supplying the arguments to the
actual
> driver as an array, instead have a function that receives arbitrary
number
> of arguments and works on them (This is supported in PHP, check
> http://php.net/func_get_args).
Let me remind you that I'm using perl :). I think perl sees all
arguments as elements of one array:
@array = (1, 2, 3);
$arrayRef = [EMAIL PROTECTED];
func( $arrayRef, @array);
the Argument array (@_) will look like this: ($arrayRef, 1, 2, 3)
So their is no problem with variable number of arguments.
> A gotcha: what if a string contained the delimiter? you need to do a bit
of
> checking on that, unless you have a nice library that removes this
headache.
This is solved by the CSV files specification witch states that if a
field contains the delimiting character it should be quoted. in perl
their is a module (TEXT::CSV) that handles these issues, but of
course doesn't provide validation.
> Auto generating SQL should be very easy. You can as well use the factory
> strategy to generate SQL for different RDBMS. Depending on your target
> database, you would generate the desired SQL. e.g. A SQL generator for
> MySQL, Postgres, Oracle ..etc
>
> In PHP, some really advanced SQL abstraction layers exist that would
make
> generating SQL for dozens of databases rather easy.
I'm not using any abstraction layer, Although I should be using one.
but I don't really know if perl has one.
Perl does have plenty infact. It all depends on your needs, an abstraction
layer makes your SQL portable but at the cost of performance.
- Ammar
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Jolug" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups-beta.google.com/group/Jolug?hl=en-GB
-~----------~----~----~----~------~----~------~--~---