mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
cgen: fix hardcoded db__pg__DB_last_id for x := sql db { insert address into Address }
(fix #22583) (#22582)
This commit is contained in:
parent
d1b0370166
commit
380500a76b
2 changed files with 34 additions and 3 deletions
|
@ -421,3 +421,36 @@ fn test_i64_primary_field_works_with_insertions_of_id_0() {
|
|||
assert users.len == 2
|
||||
// println("${users}")
|
||||
}
|
||||
|
||||
struct Address {
|
||||
id i64 @[primary; sql: serial]
|
||||
street string
|
||||
number int
|
||||
}
|
||||
|
||||
fn test_the_result_of_insert_should_be_the_last_insert_id() {
|
||||
db := sqlite.connect(':memory:')!
|
||||
address := Address{
|
||||
street: 'abc'
|
||||
number: 123
|
||||
}
|
||||
dump(address)
|
||||
sql db {
|
||||
create table Address
|
||||
} or {}
|
||||
aid1 := sql db {
|
||||
insert address into Address
|
||||
} or { panic(err) }
|
||||
dump(aid1)
|
||||
aid2 := sql db {
|
||||
insert address into Address
|
||||
} or { panic(err) }
|
||||
dump(aid2)
|
||||
assert aid2 == 2
|
||||
addresses := sql db {
|
||||
select from Address
|
||||
}!
|
||||
dump(addresses)
|
||||
assert addresses.len == 2
|
||||
assert addresses.all(it.street == 'abc' && it.number == 123)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue