Perl and MySQL commands

Software related topics

Perl and MySQL commands

Postby Alfredo Tigolo » Mon Oct 12, 2015 6:28 pm

http://www.perl.com/pub/1999/10/DBI.html

The cool thing about the link above, it shows an example of connecting perl with MySQL commands. Hopefully, it is possible to have my own working example with my 'automotive' test data
Alfredo Tigolo
 
Posts: 2
Joined: Fri Oct 09, 2015 12:01 pm
Location: California

Re: Perl and MySQL commands

Postby Doug Coulter » Tue Oct 13, 2015 12:25 pm

Yes, perl's DBI module totally rocks. It will even allow things to be done in bulk, and most of the code is actually C(++) in there to be as fast as possible. I use it extensively in the "Lan of Things" project, and plan to keep using it as I install more units.
The SQL database (I use mySQL here) need not be on the same machine - which makes that "bulk" feature more worthwhile, due to lan overhead etc.
Here's some code that uses it: viewtopic.php?f=59&t=904&start=20#p5576
This is the code in the office trailer pi that gets data from an arduino, and an internal sensor (that's the ugly part...I tried to rewrite someone else's unbelievably bad code, but it's still ugly for that sensor - partly because the sensor needs your code to even come up with useful numbers, temperature compensate and so on) and puts it in a local mysql database. CGI programs (also perl) on that machine serve up the data to anyone on the LAN by querying the same database. I'm using NGINX (and FastCGI) and phpmyadmin for the other major pieces. All this barely loads a pi-b2 - and would probably run on the older single-core version just fine - I'll know soon as I have one in the battery box getting data from there and controlling the cooling system on the backup generator - may as well find uses for the old model pi's I've got already.

Here's a slide from a presentation I'm going to have to find the link to the rest of.
SQLBulk.png
Bulk SQL for speed

And I got lucky and found the link: http://www.slideshare.net/Tim.Bunce/dbi ... orial-2007

Of course, none of this absolves you from having to learn SQL and other things like how to design databases to 3rd normal form and so on. This is just how we talk to them.
SQL is its own world...and not all vendors speak the same version of it. MySql (and now mariaDB), PostgreSQL, etc have pretty good reputations for following the standard. Oracle is heavy into the "embrace, extend, extinguish" mode. Once you've gone full Oracle (eg full retard) it's very hard to switch vendors, as they encourage you to use all kinds of non-standard-compliant stuff they added. I've had similar issues with Microsoft's SQL server, and even Access. It's easy to go from standards-complaint DB to one of those, but once things have gone along for awhile, and you've added this or that thing they recommend you do in their dox, you can't go back easily at all. You have been warned.
Posting as just me, not as the forum owner. Everything I say is "in my opinion" and YMMV -- which should go for everyone without saying.
User avatar
Doug Coulter
 
Posts: 2964
Joined: Wed Jul 14, 2010 8:05 pm
Location: Floyd county, VA, USA


Return to Software

Who is online

Users browsing this forum: No registered users and 1 guest