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;
}
//_________________________________________________________________________________________________________________
>
> Ted
>
>
>
> _______________________________________________
> 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/louisdemers%40mac.com
>
> This email sent to [email protected]
Louis Demers eng.
www.obzerv.com
_______________________________________________
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]