db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tobr...@transolutions.net (O'brien, Tim)
Subject SQL Generation
Date Fri, 29 Nov 2002 21:10:02 GMT
I'm trying to get OJB working with SQL, and I ran into a what I'd
consider a small bug. (Although, I will admit the problem may be my own
studipity.) I'll be talking in PostgreSQL, but I'd imagine that this
problem could popup in a number of databases.

Assume for a moment that someone wants to create a table to model
Timezone,

	-- Table: timezone
	CREATE TABLE "timezone" (
  		"timezone_id" int4 NOT NULL, 
  		"offset" float8 NOT NULL, 
  		"region" varchar(128) NOT NULL, 
  		CONSTRAINT "PK_timezone_id" PRIMARY KEY ("timezone_id")
	); 

And, using P6SPY to look at a SQL statement that OJB generates we get:

	"SELECT A0.region,A0.offset,A0.timezone_id FROM timezone A0"

PostgreSQL will choke on "offset" because it is a keyword....

There are two solutions to this problem:

1. Tell people not to use keywords as column or table names.

2. Surround all column and table names with double quotes.  

--------
Tim O'Brien 
Transolutions, Inc.
18 N Waukegan Road
Lake Bluff, Il 60044
W 847-574-2143
F 847-234-3471
M 847-863-7045




Mime
View raw message