Flutter error while using sqflite no such column in table - flutter

I'm trying to learn flutter by myself so i've decided to make an app.
I admit that i have difficulties to make a database correctly so i've copied the code for the database from an opensource app.
Basically the copied app creates notes object which have a title, description date, id.
Now what i want is to add another attribute to the object (dateexamen) (String)
What I have :
I've a main.dart, a database.dart, model folder within a note.dart, a Screen folder within a page with a listView and a floating button to another page for modifying/add/deleting object.
My object has :
Name
Description
Date created
Priority
Dateexamen (I make everything to add this one)
When i click on the floatingbutton an object is created and then the form page opens and updates the object just created.
So what i did ?:
I've just went into the note.dart, added my attribute dateexamen everywhere juste like everything was inside it and did this for all the file.
I don't have any crashes, but now it doesn't want to create any object, it works again when a delete my modification to all files..
There is the error in the console :
E/SQLiteLog( 4684): (1) table note_table has no column named
dateexamen E/flutter ( 4684):
[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception:
DatabaseException(table note_table has no column named dateexamen
(code 1 SQLITE_ERROR): , while compiling: INSERT INTO note_table
(title, description, priority, date, dateexamen) VALUES (?, ?, ?, ?,
?)) sql 'INSERT INTO note_table (title, description, priority, date,
dateexamen) VALUES (?, ?, ?, ?, ?)' args [a, b, 2, Jul 13, 2019,
Sunday, July 14, 2019 at 12:00PM]}
There is the link to the app repo: https://github.com/fakman99/flutter_first/
Thank's in advance for your help, i'm very excited about flutter and i need to understand how database and backend works with flutter.
Have a good day, Fatih

It is likely that anyone who tries your application will not get the error you get. My guess is that you ran the application once before adding your new columns so indeed the column does not exist yet. In sqlite, once the tables are defined, unless you drop/recreate them, columns must be added manually.
Once solution for this is to bump the version number and modify (or simply drop/create the table) during the onUpgrade callback. We can call this a schema migration process. There is an example here: https://github.com/tekartik/sqflite/blob/master/sqflite/doc/migration_example.md.
One quick test on your side is to simply uninstall your app, or delete the app data before trying you code again => magic, it works!

It seems that you just adjust the objects, but not the database itself.
Search for the openDatabase
openDatabase(join(await getDatabasesPath(), 'cache.db'),
onCreate: (db, version) {
return db.execute(
'CREATE TABLE cache(timestamp INTEGER, query TEXT PRIMARY KEY, data TEXT)');
}, version: 1)
and adjust the create table according to your needs. (change version or wipe app data.) retry....

Related

oracle form ''you cannot update this record''

I have a procedure in which I get values from different tables and calculate a certain decimal number. After that i try to post it on a form text-field which is a database item (update and insert allowed on the settings of block and item). everything works fine but the result wont show on the item and won't save in the database field. I get the error
"you cannot update this record".
Can someone help? i have been working on it for two days now and can't find anything.
Did you check if your user has update access on the table?
Check also if there are database triggers on the table that prevents you from updating the record.

How to apply new changes without dropping current data in the db.(Playframework evaluations)

I'm using play 2.2.1 with scala. And I have a managing database evaluations. When I run my application with changes on the database, it'll drop all my datas.
At this moment evaluationplugin = disabled is comment in. If I comment out, it does not apply my changes.
For example. I have a users table and there are id, f_name, l_name
User
id f_name l_name
1. khazo rasp
And I want to add age field to this table without losing data. I've added this field in scala files.It works properly. I'm assuming I need to write script in 1.sql for some alter command, but I don't want to write script.
How to apply new changes without dropping current data in the db. I've read this documentation. Thanks in advance.
I've added this field in scala files
In slick (you have the tag play-slick), you can specify a default value in your Table
See the documentation here, under Tables:
Default[T](defaultValue: T)
Specify a default value for inserting data the table without this column. This information is only used for creating DDL statements so that the database can fill in the missing information.
I am not sure if it gets translated to ALTER statement if the table already exists . You will have to test it.

Silverlight WCF RIA Service select from SQL View vs SQL Table

