热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

无法解析调用者sqlite3_bind:在Perl6脚本中无法理解此错误

如何解决《无法解析调用者sqlite3_bind:在Perl6脚本中无法理解此错误》经验,为你挑选了2个好方法。

脚本的目的:我希望能够使用它将费用插入到SQLite数据库中,然后再制作自定义报告以提取信息,这样我就可以更好地预算我的费用.

我根本不明白这个错误代码.

perl6 budgetpro.p6

苹果

一天一苹果,医生远离我

嗨,我很精干,很高兴见到你,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  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;

Brad Gilbert.. 7

问题是你打来电话:

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

最终会调用sqlite3_bind,但没有候选者接受Date第三个参数的实例.


它会接受的一个实例Blob,Int,Real(Numeric但不是Complex),或Str.它也会接受一个未定义的值(Any:U).

在我看来,它是数据库驱动程序中的一个错误或缺少的功能,它不接受DateTime或甚至可能是一个Instant对象,并自动将其转换为SQLite期望的内容.


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



1> Brad Gilbert..:

问题是你打来电话:

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

最终会调用sqlite3_bind,但没有候选者接受Date第三个参数的实例.


它会接受的一个实例Blob,Int,Real(Numeric但不是Complex),或Str.它也会接受一个未定义的值(Any:U).

在我看来,它是数据库驱动程序中的一个错误或缺少的功能,它不接受DateTime或甚至可能是一个Instant对象,并自动将其转换为SQLite期望的内容.


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



2> jjmerelo..:

@Brad Gilbert是对的.语句只允许5种数据结构,而且都不是Date.TIME并且DATE是SQL中的标准数据类型,但目前它们似乎没有DBIish支持.在这种情况下,您只需将第85行更改为

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

让你的程序处理日期转换,你也必须改变Essential表的定义.您还可以让数据库处理默认值.你必须消除"not null",因为它与default句子冲突.

还有一些小错误.这个,减少到最小表达式,工作并将默认时间戳正确插入数据库(通过使用sqlite3命令行检查):

use v6;
use DBIish;

constant DB = 'budgetpro.sqlite3';
my $dbh = DBIish.connect('SQLite', database => DB);

#$dbh.do('drop table if exists Essential, Savings, Personal');

sub create-schema {
    $dbh.do(qq:to/SCHEMA/);
        create table if not exists Essential(
            id          integer primary key not null,
            name        varchar not null,
            quantity    integer not null,
            price       numeric(5,2) not null,
            description varchar not null,
            date        timestamp default (datetime('now'))
        );
    SCHEMA
}

create-schema;

class Item {
    has $!table = 'Essential';
    has $.name;
    has $.quantity;
    has $.price;
    has $.description is rw;
    has $.timestamp;
    has Str $.notes is rw;
    method notes() { "$!notes\n" };

    method insert($name, $quantity?, $price?, $description?, $timestamp?) {
        my $sth = $dbh.prepare("insert into Essential(name,quantity,price,description) values (?,?,?,?)");
        $sth.execute($name, $quantity, $price, $description);

        say "Inserted $name, $quantity, $price, $description";
    }
}

Item.new().insert("Cheese", 2, 1.99, 'Block of cheddar');

请注意,您的Item类实际上并不是通过运行insert句子来实例化的,因此$test.name在最后一行中只返回一个空对象,其默认值分配给实例变量.您可能要改变insert的方法来实例化项的子方法它插入到数据库中.


推荐阅读
  • 阿,里,云,物,联网,net,core,客户端,czgl,aliiotclient, ... [详细]
  • 高质量SQL书写的30条建议
    本文提供了30条关于优化SQL的建议,包括避免使用select *,使用具体字段,以及使用limit 1等。这些建议是基于实际开发经验总结出来的,旨在帮助读者优化SQL查询。 ... [详细]
  • 本文介绍了在使用Laravel和sqlsrv连接到SQL Server 2016时,如何在插入查询中使用输出子句,并返回所需的值。同时讨论了使用CreatedOn字段返回最近创建的行的解决方法以及使用Eloquent模型创建后,值正确插入数据库但没有返回uniqueidentifier字段的问题。最后给出了一个示例代码。 ... [详细]
  • 本文提供了关于数据库设计的建议和注意事项,包括字段类型选择、命名规则、日期的加入、索引的使用、主键的选择、NULL处理、网络带宽消耗的减少、事务粒度的控制等方面的建议。同时还介绍了使用Window Functions进行数据处理的方法。通过遵循这些建议,可以提高数据库的性能和可维护性。 ... [详细]
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • 使用Ubuntu中的Python获取浏览器历史记录原文: ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • 本文详细介绍了Spring的JdbcTemplate的使用方法,包括执行存储过程、存储函数的call()方法,执行任何SQL语句的execute()方法,单个更新和批量更新的update()和batchUpdate()方法,以及单查和列表查询的query()和queryForXXX()方法。提供了经过测试的API供使用。 ... [详细]
  • ALTERTABLE通过更改、添加、除去列和约束,或者通过启用或禁用约束和触发器来更改表的定义。语法ALTERTABLEtable{[ALTERCOLUMNcolu ... [详细]
  • MyBatis多表查询与动态SQL使用
    本文介绍了MyBatis多表查询与动态SQL的使用方法,包括一对一查询和一对多查询。同时还介绍了动态SQL的使用,包括if标签、trim标签、where标签、set标签和foreach标签的用法。文章还提供了相关的配置信息和示例代码。 ... [详细]
  • 解决.net项目中未注册“microsoft.ACE.oledb.12.0”提供程序的方法
    在开发.net项目中,通过microsoft.ACE.oledb读取excel文件信息时,报错“未在本地计算机上注册“microsoft.ACE.oledb.12.0”提供程序”。本文提供了解决这个问题的方法,包括错误描述和代码示例。通过注册提供程序和修改连接字符串,可以成功读取excel文件信息。 ... [详细]
  • 本文讨论了在使用Git进行版本控制时,如何提供类似CVS中自动增加版本号的功能。作者介绍了Git中的其他版本表示方式,如git describe命令,并提供了使用这些表示方式来确定文件更新情况的示例。此外,文章还介绍了启用$Id:$功能的方法,并讨论了一些开发者在使用Git时的需求和使用场景。 ... [详细]
  • 获取时间的函数js代码,js获取时区代码
    本文目录一览:1、js获取服务器时间(动态)2 ... [详细]
  • 工作用可能会用到会话分组:Message是消息实体对象,里面有toId和fromId指明接收方ID和发送方Id,通过组合形式“12-22-”为map的key其中Mess ... [详细]
  • 目录浏览漏洞与目录遍历漏洞的危害及修复方法
    本文讨论了目录浏览漏洞与目录遍历漏洞的危害,包括网站结构暴露、隐秘文件访问等。同时介绍了检测方法,如使用漏洞扫描器和搜索关键词。最后提供了针对常见中间件的修复方式,包括关闭目录浏览功能。对于保护网站安全具有一定的参考价值。 ... [详细]
author-avatar
厉害了
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有