Pages

Hubert Lubaczewski: explain.depesz.com - update

I just updated explain.depesz.com with the newest explain-parsing library version (Pg::Explain v 0.09). This version will hit CPAN mirrors in next couple of hours. Changes: Fix exclusive time calculations Make PE::Node understand Bitmap scans (heap and index) Add proper handling of nodes that were “never executed” Add ->is_analyzed method to PE::Node to make it easy to distinguish between EXPLAIN and EXPLAIN [...]

Pavel Golub: PgMDD-1.2.8: Wine out of the box


Preface

As was mentioned PgMDD entered beta-testing stage. Details have been promised. Voilà.

Crux of the matter

PgMDD-1.2.8 supports WineHQ out of the box. What mean supports?

  • PgMDD always knows if it was launched under Wine or in pure Windows environment
  • PgMDD offers several ways to bypass imperfect Wine functionality
  • PgMDD disables the functionality which current Wine configuration cannot provide

Lets go on each item.

Imperfect functionality

Despite the fact of hh.exe (Wine’s HTML Help viewer) existence you probably will be absolutely disappointed with it’s functionality.

Because of this PgMDD will ask you about way you want to get help. You may choose on-line sources or use CHM file shipped with installation.

Step 1

Step 1

Missing functionality

How can this happen? Often redistributable runtime libraries are needed to run programs in Wine. At this moment PgMDD needs MS MDAC for “MS Access Reverse Engineering” functionality. In a clean Wine package there is no MDAC installed. However, you always may do this using winetricks script. I already wrote post about winetricks using.

In current version “MS Access Reverse Engineering” functionality will be disabled till MDAC is installed. After that this functionality will be automatically enabled. (In pre-1.2.8 MDAC was required for actual installation of the Designer)

Step 2

Step 2

DreamCoder for PostgreSQL ver 2.0 is now available

Mentat Technologies is happy to announce the new version of DreamCoder for PostgreSQL version 2.0, a powerful Windows solution for PostgreSQL administration and database development.

Magnus Hagander: pgcon photos

Just a quick note to let people know I have uploaded my photos from pgcon. They're not as many as last year, and not really good, but there are at least some for people to look at :-)

I have only started tagging up names. If you know more of them, just drop me an email with photo link and name. Thanks!

Dane Foster: PGCon2009 Postscript: Unit Test Your Database!

I started watching some of the PGCon2009 videos that I didn't attend while at PGCon. Last night I watched, Unit Test Your Database!, by David Wheeler. I have had my come to Jesus moment on unit testing years ago, so I'm really happy that there is a solution for testing strictly at the database level without depending on the application layer. Some developers make the mistake of treating the

Josh Berkus: pgCon 2009 part 2

Thursday. Dave, Magnus and Selena gave their keynote, which was more funny than anything else. Dan also announced that pgCon would be sponsoring the Website Design Contest. Then we had 6 hours of sessions. Going to an all-PostgreSQL conference is painful; in every time slot I have to pick the two talks I'm not going to see.

Josh Berkus: pgCon 2009 part 1

Wow, pgCon is already over and I'm on my way home. This year's conference flew by, an intense journey of tutorials, meetings, sessions, dinners and one big party. And one big blur of 1am discussions of Postgres hacking at the Royal Oak over pitchers of Rickard's Red.

Thor Michael Støre: TMDBC: Extending the Java compiler to handle SQL


Some few years ago I was developing a database backed Java application and grew annoyed at how cumbersome interacting with a database really was in that language. I just wanted to interface with SQL using Java call semantics and native Java objects. I didn’t want to have to write dumb container objects copying the result set type in those cases where that was all I needed, and under no circumstance did I want write anything to copy data back and forth, neither code nor any kind of configuration to explain to some tool how to do that. I just wanted a simple, boilerplate-free and seamless way to run SQL commands from Java, kind of like running SQL from PL/pgSQL is.

Additionally, since I was working in Java I expected that everything would be statically checked. I expected types to be checked between the database and application and that all SQL in the application would be verified against the database without having to do anything such as set up tests or, again, write configuration or something. For example syntax errors in SQL commands in the application or passing a Java string to a date field in a SQL command should generate a compile time error.

So I started tinkering on my spare time, and ended up with an approach relying on the metaprogramming facilities in Java to simply take SQL commands and Java method signatures and figure out how to connect them. Others have used similar approaches too, in Java and other languages; those that follow Planet PostgreSQL might have noticed Aurynn Shaws Simpycity for tool Python, which operates in the same fashion despite being simpler.

The tool is accidentally named TMDBC, and consists of a compile time and runtime library. The compile time is technically implemented as a code generating Java 6/JSR 269 annotation processor, a consequence of which is that it’s invoked by the Java compiler when it detects the relevant annotations, and while the run time is actually optional you won’t have all the fun without it. It has been developed against PostgreSQL and only tested successfully against that.

