Database layer?

Discussion corner for Developers of Serendipity.
Post Reply
francisco
Regular
Posts: 42
Joined: Thu Jul 21, 2005 9:33 pm

Database layer?

Post by francisco »

How is multi-DB handled?
I see that PostgreSQL has a number of issues.. starting with the way tables are defined.

Is there a DB layer?

I am no MySQL user, but I would be surprised if one had to cast a default in MysQL.

For example looking at one of the tables created by serendipity in my PostgreSQL DB I see
default 0::smallint
show_childpages | smallint | not null default 0::smallint

The casting to smallint, in my opinion, is not needed (for sure it is NOT needed in PostgreSQL)

Also I have seen in several parts of the code surrounding integers with quotes.. Numbers do not need to be surrounded by quotes.

WRONG:
inser into table_abc (int_field) value ('123')

CORRECT:
inser into table_abc (int_field) value (123)
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Database layer?

Post by garvinhicking »

We have a set of files in our include/db/ directory, where the functions define specific things for specific databases. This is a very ligthweight abstraction, no prepared statements and so on.

The smallint is just used because not all RDBMSes have a "boolean" type of field, so this was the most compatible way to go with.

We surround integers in quotes as well, because that way we can handle string and integer inserts with one function, and are less prone to SQL injections if everything is surrounded by quotes.

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply