Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
duck monster
Dec 15, 2004

Oben posted:

Well, gently caress. Is there a way to use views in MySQL 4, or do I really have to go in and somehow rewrite the database and php code that accesses it?

Views have changed my life. For serious. I used to *hate* writing SQL stuff in PHP, and in fact I still do.

Being an Object Oriented nut, I'm deeply fond of things like Active Record and its ilk. The problem with Active Record is that it tends to suck for complex queries.

So along comes Views and its all better now. You just use a view to turn a complex query into a simple minded query, and then your code magically starts being lovely and simple. The beauty of it is, since data tends to repeatedly be looked at the same way over and over, you just keep reuseing the same view.

Caveat: Beware of how agregation and parameterised querys nest when doing things like views of views.

code:
DROP VIEW IF EXISTS `<yourviewname>`;

CREATE
    VIEW `<yourviewname>` 
	AS 
            (
                 <stick some SQL in here>
             )
Copy and paste that poo poo, for instant View love. Its that easy. Also, views in theory are much faster than constantly feeding big querys over and over again into it. Pre-compilation or something. Not entirely sure why, but when we benchmarked it at work, the speed differences where outrageous at times.

Caveat. Views tend to dislike this sort of thing;- SELECT * FROM TABLE
Your better off using something like SELECT raraID,raraName,raraHeyMan FROM TABLE . This means you need to watch what happens with your views when you change the tables they are dependant on. If you add a field to a dependancy , you might need to add that field to the view. I tend to keep a views.txt file with my code project s that have copies of all the views inside them.

duck monster fucked around with this message at 22:30 on Nov 5, 2007

Adbot
ADBOT LOVES YOU

duck monster
Dec 15, 2004

Sort of on/off topic, BUT;-

If anyones ever wondered about how sql type databases actually work at the core, have a read of this;-

First read this;-
http://www.sqlite.org/arch.html
Then read this;-
http://www.sqlite.org/vdbe.html

Its on how the SQL engine in SQLLite's opcode system works. Its fascinating stuff, and really is quite enlightening the process of going from really high level SQL query, to snappy-as-gently caress low level data retrieval. Its amazing stuff (Probably more so , considering what a wonder that little database really is.)

Honestly, after having a dig around the *excelent* developer documentation for SQLLite, I now know a hell of a lot more about how these things work than I used to. Required reading.

duck monster
Dec 15, 2004

Does anyone know if its possible to get Multicorn (The Postgres plugin that lets you write Foreign Data Wrappers in python) working in Azures Postgress service? We have a giant legacy OSC OSI PI thing (Big ugly enterprisey timescale database thing) that we all hate using but its kinda core to our operation. We're toying with ideas how to cut that expensive crackpipe out and as a first step accessing it via a FTW means we can later on just move it to a local timescaledb table instance.

It might just be a hare brained scheme, but we'd like to try it.

duck monster
Dec 15, 2004

If your going into an existing codebase/deploy with an existing style guide, that is *always* going to be the one you want to use. snake_case and pluralized tables might be more logical, but in the scheme of things, its just a preference, and bucking the teams preference isn't a good way to remain employed.

And yeah, I prefer just using id for the index too, because it means theres always a predictable pk, but again, its a preference, and mob rules when it comes to teamwork.

duck monster
Dec 15, 2004

Y'all fools aint seen nothing till you've worked with a database designed by scientists. Horrors without end.

"I just copied the field names from excel but for some reason it wont let me use spaces"

"I just put the code in a text field and then use pythons exec command to run it"

"Ever Their praises, and abundance to the Black Goat of the Woods. Iä! Shub-Niggurath! Iä! Shub-Niggurath! The Black Goat of the Woods with a Thousand Young"

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply