为了测试到数据库的连接,我只想将一些硬编码的数据添加到一个表中。这是我的方法。在main.dart文件中,只有两个与问题相关的行
DatabaseUtility dbUtil = new DatabaseUtility('postgres', 'kewoziwa', 'auctionDB');
dbUtil.insertIntoUsers({'login': 'dartUser', 'password': 'passMePlease'});在第一行中,我创建了一个助手类的实例。在第二个过程中,我调用了这个类中定义的方法。
主要代码:
import 'dart:io';
import 'package:http_server/http_server.dart' show VirtualDirectory;
import 'database_utility.dart';
VirtualDirectory virDir; // not related to this problem
main() {
DatabaseUtility dbUtil = new DatabaseUtility('postgres', 'kewoziwa', 'auctionDB');
dbUtil.insertIntoUsers({'login': 'dartUser', 'password': 'passMePlease'});
initVirDir(); // not related to this problem
runServer(); // not related to this problem
}在DatabaseUtility类构造函数中,我只为数据库连接创建uri。使用pgAdmin III在实例化日志中使用相同的密码,没有任何问题。所有其他输入都与pgAdmin III相同。定义的insertIntoUsers方法只对users表执行插入操作。我看不出那里有什么问题。插入后,我关闭连接。
帮助者全班:
import 'package:postgresql/postgresql.dart';
class DatabaseUtility {
//Connection conn;
String username;
String passwd;
String database;
var uri;
DatabaseUtility(this.username, this.passwd, this.database) {
uri ='postgres://$username:$passwd@localhost:5432/$database';
print(uri);
}
insertIntoUsers(Map values){
connect(uri)
.then((conn){
conn.execute('insert into users values(@login, @password)')
.then((_) => conn.close());
})
.catchError(print);
}
}不幸的是,当我运行这个程序时,我得到了错误: 42703
错误消息:
Unhandled exception:
Uncaught Error: BŁĄD 42703 kolumna "login" nie istnieje
// Trnaslation Error: 42703 the column "login" does not exist
#0 _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:886)
#1 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:41)
#2 _asyncRunCallback (dart:async/schedule_microtask.dart:48)
#3 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:96)
#4 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:143)在pgAdminIII工具中,我可以看到这个专栏。

这里怎么了?
发布于 2015-05-06 07:16:25
我认为您忘记将值传递到conn.execute()。
试着改变这一行:
conn.execute('insert into users values(@login, @password)')对此:
conn.execute('insert into users values(@login, @password)', values)
^^^^^^此外,我建议存储盐渍密码散列,而不是明文字符串。这里有一个很好的起点:How can I hash passwords in postgresql?
https://stackoverflow.com/questions/30063120
复制相似问题