SQLiteLog( 8646): (1) table tempsettings has no column named user - flutter

I'm learning how to upgrade databases in an flutter application, apears to be very simple, but I'm getting this error executing an INSERT:
E/SQLiteLog( 9107): (1) table tempsettings has no column named user
I/flutter ( 9107): DatabaseException(table tempsettings has no column
named user (code 1 SQLITE_ERROR): , while compiling: INSERT INTO
tempsettings('id', 'user', 'company', 'url') SELECT 'id', 'user',
'company', 'url' FROM settings) E/SQLiteLog( 9107): (1) no such
column: user I/flutter ( 9107): DatabaseException(no such column: user
(code 1 SQLITE_ERROR): , while compiling: INSERT INTO settings('id',
'user', 'company', 'url', 'theme') SELECT id, user, company, url, 1
FROM tempsettings)
await db
.execute("CREATE TABLE tempsettings("
"'id' INTEGER "
"'user' TEXT,"
"'company' TEXT,"
"'url' TEXT)")
.catchError((error) => print(error.toString()));
await db.execute(
"INSERT INTO tempsettings('id', 'user', 'company', 'url') SELECT 'id', 'user', 'company', 'url' FROM settings")
.catchError((error) => print(error.toString()));
Does anyone could help me how to do this INSERT?
Thanks.

You're missing a comma after the id column creation
await db.execute("CREATE TABLE tempsettings("
"id INTEGER ", //this comma was missing
"user TEXT,"
"company TEXT,"
"url TEXT)")
.catchError((error) => print(error.toString()));

Related

how to include two id from different table into one column in postgres using nest

Realtions database:
i want to pick vendor id and purchase id into one column at column document id
what should i do to combine these two fields into the document_id column, because i trying use join column it will create two different columns in the approval table
example code
#ManyToOne(() => Vendor, (vendor) => vendor.id)
#JoinColumn({ name: 'document_id' })
document_id: Vendor;
#ManyToOne(() => Purchase, (purchase) => purchase.id)
#JoinColumn({ name: 'document_id' })
document_id: Purchase;
i use nestjs and postgre, and use typeorm to connect them
#ManyToMany(() => MenuEntity, (menuEntity) => menuEntity.roles)
#JoinTable({
name: "rcon_role_menu",
joinColumn: {
name: "role_id",
referencedColumnName: "id",
},
inverseJoinColumn: {
name: "menu_id",
referencedColumnName: "id",
},
})
menus: MenuEntity[];
This may be helpful to you

Using dblink extension from pg-promise

I have a PostgreSQL database with dblink extension.
I can use dblink without issues from pgAdmin but not from my nodeJS code using pg-promise.
I have checked that I am on the correct schema and database.
Running SELECT * FROM pg_extension; from my code does return that dblink is installed. However running a query including dblink results in: error: function dblink(unknown, unknown) does not exist
Is there something I should do to make dblink work in this scenario?
This a basic example of my code:
query1 = 'SELECT * FROM pg_extension;'
query2 = `Select *
FROM dblink('host=XXX user=XXX password=XXXX dbname=XXXX',
'select name from example_table')
AS t(name text);`
db.any(
query1
).then(function(results) {
console.log('Query1 result:', results)
}).catch(function(err) {
console.log(`Error in query1 ${err}`)
})
db.any(
query2
).then(function(results) {
console.log('Query2 result:', results)
}).catch(function(err) {
console.log(`Error in query2 ${err}`)
})
Result:
Query1 result: [
{
extname: 'plpgsql',
extowner: 10,
extnamespace: 11,
extrelocatable: false,
extversion: '1.0',
extconfig: null,
extcondition: null
},
{
extname: 'dblink',
extowner: 10,
extnamespace: 2200,
extrelocatable: true,
extversion: '1.2',
extconfig: null,
extcondition: null
},
{
extname: 'timescaledb',
extowner: 10,
extnamespace: 24523,
extrelocatable: false,
extversion: '1.7.1',
extconfig: [
25044, 25042, 25068, 25083,
25081, 25102, 25100, 25118,
25116, 25139, 25155, 25157,
25173, 25175, 25193, 25210,
25246, 25254, 25283, 25293,
25303, 25307, 25324, 25343,
25358, 25472, 25478, 25475
],
extcondition: [
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'WHERE id >= 1000',
'',
'',
"WHERE key='exported_uuid'",
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
''
]
}
]
Error in query2 error: function dblink(unknown, unknown) does not exist
It looks like exactly what I get if dblink is installed in "public" but "public" is not in my search_path.