I have arrived at this dilemma via a tortuous and frustrating route, but I'll start with where I am right now. For information I'm using VS2010, Silverlight 5 and the latest versions of the Silverlight and RIA Toolkits, SDKs etc.
I have a view in my database (it's actually now an indexed view, but that has made no difference to the behaviour). For testing purposes (and that includes testing my sanity) I have duplicated the view as a Table (ie identical column names and definitions), and inserted all the view rows into the table. So if I SELECT * from the view or the table in Query Analyzer, I get identical results. So far so good.
I create an EDF model in my Silverlight Business Application web project, including all objects.
I create a Domain Service based on the model, and it creates ContextTypes and metadata for both the View and the Table, and associated Query objects.
If I populate a Silverlight ListBox in my Silverlight project via the Table Query, it returns all the data in the table.
If I populate the same ListBox via the View Query, it returns one row only, always the first row in the collection, however it is ordered. In fact, if I delve into the inner workings via the debugger, when it executes the ObjectContext Query in the service, it returns a result set of the correct number of rows, but all the rows are identical! If I order ascending I get n copies of the first row, descending I get n copies of the last row.
Can anyone put me out of my misery here, and tell me why the View doesn't work?
Ade
OK, well that was predictable - nearly every time I ask a question on a forum I stumble across the answer while I'm waiting for responses to flood in!
Despite having been through the metadata and model.designer files and made sure that all "view" and "table" class/method definitions etc were identical, it was still showing the exasperating difference in behaviour between view and table queries. So the problem just had to be caused by the database, right?
Sure enough, I hadn't noticed myself creating NOT NULL columns when I created the "identical" Table version of my view! Even though I was using a SELECT NEWID() to create a unique key column on the view, the database insisted that the ID column in the view was NULLABLE, and it was apparently this which was causing the problem.
To save some storage space I switched from using NEWID() to using ROW_NUMBER() to create my key column, but still had the "NULLABLE" property problem. SO I then changed it to
SELECT ISNULL(ROW_NUMBER() (OVER...) , -1)
for the ID column, and at last the column in the view was created NOT NULL! Even though neither NEWID() nor ROW_NUMBER() can ever generate NULL output, it seems you have to hold SQL Server's hand and reassure it by using the ISNULL operator before it will believe itself.
Having done this, deleted/recreated my model and service files, everything burst into glorious technicolour life without any manual additions of [Key()] properties or anything else. The problem had been with the database all along, and NOT with the Model/Service/Metadata definitions.
Hope this saves someone some time. Now all I need to do is work out why the original stored procedure method I started with two days ago doesn't work - but at least I now have a hint!
Ade

Perform find over list of values

In Filemaker11.
I have a table, with a field categoryID, and want to Perform Find on these records.
I want to display only the records which have categoryID as either 1, 2, 4, 6, 12 or 13.
Perform Find doesn't seem to allow me to set up ORs... or at least I can't see where it does.
How can I do this?
Note: This table is actually connecting (with read-only permissions) to a table from a MySQL database, so I cannot set up a field which displays the boolean isOneOrTwoOr...
While in find mode, go to the 'Record' menu and select new find request. All find requests are ORed together. You can do the same thing in a script by doing the 'new record/request' script step.
you can do something like this (Assuming you using MySql database as you haven't mentioned)
Select * from tablename where categoryID in (1,2,4,6,12,13);
That's simple MySql query

Store and display REAL values from sqlite database on UItable

I created sqlite table to store values of differnet fields as shown below.
CREATE TABLE places_table (PlaceID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, PlaceName VARCHAR(50), PlaceAddress TEXT, PlaceLatitude REAL, PlaceLongitude REAL);
I can assign some value to PlaceLatitude and PlaceLongitude and display the values in UItable. But when I close and restart the application it displays value of these two fields as 0. Other entries (PlaceAddress, PlaceName) do not have this problem.
Can anyone please help me? Thanks for help in advance.
Are you sure first time values are coming from DB? If so then please provide code you wrote to insert data in DB.
I think you have to check condition if table exit or not .
One possibility of such behavior is that you're doing writing operation in your in-bundle sqlite3 database which is read-only. To solve this, you may need to copy the in-bundle sqlite3 database to the app sandbox when user runs the app for the first time.
If this is your case, please follow this thread: Where would you place your SQLite database file in an iPhone app?