appcelerator escape query string - sql

I'm looking for a way to escape all characters in javascript so i can insert them into a database. But i don't want to use escape() because that's breaking my code.
now getting this error:
[ERROR] invalid SQL statement. Error Domain=com.plausiblelabs.pldatabase Code=3 "An error occured parsing the provided SQL statement." UserInfo=0x6de2b50 {com.plausiblelabs.pldatabase.error.vendor.code=1, NSLocalizedDescription=An error occured parsing the provided SQL statement.
com.plausiblelabs.pldatabase.error.query.string=INSERT INTO vac ( category, title, url, description) VALUES ( '201', ' Adviseur Bankshop', 'someurl', 'description \'t more text.')

You can use parameters in Appcelerator.
DB.db.execute(
"INSERT INTO feeds (title, description) VALUES (?, ?)",
'Good News!', 'A little description'
);

Related

Error at or near square brackets - Postgres

I'm trying to run a PostgreSQL query which is:
insert into client (email, name) values ('johndoe#email.com', 'johnDoe');
insert into client_settings (client_id, data) values (currval('client_id_seq'), 0);
insert into client_verify (client_id, dataFields) values (currval('client_id_seq'), json_build_object('data1', ['a1', 'a2'], 'data2', ['b1', 'b2']) );
But I'm getting an error stating SQL Error [42601]: syntax error at or near "[".
The last json object(i.e., the dataFields) when inserted into the DB it should look like:
{"data1": ["a1", "a2"], "data2": ["b1", "b2"]}
Not sure what I am doing wrong. Is there something that I'm missing or a different way to do that?
After good research I found documentation to put 'Array' in front of those like:
json_build_object('data1', Array['a1', 'a2'], 'data2', Array['b1', 'b2'])
Is this what you need :
insert into client_verify (client_id, dataFields)
values (currval('client_id_seq'), json_build_object('data1', 'a1, a2', 'data2', 'b1, b2') );
Please try this:
insert into client_verify (client_id, dataFields)
values (currval('client_id_seq')
, json_build_object('data1', '["a1", "a2"]', 'data2', '["b1", "b2"]'));
Here you can check how you need to add your string:
https://www.freeformatter.com/json-escape.html#ad-output
The UNESCAPE is the option you need
Here is a demo :
DEMO

Error in the SQL query

Can't figure out what is wrong with the following SQL query:
INSERT into ALL (name, address, client_id, service_id, service, service_address) values
('Товарищество с ограниченной ответственностью "King Fisher"',
'г.Алматы, ул.Айманова, 155, уг.ул.Жандосова','10','10','Интернет(1024)/10','г.Алматы, ул.Айманова, д.155, уг.Жандосова');
Here is an error output:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ALL (name, address, client_id, service_id, service, service_address) values ('' at line 1
Any help would be appreciated)
ALL is a reserved keyword. Because of this, it is necessary to wrap the table name in backticks:
INSERT into `ALL` (name, address, client_id, service_id, service, service_address) values
('Товарищество с ограниченной ответственностью "King Fisher"',
'г.Алматы, ул.Айманова, 155, уг.ул.Жандосова','10','10','Интернет(1024)/10','г.Алматы, ул.Айманова, д.155, уг.Жандосова');
See:
http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html
you have not closed the ' quotes, check and try or try using brackets

Error parsing the query token line error

I am trying to enter fictional values into a table I created with columns. I am getting this error:
Major Error 0x80040E14, Minor Error 25501
insert into employees (`first`, `last`, `title`, `age`, `salary`)
values (`Jonie`, `Weber`, `Secretary`, `28`, `19500`))
There was an error parsing the query. [ Token line number = 2,Token line offset = 2,Token in error = ` ]
I have entered:
insert into employees (`first`, `last`, `title`, `age`, `salary`)
values (`Jonie`, `Weber`, `Secretary`, `28`, `19500`));
What am I doing incorrectly?
You need to put quotes around strings, not backticks:
insert into employees (first, last, title, age, salary)
values ('Jonie', 'Weber', 'Secretary', 28, 19500)
And you have a ) too much at the end.

Active Record query causing SQLException near "," syntax error

I'm trying to display all such rows of a table STUDENTS which have a value of an attribute, such as COURSE IN a set of given values e.g. 'MS', 'PhD'.
I get the values in the students_controller.rb file using params. I tried to run an Active Record query using where to do the job:
#all_courses = ['MS', 'PhD', 'BA', 'MSc']
#students = Student.where("course IN :courses" , {:courses => params.has_key?(:courses) ? params[:courses].keys : #all_courses})
But I get the following error:
SQLite3::SQLException: near ",": syntax error: SELECT "students".* FROM "students" WHERE (course IN 'MS', 'PhD', 'BA', 'MSc')
I think the error might be due to the absence of ; at the end of the SQL query generated by Active Record, but I cannot do anything to get that semicolon at the end.
You need to use parentheses: "course IN (:courses)"

SQLAlchemy ProgrammingError - how to debug?

I'm using SQLAlchemy 0.5.8, and seeing this error:
ProgrammingError: (ProgrammingError) can't adapt 'INSERT INTO enumeration_value (id,
key_id, code, name, notes) VALUES (%(id)s, %(key_id)s, %(code)s, %(name)s, %(notes)s)'
{'key_id': 'aac6fc29-4ccd-4fe4-9118-cfbbd04449fe', 'notes': '', 'code': (u'Barnet',),
'id': 'd0540c97-882e-4a5b-bf14-b3ebcfeea051', 'name': (u'Barnet',)}
But a direct SQL insert with the values from the error seems to work just fine:
=> INSERT INTO enumeration_value (id, key_id, code, name, notes)
VALUES ('d0540c97-882e-4a5b-bf14-b3ebcfeea051', 'aac6fc29-4ccd-4fe4-9118-cfbbd04449fe',
'Barnet', 'Barnet', '');
INSERT 0 1
If the direct SQL works OK, how can I start to debug this?
Incidentally, the line that's throwing the error doesn't seem to have an INSERT statement in it at all, so I am a bit confused:
File "----barnet.py", line 117, in load_file
instance = model.Session.query(model.EnumerationValue).filter_by(key=key_barnet_level_2, code=level_2).all()
Do SQLAlchemy filter statements generate INSERT commands, or does this just happen to be the last line before things start to go wrong?
Figured it out - the problem was actually a syntax error a few lines higher up, with a rogue comma:
key_from = code,
Sorry if I wasted anyone's time. Please close the question.