I'm attempting to place a decently sized array of objects into a db and I've got the code written that will do it and several records ARE actually written to the DB, however something about the formatting is causing the function to throw errors.
One of those errors that I've seen on multiple attempts to fix this issue is:
"Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon."
another is
"Incorrect syntax near 's'."
When I initially open the array I'm attempting to place into the DB I get an alert from VSCode about symbols that needed to be removed but I am not able to get the error verbatim at the moment and don't know how to replicate the message. Regardless it has no effect on if it will add all entries or not.
My question is what about my objects could cause this kind of weird issue and what kinds of things could I fix keeping in mind that some of the records are actually being added. Thank you!
Also what is the best/easiest way for bulk adding items to a DB programmatically? ATM I'm just doing INSERT INTO query.
Related
I try write this command:
DELETE FROM locations ORDER BY id DESC LIMIT 1
on knex.js.
I write this code:
knex('locations').delete().orderBy('id', 'desc').limit(1).toString()
But it return
DELETE FROM locations
Why?
Because LIMIT is not supported by Postgres and Knex is supposed to be compatible with both MySQL and PostgreSQL. See GitHub issue:
[...] this syntax isn't supported in Postgres, so that might be a bit unexpected if it's possible in one database and not another [...]
Please open a new feature request if you need this functionality to be changed.
It was mentioned there that it works since 0.6 but I can't verify that, it seems still to be not working, and that seems to be a design choice. (Personally I find this quite problematic because there is no error, you just silently get everything deleted.)
The only way to handle a DELETE LIMIT statement would be as raw query with knex.raw then.
I have been wondering about how to write down function in migration file. Ideally, it should be exactly opposite of what we are doing in up method. Now suppose I wrote up function to drop unique constraint on a column, added some new rows(having duplicate data) to a table and now I want to rollback the migration. Ideally, I would write down method to add a unique constraint again on the column but migration would not rollback as a table now contains duplicate data.
So my questions are -
What to do in such a situation?
How to write down function in migrations?
Can I keep the down function blank in such a situations?
Thanks.
I usually don't write down functions at all and just leave them empty.
I never rollback migrations and if I want to get to earlier DB state I just restore whole DB from backups.
If I just want to put unique constraint back, I will write another up migration which fixes duplicate rows and then adds unique constraint back.
I know that many people is using rollback between tests to reset DB, but that is really slow way to do it.
I am designing a SQL engine. From the UI the user will select certain parameters and based on those parameter I will design a SQL statement. User will have option to join tables, apply conditions, create temp tables, ability to apply many SQL in-build functions etc. I will write many functions which will look at the input and based that perform some action which will ultimately give a SQL statement.
I can do this code using any server side language but we want to try JavaScript.
Obviously this will require lot of string manipulation.
I am just worried if this will result "“A script on this page is causing Internet Explorer to run slowly. If it continues to run, your compute may become unresponsive." on IE or "A script on this page may be busy, or it may have stopped responding. You can stop the script now, open the script in the debugger, or let the script continue" on Firefox.
I know I am not sharing any code & the question is little subjective. But I am sure some of you may have faced similar issues/challenge in your previous assignment & your valuable suggestions will be a big help.
Unless I have misunderstood your question, you are asking if there is a risk of getting that dreaded message when doing a couple of string manipulations.
If you want to only construct the query in the browser, then I think you are fine, as you won't have to, say, concatenate 1000 strings, or search a string amongst 1000. The only risk I would say is if you intend to do complicated regexp operations on big strings.
If I misunderstood, a few example of the string manipulations you intend to do would help.
Of course, I am assuming you will send and run the SQL queries in an asynchronous manner.
If my JSON data-file comes from a database result set and that result set is empty, how do I tell OFC2 to display an error message, instead of crashing because of a malformed JSON string?
Add tags for javascript and actionscript-3 to this question and you should get a load more views and useful responses than you currently are, with more precise details than I am giving. Post the actual JSON string that is causing you the problem and that you would like to be guarded against. That way people can suggest a regexp to catch it, treating it as a string rather than as JSON data at some point before JSON.decode() happens.
In more detail:
You can catch it in two places. One route is to switch over to using the javascript interface to OFC2 and use client side javascript to detect the bad string. This allows you to modify the JSON string client side. See http://teethgrinder.co.uk/open-flash-chart-2/tutorial-5.php for that approach. One downside is that the clients must have javascript enabled for this to work.
Alternatively, since OFC2 is LGPL, you or an actionscript developer can dive into the OFC2 source code and do the same thing there. I am not an actionscript developer so you are better off ensuring you get a reply from one.
The main thing is to add those two tags to this question. 22 Views is way too low for a question with a bounty of 500. Hope this helps.
Several solution avenues are possible, depending on your level of access to the server and your knowledge of JavaScript and/or any server-side platforms.
With access to database
Depending on the kind of data you are displaying, it might be possible to add dummy records for those queries that would otherwise have returned an empty set. If you have access to the query definition, you may check for the empty set in the DB-query. For example, if you're on MS SQL Server you could check the condition with some T-SQL statements.
With access to server
If you have access to the server side script generating the dataset, add a condition that returns some default value that OFC2 will handle correctly.
With access to another server or serverlocation
If you don't have access to the specific script, you may consider creating a new script at another location that queries the original script and replaces empty results with the default value.
Client-side only
You can add the JavaScript open_flash_chart_data function (see tutorial) to replace empty datasets. OFC2 can use that function as data source.
Hope this helps.
This is an ajax questions. I have a table this table shows users information at certain time depending on what settings the user sets.
Now in some cases a user will see the information right away and in some cases they won't it all depends on when they want to see the information.
Now what should I do?
Should I do? do a post and post their data and then do a ajax get after to get the table and render it?
*I probably could it all in the post but unless some huge performance gain is gained I rather not otherwise I have to do mix "success/fail" messages and the table to be rendered all in the same response.
So each one seems to have pluses and minuses.
Ajax way
don't have to worry about having a
JavaScript solution that queries the
database to figure out what their
timezone is and then determine if the
row should be added or not and any
other headaches that comes with
javascript dates.
Each row could potential have a
different style to. This would
mean I would have to possibly do a
query to the database and figure it
out or have hidden field in the page
for easy access. With Ajax way I
would not have to worry about it.
don't have to worry about making a
manual row in javascript/jquery
syntax what can be a pain to do if
you have many columns.
Javascript way
Problem less of a performance hit
since only have to potentially make
one new or do nothing. Where
otherwise I have to generate a new
table regardless and if it has lots
of rows in it that could be slow.
Have to rebind all jquery plugins
that would be on the table. Or use
jquery.live for everything else.
So I am not sure to me it seems like a hard choice.
Unless I misunderstand what you want to do, why not do both in one solution?
Return a JSON response, so, when a user logs in, you post the information using an ajax call, and just return the data from the database. I tend to return either data or an error message, but you could have two objects in your json string, one for a possible error message and the other being the data that is being returned.
The javascript then can process the data as is needed.
So, you do both, it isn't an either/or decision.