The Artima Developer Community
Sponsored Link

Python Buzz Forum
Optimising how you write your code so SQL doesn't hurt so much to use

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Phillip Pearson

Posts: 1083
Nickname: myelin
Registered: Aug, 2003

Phillip Pearson is a Python hacker from New Zealand
Optimising how you write your code so SQL doesn't hurt so much to use Posted: Feb 14, 2005 10:38 AM
Reply to this message Reply

This post originated from an RSS feed registered with Python Buzz by Phillip Pearson.
Original Post: Optimising how you write your code so SQL doesn't hurt so much to use
Feed Title: Second p0st
Feed URL: http://www.myelin.co.nz/post/rss.xml
Feed Description: Tech notes and web hackery from the guy that brought you bzero, Python Community Server, the Blogging Ecosystem and the Internet Topic Exchange
Latest Python Buzz Posts
Latest Python Buzz Posts by Phillip Pearson
Latest Posts From Second p0st

Advertisement

I used to not like using SQL, because it meant so many lines of code to do anything. Now I have some helper functions, and just about anything is very easy.

In Python:

z, = db.query_one("SELECT a FROM foo WHERE id=%d", (myid,))

for a,b,c in db.execute("SELECT a,b,c FROM foo"): ...

In PHP:

list($z) = query_one("SELECT a FROM foo WHERE id=?", array($myid));

$sth = query("SELECT a,b,c FROM foo"); while ($r = qrow($sth)) { list($a, $b, $c) = $r; ... }

I'll leave the implementation of the execute, query and qrow functions to the reader; they're not hard. But setting your code up so that you can do SQL queries with as little work as possible will completely change how it "feels" to work with an SQL database.

Comment

Read: Optimising how you write your code so SQL doesn't hurt so much to use

Topic: Camera back Previous Topic   Next Topic Topic: How MySQL fails to optimise LIMIT

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use