v icon indicating copy to clipboard operation
v copied to clipboard

C error with sqlite

Open crat1985 opened this issue 2 years ago • 1 comments

Describe the bug

I got a C error while using sqlite.

Expected Behavior

The code to compile.

Current Behavior

==================
/tmp/v_1000/ReportBug.9606162841963709712.tmp.c:16366: error: ',' expected (got ";")
...
==================
(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

Reproduction Steps

module main

import db.sqlite

struct Account {
	id int [nonnull; primary]
}

fn main() {
	db := sqlite.connect("test.db")!
	sql db {
		create table Account
	}

	_ := sql db {
		select from Account where id == 0 limit 1
	}[0]
}

Possible Solution

No response

Additional Information/Context

There is only an error when there is the [0].

V version

V 0.3.3 a552a79

Environment details (OS name and version, etc.)

V full version: V 0.3.3 7939ca2.a552a79
OS: linux, Zorin OS 16.2
Processor: 2 cpus, 64bit, little endian, Intel(R) Celeron(R) N4020 CPU @ 1.10GHz

getwd: /home/riccardo
vexe: /home/riccardo/v/v
vexe mtime: 2023-03-22 18:51:54

vroot: OK, value: /home/riccardo/v
VMODULES: OK, value: /home/riccardo/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.25.1
Git vroot status: weekly.2023.12-14-ga552a79c
.git/config present: true

CC version: cc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

crat1985 avatar Mar 22 '23 20:03 crat1985

There is no error if the [0] is removed after the closing } on the 2nd sql.db call.

The question is whether or not this code should work as-is. If it should, the bug needs to be fixed. If it shouldn't V needs to give a useful error message.

JalonSolov avatar Mar 22 '23 22:03 JalonSolov

I think this should be a V error because you shouldn't index queries like that.

Delta456 avatar Mar 30 '23 08:03 Delta456