It would be a good idea to create some form of a meta description to valid
data. As you mentioned, passed to the file, or simply some sort of
configuration file. Here's an example, nevermind the syntax, consider it
psuedo code.
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
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).
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.
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.
On 1/4/07, etoom etoom <[EMAIL PROTECTED]> wrote:
I'm writing a module that validates a csv file against a simple
schema, here is an example on how it should work:
Simple schema(might be given in a file or as argument):
int, char, char, date,bool
Here is a sample of valid data:
123, hello, all, 12/12/06, 0
in my program I only need dates with the (MM/DD/YY) format and 0/1
booleans. but extending that won't be a tough problem.
I also think that auto sql generation will be usefull.
On 1/4/07, Jad madi <[EMAIL PROTECTED]> wrote:
>
> I second Ammai, there is and there should be a universal validator, it
> depends on your data 7aj
>
>
> On 1/3/07, Ammar Ibrahim <[EMAIL PROTECTED]> wrote:
> > It would be easy to write a validator yourself to check on the number
of
> > column, but as for the types of data, this is more of a business logic
in
> > your application, and I doubt you'd find anything like that. Best
thing to
> > do is to write one yourself.
> >
> >
> > - Ammar
> >
> > On 1/3/07, etoom etoom <[EMAIL PROTECTED]> wrote:
> > >
> > > yes of course, the number of columns, the type of data each column
is
> > > supposed to have (numbers, dates,..). that's it.
> > >
> > > On 1/3/07, Ammar Ibrahim <[EMAIL PROTECTED] > wrote:
> > > > What would make a CSV file valid or invalid? e.g. every record to
have
> > the
> > > > same number of column? etc
> > > >
> > > > - Ammar
> > > >
> > > >
> > > >
> > > > On 1/3/07, etoom etoom < [EMAIL PROTECTED]> wrote:
> > > > >
> > > > >
> > > > > Salam all,
> > > > > I'm trying to read a csv (comma separated values) file and store
the
> > > > > values in a database using perl, every thing is going great
except I
> > > > > can't find any module that validates csv file against a schema
of some
> > > > > form like we have in xml. Is their any?
> > > > >
> > > > > Yazan
> > > > >
> > > > > > >
> > > > >
> > > >
> > >
> > > > >
> > >
> >
>
> >
>
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---