Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cgen: mutable + array + database = error #16364

Open
enghitalo opened this issue Nov 8, 2022 · 3 comments
Open

cgen: mutable + array + database = error #16364

enghitalo opened this issue Nov 8, 2022 · 3 comments

Comments

@enghitalo
Copy link
Contributor

V doctor:

OS: linux, Ubuntu 22.04.1 LTS
Processor: 8 cpus, 64bit, little endian, 11th Gen Intel(R) Core(TM) i7-11390H @ 3.40GHz
CC version: cc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0

getwd: /home/hitalo/Documents/bugs no v/mut_error
vmodules: /home/hitalo/.vmodules
vroot: /home/hitalo/v
vexe: /home/hitalo/v/v
vexe mtime: 2022-11-07 15:12:13
is vroot writable: true
is vmodules writable: true
V full version: V 0.3.2 bf00e9b.5f33585

Git version: git version 2.34.1
Git vroot status: weekly.2022.45 (5 commit(s) behind V master)
.git/config present: true
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

What did you do?
v -g -o vdbg cmd/v && vdbg main.v

module main

import sqlite

[table: 'taskx']
struct Task {
mut:
	id            u32    [primary; serial; sql: serial]
	frequency     string [required; sql_type: 'varchar(10)']
	deadline_hhmm string [required; sql_type: 'varchar(5)']
}

pub fn create_db_connection() !sqlite.DB {
	mut db := sqlite.connect('databasx.db')!
	return db
}

fn main() {
	mut db := create_db_connection() or { panic(err) }

	sql db {
		create table Task
	} or { panic('error on create table: $err') }

	mut tasks_model := [Task{
		frequency: 'a'
		deadline_hhmm: 'b'
	}]

	for mut task_model in tasks_model {
		sql db {
			insert task_model into Task
		} or { eprintln('Error on insert tasks: \n$err') }
	}

	// sql db {
	// 	insert tasks_model[0] into Task
	// } or { eprintln('Error on insert tasks: \n$err') }
}

What did you expect to see?

task_model inserction

What did you see instead?

==================
/tmp/v_1000/main.10870584657395213853.tmp.c:42359: error: struct or union expected
...
==================
(Use `v -cg` to print the entire error message)

builder error: 
==================
C error. This should never happen.

This is a compiler bug, please report it using `v bug file.v`.

https://github.com/vlang/v/issues/new/choose

You can also use #help on Discord: https://discord.gg/vlang

@jacksonmowry
Copy link
Contributor

It looks like the error has since been updated to now say error: can only insert variables, where the datatype of tasks_model[0] is an expression. Should the orm support inserting expressions directly?

@enghitalo
Copy link
Contributor Author

Hi, @jacksonmowry. Are you facing a problem like that right now? Can you try using an indexed variable ?

@jacksonmowry
Copy link
Contributor

Oh no, I was just working through some of the issues in the backlog seeing which ones we can close.

It looks likes the original error you had has at least been translated into a V error now, which is better. From the new error message I assume this is the intended behavior, but I was planning to ask.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants