Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Can SQL be used without a database?

by CountZero (Bishop)
on Dec 31, 2003 at 08:01 UTC ( [id://317853]=note: print w/replies, xml ) Need Help??


in reply to Can SQL be used without a database?

My fellow Monks have all gone lyrical over the benefits of the use of DBI and databases (and very right they are: if you are going to use a database, DBI is the way to go and then you better at the same time install a real database engine, such as MySQL) but I fear that is perhaps not what you were asking: i.e. use SQL statements to traverse a set of hashes.

If by hashes you mean the associative arrays of Perl, I don't think that you can traverse them by using SQL, or at least not in an easy and straightforward way.

DBI::AnyData can use an Array of Arrays (in a particular format) as a data source and theoretically a Hash of Arrays is perhaps just as possible, but it is not documented.

My advice to someone new to (Perl) programming is not to mix hashes and SQL, but rather to concentrate on getting a good grip first on each of these separately.

If you will spend some more time in the Monastery, you will see that we are much better in providing practical answers to concrete questions than in discussing issues of a more general nature (where we tend to become rather filosophical). So if you provide us with some examples of your data, your data structure and perhaps some code snippets, we will gladly give you a "made to measure" solution.

CountZero

"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

  • Comment on Re: Can SQL be used without a database?

Replies are listed 'Best First'.
•Re: Re: Can SQL be used without a database?
by merlyn (Sage) on Dec 31, 2003 at 16:50 UTC
Re: Re: Can SQL be used without a database?
by thegoaltender (Sexton) on Dec 31, 2003 at 14:56 UTC
    First, thanks for everyone's help.
    Let me better explain what I am doing. I have 4 tables of data and I am trying to do joins between them without using a database.
    I changed my hashes to arrays of arrays and tried to use DBI::AnyData. It seems to be having trouble getting my arrays into table format. I am getting the following error:

    Can't coerce array into hash at C:/Perl/site/lib/DBD/AnyData.pm line 247.

    Here is the some of the test code I am using for 1 join:

    $dbh = DBI->connect('dbi:AnyData(RaiseError=>1):'); $dbh->func( 'rdbtable', 'ARRAY', @rdb, 'ad_import'); $dbh->func( 'asitable', 'ARRAY', @asi, 'ad_import'); $dbh->func( 'bomtable', 'ARRAY', @bom, 'ad_import'); $dbh->func( 'mpttable', 'ARRAY', @mpt, 'ad_import'); $rdbtable_sth = $dbh->prepare( "SELECT SIGNAL_NAME,LOCATION,X_COORDINA +TE,Y_COORDINATE,Z_COORDINATE,COMPONENT_SIDE,ETCH_SIDE,GROUND,GROUND_L +OCATION FROM rdbtable" ); $asitable_sth = $dbh->prepare( "SELECT SIGNAL_NAME,LOCATION,REFERENC +E_DESIGNATOR,PIN_NUMBER,DEVICE_NAME,PACKAGE_TYPE,CS_PART_NUMBER FROM +asitable WHERE LOCATION = ?" ); $rdbtable_sth->execute; while (($location,$rdb_signal_name) = $rdbtable_sth->fetchrow_array) { $asitable_sth->execute($location); $row = $asitable_sth->fetchrow_arrayref; $asi_signal_name = $row ? $row->[0] : ''; print "$rdb_signal_name : $asi_signal_name\n"; }

    Here are the 2 tables:

    rdbtable:

    SIGNAL_NAME,LOCATION,X_COORDINATE,Y_COORDINATE,Z_COORDINATE,COMPONENT_SIDE,ETCH_SIDE,GROUND,GROUND_LOCATION
    A_AD0,BP1.19E25,-895.0390,3277.3700,0.0000,0,1,GND,BP1.19245
    A_AD0,F6_54.W4VIA,1825.0000,3975.0000,0.0000,0,1,GND,F6_54.W7VIA
    A_AD1,F6_54.Y3VIA,1775.0000,3925.0000,0.0000,0,1,GND,F6_54.AB4VIA
    A_AD1,BP1.18A3,-1210.0000,3513.5910,0.0000,0,1,,
    A_AD2,BP1.19C25,-1052.5200,3277.3700,0.0000,0,1,GND,BP1.19254
    A_AD2,F6_54.W3VIA,1825.0000,3925.0000,0.0000,0,1,GND,F6_54.AB4VIA

    asitable:

    SIGNAL_NAME,LOCATION,REFERENCE_DESIGNATOR,PIN_NUMBER,DEVICENAME,PACKAGE_TYPE,CS_PART_NUMBER
    A_AD0,F6_54.W4VIA,F6_54,W4,XC2V4000,BGA957XBTF-XC2V4000_9B,059-000-408
    A_AD1,F6_54.Y3VIA,F6_54,Y3,XC2V4000,BGA957XBTF-XC2V4000_9B,059-000-408
    A_AD2,F6_54.W3VIA,F6_54,W3,XC2V4000,BGA957XBTF-XC2V4000_9B,059-000-408
    A_AD3,F6_54.AA5VIA,F6_54,AA5,XC2V4000,BGA957XBTF-XC2V4000_9B,059-000-408
    A_AD4,F6_54.Y5VIA,F6_54,Y5,XC2V4000,BGA957XBTF-XC2V4000_9B,059-000-408
    A_AD5,F6_54.Y6VIA,F6_54,Y6,XC2V4000,BGA957XBTF-XC2V4000_9B,059-000-408

    Any suggestions for fixing what I have or better ways to handle this situation would be greatly appreciated.

    Thanks again,
    Jim

      Can't coerce array into hash at C:/Perl/site/lib/DBD/AnyData.pm line 247.

      This appears to be caused by the way my array of arrays is created.

      I am creating it in the following manner:

      $test[0][0] = 'No'; $test[0][1] = 'Letter'; $test[0][2] = 'Roman'; $test[1][0] = 1; $test[1][1] = 'a'; $test[1][2] = 'i'; $test[2][0] = 2; $test[2][1] = 'b'; $test[2][2] = 'ii'; $test[3][0] = 3; $test[3][1] = 'c'; $test[3][2] = 'iii'; $test[4][0] = 4; $test[4][1] = 'd'; $test[4][2] = 'iv'; $test[5][0] = 5; $test[5][1] = 'e'; $test[5][2] = 'v'; $test[6][0] = 6; $test[6][1] = 'f'; $test[6][2] = 'vi';

      I don't currently see what the difference is from the following (which works):

      @test = [ ['No','Letter','Roman'], [1,'a','i'], [2,'b','ii'], [3,'c','iii'], [4,'d','iv'], [5,'e','v'], [6,'f','vi'] ];

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-19 07:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found