[Ur] Sequences
Yves Cloutier
yves.cloutier at gmail.com
Fri Apr 1 20:31:14 EDT 2016
Hello,
I would like to refactor some code to use a sequence instead of manually
incrementing a counter to serve as a unique db table index.
Following an example, I simply did:
...
sequence expId
...
Then when I want to increment:
...
nextId <- nextval expId;
...
I recompile, but when I execute I get the following error:
Fatal initialization error: Sequence 'uw_Portfolipro_expId' does not exist.
IS there something else that I need to do, create or initialise in order to
use sequences?
Below is my full code:
table experienceTable : { Id : int, Description : string}
PRIMARY KEY Id
sequence expId
fun refresh () =
rows <- queryX (SELECT * FROM experienceTable)
(fn row => <xml><tr>
<td>{[row.ExperienceTable.Id]}</td>
<td>{[row.ExperienceTable.Description]}</td>
<td><form><submit action={deleteExperience
row.ExperienceTable.Id} value="Delete"/></form></td>
</tr></xml>);
return <xml>
<table border=1>
<tr> <th>Id</th> <th>Description</th></tr>
{rows}
</table>
<br/><hr/><br/>
<form>
<table>
<tr> <th>Description:</th><td><textbox{#Description}/></td> </tr>
<tr> <th/> <td><submit action={addExperience} value="Add"/></td>
</tr>
</table>
</form>
</xml>
(* Add a new experience *)
and addExperience experience =
nextId <- nextval expId;
dml (INSERT INTO experienceTable (Id, Description)
VALUES ({[nextId]}, {[readError experience.Description]}));
page <- refresh ();
return <xml><body>
{page}
</body></xml>
(* Delete a given experience *)
and deleteExperience experienceId () =
dml (DELETE FROM experienceTable
WHERE t.Id = {[experienceId]});
page <- refresh ();
return <xml><body>
{page}
</body></xml>
fun main () =
content <- refresh ();
return <xml><body>
{content}
</body></xml>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.impredicative.com/pipermail/ur/attachments/20160401/3ed8213a/attachment.html>
More information about the Ur
mailing list