Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: An odd flat file database question

by Stamp_Guy (Monk)
on Feb 10, 2001 at 23:31 UTC ( [id://57650]=note: print w/replies, xml ) Need Help??


in reply to An odd flat file database question

Seems that everyone is saying "GO SQL!", so I've started to do some research into it, but I've got a few questions:

  • Is is possible to set it up so I could develop the program on my Win98 desktop and have it completely portable to a Linux server with minimal changes? Basically: is it cross-platform?
  • How hard is it to learn SQL?
  • Should I get a really good handle on Perl and Linux before I start messing with any SQL stuff?
  • Is there any natively supported database system that Perl uses? I've been reading a book called Teach Yourself Perl 5 in 24 Hours (yea right, 24 hours!) and it had a little example of a program that uses DBMs. Where could I find some more information in newbie language for that?
As you can see, this newbie's got tons of questions. Perhaps some of these questions are stupid, but I really want to learn. I appreciate all the help I'm getting from the people here! Thanks guys!

Replies are listed 'Best First'.
Re: Re: An odd flat file database question
by footpad (Abbot) on Feb 11, 2001 at 10:17 UTC
    First and foremost, do not confuse SQL as a language or database format. While it has the word "language" in its name, it's really a standard for obtaining, and futzing with data across many different development tools (languages) and database formats/Products (MySQL, Oracle, Sybase, PostGres, Excess, xBASE, Paradox, yadda, yadda, yadda).

    SQL is a standard for manipulating and defining databases. It has two types of statements:

    • Data Manipulation Language (DML): SELECT, UPDATE, INSERT, and DELETE.
    • Data Definition Language (DDL): CREATE, DROP, ALTER, GRANT.

    Each statement is aptly named and operates against an object that generally makes sense.

    A decent overview will help. (See below)

    In your case, you're looking for something along these lines:

    select c.* from Catalog c where ( c."CatalogId" < $lovalue ) AND ( c."CatalogID" > $hivalue )

    This returns all records from the Catalog table that have Catalog ID's in the range specified by the $lovalue and $hivalue variables. (The specific syntax will depend greatly on the database format you choose. For example MySQL has slight syntax variations over Oracle and ODBC.)

    With most DBI drivers, this will give you an array of matched records, that you can then print very quickly using whatever approach you're most comfortable with.

    To gain the cross platform success you're looking for, you need to choose your database format with care. I recommend starting with mySQL, for though it doesn't completely offer the features of a complete client/remote server database format, it is cross platform, easy to install, and free. Should you eventually outgrow it, you should be able to convert your SQL to your new format with little to no trouble.

    Like chess, the basics of SQL are easy to learn. Those eight statements I listed earlier are (arguably) pretty much the heart of SQL itself. It gets a little harder when you start learning the extensions and features of your database format. For example, many remote database servers support stored procedures and triggers, which are (essentially) chunks of code run by the database server to validate (and respond to) your data values and what the users does with them. This can be quite daunting, but it can be very powerful. Learn it as you can.

    Personally, I wouldn't worry about mastering Linux before tackling SQL. Get the Cheetah book; it'll help a great deal. It goes into the basics, offers a decent SQL tutorial, and walks you through the process very carefully. Also, it provides a great reference to various DBI drivers, which will help you make the most informed decision regarding the file format.

    As far as the latest AM advice is concerned, she (assumed) was offering advice on how to similate the SELECT statement without using SQL.

    Assuming that you're storing your data in a hash, she suggested building a second hash that sorted all records in order of your desired sort order. This hash contains two values: the value you're sorting on as the key and a pointer (or reference) to the "real" database record in the original hash. (Note that if you have multiple matches to the same catalog number, the second hash element should be an array of references to each unique record.) That way, you can quickly determine which set of records you're after, simply by examining the keys you're dealing with.

    --f

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://57650]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-09-18 17:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (25 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.