Sequelize throws generic error messages when querying the database

Sequelize version: 6.13.0
Database version: PostgreSQL 13.3
Whenever there's an issue with a query, Sequelize doesn't tell me the actual issue. For example, this old Stack Overflow post shows Sequelize displaying an error that a column is unknown. In my case, I receive a generic error message and need to manually inspect the queries and my database tables to find out what's wrong. Here's an example:
const user = await User.findByPk(params.id);
const settings = await Setting.findAll({ attributes: ['id', 'key', 'defaultValue'] });
const userSettings = await user.getUserSettings({ attributes: ['id', 'key', 'value'] });
This will produce the following SQL:
Executing (default): SELECT "id", "name", "email", "password", "referralCode", "referredByUserId", "bio", "twitterUrl", "facebookUrl", "instagramUrl", "createdAt", "updatedAt" FROM "Users" AS "User" WHERE "User"."id" = '1';
Executing (default): SELECT "id", "key", "defaultValue" FROM "Settings" AS "Setting";
Executing (default): SELECT "id", "key", "value" FROM "UserSettings" AS "UserSetting" WHERE "UserSetting"."userId" = 1;
And here's the error message:
/home/user/app/backend/node_modules/sequelize/lib/dialects/postgres/query.js:76
const errForStack = new Error();
^
Error:
at Query.run (/home/user/app/backend/node_modules/sequelize/lib/dialects/postgres/query.js:76:25)
at /home/user/app/backend/node_modules/sequelize/lib/sequelize.js:642:28
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at PostgresQueryInterface.select (/home/user/app/backend/node_modules/sequelize/lib/dialects/abstract/query-interface.js:979:12)
at Function.findAll (/home/user/app/backend/node_modules/sequelize/lib/model.js:1789:21)
at HasMany.get (/home/user/app/backend/node_modules/sequelize/lib/associations/has-many.js:228:21)
I had to manually check my database tables, and I found out that the key column is not present on the UserSettings table.
Why doesn't Sequelize tell me this on any of my models? Is there some configuration I'm missing?
As #Anatoly mentioned in the comments, I just needed to catch the errors in try-catch block, like this for example:
try {
const user = await User.findByPk(params.id);
const settings = await Setting.findAll({ attributes: ['id', 'key', 'defaultValue'] });
const userSettings = await user.getUserSettings({ attributes: ['id', 'key', 'value'] });
} catch (e) {
console.log(e);
next(e);
}
Coming from a Ruby on Rails background, I had expected the errors to be shown in the output of my terminal running the Express server, but that doesn't seem to be the case.
Thanks #Anatoly, debugging will be a lot easier now!

What is wrong with my MYSQL Workbench Query? (Error Code: 1064)

