gpt4 book ai didi

sqlite - 无法解析调用者 sqlite3_bind : Do not understand this error in my Perl 6 script

转载 作者:IT王子 更新时间:2023-10-29 06:27:23 25 4
gpt4 key购买 nike

脚本的用途:我希望能够使用它来将费用插入到 SQLite 数据库中,然后制作自定义报告以提取信息,以便更好地预算我的费用。

我完全不明白这个错误代码。

perl6 budgetpro.p6

Apple

An apple a day keeps the doctor away

Hi, I am Essential, nice to meet you, Eggman

Cannot resolve caller sqlite3_bind(DBDish::SQLite::Native::STMT, Int,
Date); none of these signatures match:
(DBDish::SQLite::Native::STMT $stmt, Int $n, Blob:D $b)
(DBDish::SQLite::Native::STMT $stmt, Int $n, Real:D $d)
(DBDish::SQLite::Native::STMT $stmt, Int $n, Int:D $i)
(DBDish::SQLite::Native::STMT $stmt, Int $n, Any:U)
(DBDish::SQLite::Native::STMT $stmt, Int $n, Str:D $d)
in method execute at /home/jon/opt/rakudo-star/share/perl6/site/sources/2D749062AA6D5641452CDA214FC7C566E7E3E2A1
(DBDish::SQLite::StatementHandle) line 38
in method insert at budgetpro.p6 line 54 in block <unit> at budgetpro.p6 line 86`
  2
3 use v6;
4 use DBIish;
5
6 constant DB = 'budgetpro.sqlite3';
7 my $dbh = DBIish.connect('SQLite', database => DB);
8
9 #$dbh.do('drop table if exists Essential, Savings, Personal');
10
11 sub create-schema {
12 $dbh.do(qq:to/SCHEMA/);
13 create table if not exists Essential(
14 id integer primary key not null,
15 name varchar not null,
16 quantity integer not null,
17 price numeric(5,2) not null,
18 description varchar not null,
19 date timestamp not null default (datetime('now'))
20 );
21 create table is not exists Savings(
22 id integer primary key not null,
23 name varchar not null,
24 quantity integer not null,
25 price numeric(5,2) not null,
26 description varchar not null,
27 date timestamp not null default (datetime('now'))
28 );
29 create table if not exists Personal(
30 id integer primary key not null,
31 name varchar not null,
32 quantity integer not null,
33 price numeric(5,2) not null,
34 description varchar not null,
35 date timestamp not null default (datetime('now'))
36 );
37 SCHEMA
38 }
39
40 create-schema;
41
42 class Item {
43 has $!table = 'Essential';
44 has $.name;
45 has $.quantity;
46 has $.price;
47 has $.description is rw;
48 has $.timestamp;
49 has Str $.notes is rw;
50 method notes() { "$!notes\n" };
51
52 method insert($name, $quantity?, $price?, $description?, $timestamp?) {
53 my $sth = $dbh.prepare("insert into Essential(name,quantity,price,description,date) values (?,?,?,?,?)");
54 $sth.execute($name, $quantity, $price, $description, $timestamp);
55
56 say "Inserted $name, $quantity, $price, $description, $timestamp";
57 }
58 }
59
60 class Essential is Item {
61 method greet($me: $person) {
62 say "Hi, I am $me.^name(), nice to meet you, $person";
63 }
64 }
65
66 class Savings is Item {
67 }
68
69 class Personal is Item {
70 }
71
72 my $food = Essential.new(
73 name => 'Apple',
74 price => .99,
75 quantity => 2,
76 notes => 'An apple a day keeps the doctor away'
77 );
78
79 say $food.name;
80 say $food.notes;
81 Essential.new.greet('Eggman');
82 say '';
83
84 my $test = Item.new();
85
86 $test.insert("Cheese", 2, 1.99, 'Block of cheddar', Date.new(now));
87
88 say $test.name;

最佳答案

问题是你调用了:

$test.insert("Cheese", 2, 1.99, 'Block of cheddar', Date.new(now));

最终会调用 sqlite3_bind,但没有一个候选对象接受 Date 的实例作为第三个参数。


它将接受 BlobIntReal 的实例(Numeric 但不是 复杂),或 Str。它还会接受未定义的值 (Any:U)。

在我看来,它不接受 DateTime 或什至可能是 Instant 对象,并且自动将其转换为 SQLite 所期望的。


我还想指出有 Date.todayDateTime.now。后者将跟踪当前时区信息,而 DateTime.new(now) 则不会。
(这是故意的,因为没有办法知道 Instant 来自哪里。)

关于sqlite - 无法解析调用者 sqlite3_bind : Do not understand this error in my Perl 6 script,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49522489/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com