sqlite3 Interface error on inserting data to database - python-2.7

i am using sqlite3 to store data to database. I have created lineedits through which i extract the data and insert it to database. But now the problem is when i run the program,once i click on add data button the above error shown. Please help me where am i going wrong.....Another thing is that if i run the same code in windows platform its runs without any problem, but if in ubuntu 13.4 it is not working..........here is the code:
queryCurs.execute('''CREATE TABLE IF NOT EXISTS PATIENT
(NAME VARCHAR(30) NOT NULL,ID INTEGER PRIMARY KEY,AGE INTEGER NOT NULL,GENDER VARCHAR(10) NOT NULL,EYE_TYPE VARCHAR(20) NOT NULL)''')
self.pName = self.patientEdit.text()
self.pAge = self.ageEdit.text()
self.pGender = self.patientgend.text()
self.pEye_type = self.eyeTypeEdit.text()
queryCurs.execute('''INSERT INTO PATIENT(NAME,AGE,GENDER,EYE_TYPE)
VALUES(?, ?, ?, ?)''',(self.pName,self.pAge,self.pGender,self.pEye_type))
print ('Inserted row')
createDb.commit()
this what i have tried in my code...i get error as
VALUES(?, ?, ?, ?)''',(self.pName,self.pAge,self.pGender,self.pEye_type))
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.

Related

Saving checkbox values into the sqlachemy database

Im new to flask and flask-sqlalchemy
Im currently working on website with checkboxes; but im getting an error. Here is the part of the code.
bodygoal= request.form.get('BodyGoal')
workouttype= request.form.getlist('WorkoutType')
slevel= request.form.get('SkillLevel')
new_workout=Workout(bodygoalDB=bodygoal, workouttypeDB=workouttype, slevelDB=slevel, user_id=current_user.id)
db.session.add(new_workout)
db.session.commit()
as for the database model; here is also the part of the part of the code
class Workout(db.Model):
id = db.Column(db.Integer, primary_key=True)
bodygoalDB=db.Column(db.Integer)
workouttypeDB=db.Column(db.String())
slevelDB=db.Column(db.Integer)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
this is the error im getting:
sqlalchemy.exc.InterfaceError: (sqlite3.InterfaceError) Error binding parameter 1 - probably unsupported type.
[SQL: INSERT INTO workout ("bodygoalDB", "workouttypeDB", "slevelDB", user_id) VALUES (?, ?, ?, ?)]
[parameters: ('Shredded', ['on', 'Dumbell', 'Barbell'], 'Beginner', 1)]
(Background on this error at: https://sqlalche.me/e/14/rvf5)
the workouttype variables gets all the checkbox values from the website; currently, im planning to store them in 1 cell but Im also accepting suggestions on how to deal with checkbox values with sqlalchemy. thanks :)
request.form.getlist('WorkoutType') is returning a list of strings, e.g. ['on', 'Dumbell', 'Barbell'], but you are trying to assign the list to column of data type string.
You could convert the string array to a comma delimited string:
# Get the string array
workout_types = request.form.getlist('WorkoutType')
# Convert to comma delimited string
workout_csv = ','.join(workout_types)
# etc
new_workout = Workout(bodygoalDB=bodygoal, workouttypeDB=workout_csv, slevelDB=slevel, user_id=current_user.id)

wso2 is change the embedded database schema

I am working with the WSO2 IS 5.2.0
for some reasons, I would like to change the data schema of the default embedded H2 database.
for example,
the maximum length of volume "ACCESS_TOKEN" in table "IDN_OAUTH2_ACCESS_TOKEN" is 255 chars. I would like to change it to 8194.
I made the following change the configuration file "/dbscripts/identity/h2.sql" (see the value "8194")
CREATE TABLE IF NOT EXISTS IDN_OAUTH2_ACCESS_TOKEN (
TOKEN_ID VARCHAR (255),
ACCESS_TOKEN VARCHAR (8194),
REFRESH_TOKEN VARCHAR (255),
CONSUMER_KEY_ID INTEGER,
AUTHZ_USER VARCHAR (100),
TENANT_ID INTEGER,
USER_DOMAIN VARCHAR(50),
USER_TYPE VARCHAR (25),
GRANT_TYPE VARCHAR (50),
TIME_CREATED TIMESTAMP DEFAULT 0,
REFRESH_TOKEN_TIME_CREATED TIMESTAMP DEFAULT 0,
VALIDITY_PERIOD BIGINT,
REFRESH_TOKEN_VALIDITY_PERIOD BIGINT,
TOKEN_SCOPE_HASH VARCHAR (32),
TOKEN_STATE VARCHAR (25) DEFAULT 'ACTIVE',
TOKEN_STATE_ID VARCHAR (128) DEFAULT 'NONE',
SUBJECT_IDENTIFIER VARCHAR(255),
PRIMARY KEY (TOKEN_ID),
FOREIGN KEY (CONSUMER_KEY_ID) REFERENCES IDN_OAUTH_CONSUMER_APPS(ID) ON DELETE CASCADE,
CONSTRAINT CON_APP_KEY UNIQUE (CONSUMER_KEY_ID,AUTHZ_USER,TENANT_ID,USER_DOMAIN,USER_TYPE,TOKEN_SCOPE_HASH,
TOKEN_STATE,TOKEN_STATE_ID)
the problems is that I just cannot put this change into effect. I did everything (restart, reinstall), the original settings ("256") persists...
it seems that the database schema had been generated in the IS server image. and the generating script file says "GENERATE IF NOT EXISTS..."
anyone has any idea?
thanks
Remove <IS_HOME>/repository/database/*. Then start server with -Dsetup.
./wso2server.sh -Dsetup
Yes, It is generated with the server distribution. What you can do is (backup and) remove the content of repository/database, update the db scripts and start the server with bin/wso2server.sh -Dsetup. This needs to be done only once, from next time on you can start the server as usual.
One other possibility is to use the H2 console. If you already have data, it will be the better option.

SQLite DB Browser: invalid operand for regexp

I used DB Browser for SQLite version 3.6.0; SQLite Version 3.8.9.
This application already supports Regular Expression out of box (sqlitebrowser). I can use regexp on column brand but failed on column revision;
For example
SELECT brand,revision FROM TDevice where TDevice.brand regexp '^ASUS$'
and the result is 114 Rows returned from: SELECT brand,revision FROM TDevice WHERE TDevice.brand regexp '^ASUS$'; (took 51ms)
However, if regexp is applied on different column, then I get the error
SELECT brand,revision FROM TDevice WHERE TDevice.revision regexp '^ASUS$';
and the error message is invalid operand: SELECT brand,revision FROM TDevice WHERE TDevice.revision regexp '^ASUS$';
Both brand and revision are of TEXT type. The table creation schema is as below:
CREATE TABLE `TDevice` (
`id` INTEGER NOT NULL,
`brand` varchar(128) NOT NULL,
`model` varchar(128) NOT NULL,
`revision` TEXT,
PRIMARY KEY(id)
);
Both brand and revision are of TEXT type. The table creation schema is as below:
No They are different see your table description correctly if you change the TEXT to varchar it will work fine.
Or I will check and inform you how to use regex or can we use regex with TEXT datatype.
or you can convert(CAST) your TEXT to varchar and can perform the match operations
See this post for how to CAST TEXT into varchar
Need to convert Text field to Varchar temporarily so that I can pass to a stored procedure
The difference between brand and revision is that brand cannot accept NULL text. After I fill the revision with empty string '':
UPDATE TDevice SET revision='' WHERE revision IS NULL
, this invalid operand error is resolved.

Convert varchar to double fails when I use ADO yet it works in MS Access

I have made a query that ran successfully in the first version of my program, using ADO and C++ to query MS Access 2007 database.
However, the structure of my database had to be modified.
Fields that were once of type double are now varchar.
When I execute the same query on the modified database, it reports data type mismatch, as it should.
EDITED QUERY TO HELP THE POSTER OF THE FIRST SOLUTION:
Here is simplified version of my query:
wchar_t query = L" select ( ads(Field) + Field ) / 2 from MyTable where PrimaryKey = 1;";
Field was of type double, but now is varchar.
I have tried using CDbl like this:
wchar_t query = L" select ( abs( CDbl(Field) ) + CDbl(Field) ) / 2 from MyTable where PrimaryKey = 1;";
It works when I create query in MS Access, but in my program I still get data type mismatch error reported.
I have tried to find alternative on the Internet, and have thought that CAST or CONVERT can sole this, but it seems that they do not work in MS Access.
Is there any solution for this ?
Thank you.
Regards.
Have you tried to convert the value to Double not in the query but after the query has been run?
CAST and CONVERT are not Access SQL functions
I dont use c++ but even with a small subroutine in Access using the ADO object I cannot reproduce the error...
Sub test()
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim db As ADODB.Connection
Set db = CurrentProject.Connection
rs.Open "SELECT (Abs(CDbl(Field))+CDbl(Field))/2 AS A FROM MyTable;", db
While rs.EOF = False
Debug.Print rs!A
rs.MoveNext
Wend
End Sub

mySql Connector exception (C++ library for mysql) when inserting row into non-empty table

I have not done much database programming at all. I am working from some example code for using MySQL Connector/C++.
When I run the following code I get a crash on the last line in some std::string code - but it ONLY crashes when the table is not empty. If the table is empty, it inserts the row and works fine. If the table is non empty it crashes. I am pretty confused. Is there something I am doing wrong with the primary key or the other values? (the column names have been changed here, but otherwise the code is verbatim)
When I look at the variable in the std::string template code (what little I can see) I don't see any familiar values of data that I was attempting to insert - so that was no help at all. I see something like "HY000" as a string value, but I am not certain where that is coming from.
Initially i thought it might be the date string, but the code works fine with an empty table and then crashes when non-empty. That indicates the date string works fine.
prep_stmt = con->prepareStatement("INSERT INTO
sometable(val1, val2, val3, Date, val5, val6, val7)
VALUES (?, ?, ?, ?, ?, ?, ?)");
/*
`idLicenses` INT NOT NULL ,
`val1` VARCHAR(45) NOT NULL ,
`val2` INT NOT NULL ,
`val3` INT ZEROFILL NULL ,
`Date` DATETIME NOT NULL ,
`val5` VARCHAR(45) NOT NULL ,
`val6` VARCHAR(45) NOT NULL ,
`val7` VARCHAR(45) NOT NULL ,
*/
// val1, val5, val6 and val7 are std::strings, val2 and val3 are ints.
prep_stmt->setString(1, val1);
prep_stmt->setInt(2, val2);
prep_stmt->setInt(3, 0);
prep_stmt->setDateTime(4, /* I created some date string here*/);
prep_stmt->setString(5, val5);
prep_stmt->setString(6, val6);
prep_stmt->setString(7, val7);
prep_stmt->execute();
This is on a MS platform using Visual Studio 2008.
The database is up and running and I can use other database query tools to see the tables, etc.
EDIT:
I see looking at the mysql exception that I get:
"Using unsupported buffer type: 4191960 (parameter: 3)"
errno 2036
EDIT:
I am not sure if the accepted answer was exactly the right answer, but it helped me get to a solution. Basically I removed all non-null attributes, took out zero fill and set the primary key to auto-increment. Now it works fine
I suspect it's either your zero-filled INT or the DATETIME column (not sure which is column 3).
Try creating your table with something like:
`val3` INT(10) ZEROFILL ,
where 10 is the number of positions to zero-fill. I'm also not sure the NULL is necessary, so I excluded it above.
Also, can you post the date string you created if the above doesn't work?