I am getting an error code (1064) when I attempt to run a query in MYSQL Workbench. I have researched the error code and I'm aware that it is often thrown when a reserved keyword is used, a command is misspelled, or when using a depreciated command. I have checked my code and I don't see any of the aforementioned errors. I have made sure that the strings are all surrounded with quotation marks, the values and properties are in their corresponding positions, and that my sequelize model and datatypes are formatted appropriately. However, when I try to run the query, I get a red squiggly line under one entry (saying that the entry is not valid in it's position and that a ')' is expected) and the error code.
INSERT INTO drycleaningprices(sameDayService, delivery, pickUpFee, dryCleaningPrices1-14, addInfo, sameDayInfo, deliveryHours, pickUpHours, EstablishmentBusinessName)
VALUES (true, true,"$20.00",‍"kill","kill","kill","kill","kill","kill",‍"kill", "kill","kill",‍"kill","kill","kill",‍"kill","kill","kill","kill","kill","kill","Affordable Laundry")
I have even replaced each of the entries with duplicate strings to no avail. In the above code, "dryCleaningPrices1-14" is actually 14 separate entries but was shortened for readability. And here is my model:
module.exports = function(sequelize, DataTypes){
var DryCleaningPrices = sequelize.define("DryCleaningPrices",{
sameDayService:{
type: DataTypes.BOOLEAN,
defaultValue: false
},
delivery:{
type: DataTypes.BOOLEAN,
defaultValue: false
},
pickUpFee:{
type:DataTypes.STRING,
defaultValue: "Enter Info"
},
freePickUp:{
type: DataTypes.BOOLEAN,
defaultValue: false
},
deliveryOrderMinimum:{
type:DataTypes.STRING
},
dryCleaningPrices1-14:{
type:DataTypes.STRING
},
addInfo:{
type:DataTypes.TEXT
},
addInfo2:{
type:DataTypes.TEXT
},
addInfo3:{
type:DataTypes.TEXT
},
sameDayInfo:{
type:DataTypes.TEXT
},
deliveryHours:{
type:DataTypes.STRING
},
pickUpHours:{
type:DataTypes.STRING
},
createdAt:{
type:DataTypes.DATE
},
updatedAt:{
type:DataTypes.DATE
}
})
DryCleaningPrices.associate=function(models){
DryCleaningPrices.belongsTo(models.Establishment,{
foreignKey: {
allowNull: false
}
})
}
return DryCleaningPrices;
}
DDL:
Table Create Table
drycleaningprices CREATE TABLE `drycleaningprices` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`sameDayService` tinyint(1) DEFAULT '0',
`delivery` tinyint(1) DEFAULT '0',
`pickUpFee` varchar(255) DEFAULT 'Enter Info',
`freePickUp` tinyint(1) DEFAULT '0',
`deliveryOrderMinimum` varchar(255) DEFAULT NULL,
`dryCleaningPrices1-14` varchar(255) DEFAULT NULL,
`addInfo` text,
`addInfo2` text,
`addInfo3` text,
`sameDayInfo` text,
`deliveryHours` varchar(255) DEFAULT NULL,
`pickUpHours` varchar(255) DEFAULT NULL,
`createdAt` datetime DEFAULT NULL,
`updatedAt` datetime DEFAULT NULL,
`EstablishmentBusinessName` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
KEY `EstablishmentBusinessName` (`EstablishmentBusinessName`),
CONSTRAINT `drycleaningprices_ibfk_1` FOREIGN KEY (`EstablishmentBusinessName`) REFERENCES `establishments` (`businessName`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
Your Insert statement is incorrect you have given 9 column names but in Values you have given more than 9. Ideally your insert statement should look like this
INSERT INTO test.drycleaningprices
(sameDayService, delivery, pickUpFee, `dryCleaningPrices1-14`, addInfo, sameDayInfo, deliveryHours, pickUpHours, EstablishmentBusinessName)
VALUES(true, true, "$20.00", "kill", "kill", "kill", "kill","kill", '');
Please refer
https://www.w3schools.com/sql/sql_insert.asp

Error 42601 using postgresql and dart

I get the error 42601 when using postgresql
I created the table using pgAdmin. The autogenerated code looks as follows.
-- Table: posts
-- DROP TABLE posts;
CREATE TABLE posts
(
post_id bigserial NOT NULL,
title character varying(150) NOT NULL,
description character varying(500),
posted_at timestamp with time zone,
last_edited timestamp with time zone,
"user" character varying(50) NOT NULL,
editor character varying(50),
up_votes integer NOT NULL,
down_votes integer NOT NULL,
flag character varying(7),
CONSTRAINT "PK_post_id" PRIMARY KEY (post_id),
CONSTRAINT "FK_user" FOREIGN KEY ("user")
REFERENCES users (login) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE posts
OWNER TO postgres;
I execute an insert operation with the following helper method.
addPost(Map values){
connect(uri)
.then((conn){
conn.execute('insert into posts values(#title, #description, now(), now(), #user, #editor, #upVotes, #downVotes, #flag', values)
.then((_) => conn.close())
.catchError((err){
print('Execute error in addPost: $err');
})
.whenComplete(() => conn.close());
})
.catchError((err) => print('Error in addPost: $err'));
}
where Map values has the form:
{'title': 'Sample title', 'description': 'This is a description for a sample post', 'user': 'dartUser', 'editor': 'dartUser', 'upVotes': 0, 'downVotes': 0, 'flag': 'healthy'}
I'm not a postgresql expert, so this might be something trivial I just don't see.
You can find the error codes for postgresql here. Error 42601 means a syntax error.
I suspect the cause is that you are missing a closing bracket on the 'values' clause, after #flag.