Any Javascript/Jquery Library To validate SQL statment? - javascript

i have a textarea in my project where users can save SQL queries but one of the requirements is to check if this query is valid or not
EXAMPLE
if user entered something like :
SELECT ** FROM EMP
this should return false and an error message just saying invalid it doesn't have to give any reasons
mainly the queries will be just select statement
NOTICE
i DON'T want to use any server side at this point
Question
Does any one knows a javascript / jquery library or plugin that have this functionality or any thing similar
i have Google this and it didn't show any thing
Thanks

Here is an example fiddle using the JS SQL Parser:
http://jsfiddle.net/Hb6az/
The parser will throw an error if it hits something unexpected, so you have to wrap your checking code in a try {} catch(error) {} block.

Related

Mail Rules using JavaScript for Automation instead of AppleScript

I'm trying to build a Mail.app rule (on OS X Yosemite) using Javascript for Automation instead of AppleScript, but I'm stuck on the basics.
I see this code in AppleScript:
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
# actual code here
end perform mail action with messages
end using terms from
but I'm unclear how this translates to JavaScript.
Do I define a function? Set a callback? I'm unclear.
I see that there is the performMailActionWithMessages function, but I can't figure out how to get it working.
Any guidance is very much appreciated!
I finally figured it out:
function performMailActionWithMessages(messages) {
messages.forEach( function(message) { // if you want to iterate
})
};

How does assert (req.assert) work in nodejs

I am currently working on MEAN stack using node, express and angularjs. I downloaded boiler plate code from mean.io and also using debugger while I explore the code.
In the controller which gets req and res as parameters, how does req.assert work?
In the file server/controllers/users.js
req.assert('username', 'Username cannot be more than 20 characters').len(1,20);
adds into validation error even when the username is empty or null. How do I check for current username value in the req? Where is the assert function of req defined.
I come from java background and find it tricky to find the function code some times as I wont be sure about where is it defined and how is it prototyped. How does one properly read the objects and browse the functions that are being used in javascript?
It's defined in Express's dependency express-validator. Check here: https://github.com/ctavan/express-validator/blob/master/lib/express_validator.js
which depends on validator:
https://github.com/chriso/validator.js
Accepted answer refers to what is now the Legacy API hence broken links.
Check out the documentation for Sanitization and the available sanitizing tools. You can make custom validators in there.

semantic ui remote validation

I am using Semantic UI along with ASP.NET MVC. I have performed client-side validation in my registration form as described in the documentation http://semantic-ui.com/modules/form.html Now i want to validate an email in order to be unique. So i have to make an ajax request to the server (this is something i know how to do). But how can i add such a rule in Semantic UI and display a corresponding error message?
After a little search at the docs I found the behavior add errors. It works like
$('.your.ui.form').form('add errors', ['Your error string 1', 'Maybe another one?']);
However, this will only change the text in the error messages. If the error message is not displayed at that time, you will probably want to show it. Add the class 'error' to the form:
$('.your.ui.form').addClass('error');
And of course you can chain these two methods like
$('.ui.form')
.form('add errors', ['oh my error'])
.addClass('error');
Here's a fiddle

Appropriate method to execute JavaScript from user input?

I need to build a web application that allow user to input javascript code and the code is then dynamically executed and somehow show the result at the same page. The flow would be something like this:
In the webpage, there area a series of textarea, and under each of these textareas, there is a result div element (or whatever element span, p, doesn't matter). User will input javascript code inside the textareas. He should be able to enter whatever javascript code he want, but at the end he will call a custom function like
my_application_output(some_variables_computed_from_previous_code_execution)
and then something will be displayed on the result div. A simple example will be:
if he input the following text in the textarea:
var a = 0;
a++;
my_application_output(a);
and then execute the code, the result div element below the textarea will have a inner html content of "1"
I don't have much idea how to get started, like what technologies or system architecture should I go for. so would like to ask for some pointers here. I have thought about two options (not sure whether they are good enough)
Use JavaScript eval() function. so I just execute the code from the textarea directly on the client side.
Implement a backend service using an engine like V8. So I do a ajax call to backend with the code content, and then the codes are executed from backend, and result is returned. I then put the result in the result div accordingly.
Personally, I'd like to go for 1) because eval() seems to be a easier solution. However, I'm not sure whether there is any limitation about this function or whether it can achieve what I want to do. Otherwise, if I have to go for the second option. Anyone can propose an architecture for that?
Not only is option 1 easier, it is also the safer choice.
Why? Everyone who has Firebug installed in Firefox (or just has the Chrome Dev tools open) already has what you're asking for, though perhaps in not as noob-friendly a fashion. The code they write is sandboxed to the browser they're using and nothing more.
With option 2, you're going to execute arbitrary untrusted code on the server. Suppose they realize that you're using Node.js (the most likely choice here) and then run a fork-bomb on your server:
require('child_process').exec(':(){:|:&};:', function() { console.log('This will never run') });
Let alone something more nefarious.
Remember that REPL stands for Read-Eval-Print-Loop, and is what dynamic languages since Lisp have used to help programmers understand their languages. Eval is perfectly fine if the only person a newbie can hurt is themselves.

Where does rails log errors in javascript?

I'm fairly new to Ruby on Rails so sorry if the answer is obvious, I couldn't find anything via search. Right now I have my view rendering _box.js.erb which simply draws a box. Inside _box.js.erb, which works correctly under normal circumstances, I introduce a simple syntax error like an unmatched parenthesis. When I load the webpage, my box doesn't show up. I look in logs/development.logs and it has no mention of my javascript syntax error. Is this error being caught somewhere? If so, how can I display it?
The error occurs on the client, not the server, so ROR cannot log it.
If you're using Firefox, install Firebug. Other browsers have JavaScript consoles, usually opened by pressing F-12 or looking on the "developer" options on the application menus.
You could also create a controller to accept javascript errors, so when there's a client side error you can just send it to a javascript error collection endpoint which in turn could take the contents of the error and add it to the Rails log or whatever log.
This old gem does that. I realize this questions is 8 years old.

Categories