1.\"	$Id: ksql_lastid.3,v 1.8 2018/04/20 21:25:01 kristaps Exp $
2.\"
3.\" Copyright (c) 2016, 2018 Kristaps Dzonsons <kristaps@bsd.lv>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.Dd $Mdocdate: April 20 2018 $
18.Dt KSQL_LASTID 3
19.Os
20.Sh NAME
21.Nm ksql_lastid
22.Nd get the last insertion row identifier
23.Sh LIBRARY
24.Lb ksql
25.Sh SYNOPSIS
26.In sys/types.h
27.In stdint.h
28.In ksql.h
29.Ft "enum ksqlc"
30.Fo ksql_lastid
31.Fa "struct ksql *sql"
32.Fa "int64_t *id"
33.Fc
34.Sh DESCRIPTION
35The
36.Nm
37function fills in
38.Fa id
39with the row identifier of the last insertion.
40If
41.Fa id
42is
43.Dv NULL ,
44then this does nothing, except that the return value still indicates
45whether the database is open.
46If no row was successfully inserted since the database
47.Fa sql
48was opened,
49.Pf * Fa id
50is set to 0.
51.\" .Sh CONTEXT
52.\" For section 9 functions only.
53.\" .Sh IMPLEMENTATION NOTES
54.\" Not used in OpenBSD.
55.Sh RETURN VALUES
56The
57.Nm
58function returns
59.Dv KSQL_NOTOPEN
60if the database is not open or
61.Dv KSQL_OK
62otherwise.
63.\" For sections 2, 3, and 9 function return values only.
64.\" .Sh ENVIRONMENT
65.\" For sections 1, 6, 7, and 8 only.
66.\" .Sh FILES
67.\" .Sh EXIT STATUS
68.\" For sections 1, 6, and 8 only.
69.Sh EXAMPLES
70The following assumes an open database
71.Va sql .
72It inserts a row and checks its row identifier.
73For brevity, it performs no error checking.
74.Bd -literal
75int64_t id;
76struct ksqlstmt *stmt;
77
78ksql_stmt_alloc(sql, &stmt,
79  "INSERT INTO test (foo) VALUES (?)", 0);
80ksql_bind_int(stmt, 0, 42);
81ksql_stmt_step(stmt);
82ksql_lastid(sql, &id);
83
84printf("The last rowid = %" PRId64 "\en", id);
85.Ed
86.\" .Sh DIAGNOSTICS
87.\" For sections 1, 4, 6, 7, 8, and 9 printf/stderr messages only.
88.\" .Sh ERRORS
89.\" For sections 2, 3, 4, and 9 errno settings only.
90.Sh SEE ALSO
91.Xr sqlite3_last_insert_rowid 3
92.\" .Xr foobar 1
93.\" .Sh STANDARDS
94.\" .Sh HISTORY
95.\" .Sh AUTHORS
96.\" .Sh CAVEATS
97.\" .Sh BUGS
98.\" .Sh SECURITY CONSIDERATIONS
99.\" Not used in OpenBSD.
100