The implementation still has a few rough edges, but it’s quite usable and since you can mix that approach and plain JDBC in the same transaction using it shouldn’t introduce any hurdles. I feel quite confident in that there aren’t any severe, outstanding issues.

Enough ranting, code here

Here’s an example. If the use-cases one were to satisfy required that one could fetch a single entry, a range of entries or a list of entries from a “employee” table then a complete example that satisfies everything I’ve mentioned could be:

package test;

import java.util.List;
import no.thormick.tmdbc.annotation.*;

@JDBC( // Connection to development database, not production
  driver = "org.postgresql.Driver",
  value = "jdbc:postgresql://localhost/postgres?user=test&password=test" )
@DBAPI public interface MinimalDBI {
    // abstract class also works and is more flexible
    @SQL(
        "SELECT name, salary, emp_id\n" +
        "FROM   employee\n" +
        "WHERE  emp_id = ?")
    Employee getEmployee( int empId );

    @SQL(
        "SELECT name, salary, emp_id\n" +
        "FROM   employee\n" +
        "WHERE  emp_id BETWEEN ? AND ?")
    List<Employee> getEmployees( int empIdLow, int empIdHigh );

    @SQL(
        "SELECT name, salary, emp_id\n" +
        "FROM   employee\n" +
        "WHERE  emp_id = ANY ( ? )")
    List<Employee> getEmployees( int[] empIds );
}

And that’s everything, done, no configuration files anywhere. When this is compiled an implementation of this interface as well as the “Employee” class will be generated (unless you supply it, in which case it will be type-checked against the result set). If there’s a type error between a SQL command and Java method or if PostgreSQL finds something wrong with a SQL command, then a compile error will be signaled. To use it, the following would suffice (the connection handling here is just the simplest way to do it, other more transparent approaches are supported):

package test;

import java.sql.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Class.forName("org.postgresql.Driver");
        Connection conn = null;
        try {
            // This, on the other hand, is the production connection
            conn = DriverManager.getConnection(
                "jdbc:postgresql://localhost/postgres?" +
                "user=test&password=test");
            // Handling the connection like this is just one way to do it
            MinimalDBI db = new MinimalDBIImpl(conn);

            System.out.println("One employee:");

            Employee employee = db.getEmployee(2);
            System.out.println("Employee "+ employee.getEmpId() +": "+
                               employee.getName() +", "+ employee.getSalary() );

            System.out.println("Two employees:");

            for(Employee emp : db.getEmployees(new int[]{1,3}) ){
                System.out.println( "Employee "+ emp.getEmpId() +": "+
                                    emp.getName() +", "+ emp.getSalary() );
            }
        } finally {
            if( conn != null )
                conn.close();
        }
    }
}

Note how the class “MinimalDBIImpl” is instantiated. This is the generated database interface class (the name can be set by passing an argument to the DBAPI annotation) and contains the glue between Java and SQL (or JDBC, to be precise.)

That example might produce output like the following:

One employee:
Employee 2: Bar, 60
Two employees:
Employee 1: Foo, 50
Employee 3: Bruce, 70

This example is very minimalistic. Using a interface for the @DBAPI class makes TMDBC use some (hopefully reasonable) defaults for the implementation, an abstract class can be used for more flexibility. Java collection types are used, which causes the results to be materialized, but there are runtime library classes that can be used instead to return connected objects, pretty much a cursor that returns JavaBeans. To use that instead just change the return-type in the method signatures from “List” to “ResultStatement“. Those can be used in a for each loop like above too.

The web page for the tool is here, and there’s also JavaDoc for the API. I’ve written a considerably more elaborate example on how to use TMDBC together with GlassFish to create a PostgreSQL backed Web Service, also demonstrating a different way to handle connections.

Have fun with it!

Andrew Dunstan: Giggle

One of the most amusing presentations at pgcon was Josh Tolley's lightning talk. I guess it's not surprising that this should be so, as he is also the author of PL/LOLcode ("kthxbye"). This talk was entitled "How not to review a patch" and the video is now available at http://hosting3.epresence.tv/fosslc/1/watch/125.aspx at about slide #246. If you weren't there, check it out - it's a hoot.

Robert Treat: Reflections on PGCon 2009

Well, another PGCon has come and gone. I always find it ironic how you struggle to cross the finish line, exhausted after such a long week, and yet really it goes by so quickly; one certainly doesn't have time to reflect while at the conference. Actually my Monday was a perfact foreshadow of the week to come; get to the airport early to make a conference call, only to realize I forgot my boarding pass and then scambling to make the flight. As normal I landed in Ottawa completely unprepared for actually getting from the airport to campus, but was once again bailed out, running into Stephen Frost, whose flight had gotten bumped so he ended up on my plane, and so I hitched a ride with him into the city. My Tuesday would have similar ups and downs, spending a lot of hours on work projects, catching some of the tutorials for the day, some disorganized dinner plans, and then finally breaking bread with some of the Etsy crew with whom I've been working with recently.


Continue reading "Reflections on PGCon 2009"