Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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

In reply to Re: Re: An odd flat file database question by footpad
in thread An odd flat file database question by Stamp_Guy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others browsing the Monastery: (5)
    As of 2024-09-18 17:33 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.