Wow, this works great... My project needed to account for the client to be able to adjust the jobNumber (primary key from the sequence) each year... ie. 100001 is 2010....11001 is 2011...
Personally I hope they are not using this system in two years.... but instead have migrated to a full blown enterprise system (and then I will be surprised when I see them using it for 5 years...) Ted --- On Sun, 4/18/10, Louis Demers <[email protected]> wrote: From: Louis Demers <[email protected]> Subject: Re: raw SQL??? To: "Theodore Petrosky" <[email protected]> Cc: [email protected] Date: Sunday, April 18, 2010, 2:31 PM Wow, for once, I might actually be able to help 8-) On 2010-04-18, at 14:21 , Theodore Petrosky wrote: I have been googling on rawRowsForSql examples. Can someone point me in the direction of an example. I want to execute: SELECT SETVAL('t_table_seq', 10001); that's it.... I could use a little help... Here is a fragment that I use to create the sequence and another one to retrieve the next number. The method used to create the sequence also set it to 1. This is used with PostgreSQL. //__________________________________________________________________________________________________________________ public Boolean createSequence(String seq) { Integer num; NSArray rawResults; String sqlCreate; sqlCreate = "CREATE SEQUENCE " + seq + "\n INCREMENT BY 1 \n NO MAXVALUE \n NO MINVALUE \n CACHE 1;\n" + "ALTER TABLE public." + seq + " OWNER TO postgres;\n" + "SELECT pg_catalog.setval('" + seq + "', 1, true);"; try { rawResults = EOUtilities.rawRowsForSQL(this.defaultEditingContext(), "Obzerv", sqlCreate, null); NSDictionary oneRow = (NSDictionary) rawResults.objectAtIndex(0); log.debug("oneRow " + oneRow); return true; } catch (Exception e) { // Creation Failed ?. return false; } } //___________________________________________________________________ public Integer nextSequenceNumber2(String seq) { Integer num; NSArray rawResults; String sqlSentence; sqlSentence = String.format("select nextval ('%s');", seq); try { rawResults = EOUtilities.rawRowsForSQL(this.defaultEditingContext(), "Obzerv", "select nextval ('" + seq + "');", null); NSDictionary oneRow = (NSDictionary) rawResults.objectAtIndex(0); log.debug("oneRow " + oneRow); log.debug("nextval " + oneRow.valueForKey("NEXTVAL")); num = new Integer(((BigDecimal) (oneRow.valueForKey("NEXTVAL"))).intValue()); } catch (Exception e) { // deal appropriately ... return null; } return num; } _______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list ([email protected]) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to [email protected]
