The following command not working:
collection.update({'somefield':{'$in':somelist}}, {'$set':{'processed':1}}, False, True)
Is it possible in MongoDb to make something like that in MySQL:
update sometable set processed=1 where id in (value1,value2,value3,etc)
The default behavior of the update() method updates a single document and would correspond to the SQL UPDATE statement with the LIMIT 1. With the multi option, update() method would correspond to the SQL UPDATE statement without the LIMIT clause.
Related
I'm using query API from com.google.cloud.bigquery.BigQuery to perform update operations Ref.
Is there a way to perform bulk update to BigQuery Table similar to insertAll or writeJsonStream.
You may try and consider as a workaround wherein you will use a for loop to loop into your query() until all your needed update have been successfully executed.
I'm trying to improve the current auditing I have with one of my databases. Currently this is done with access data macro's however I use vb.net as a front end.
Most of the updates use a data adapter and use the following command to update the backend
CurrentDataAdapter.Update
For the purposes of inserting the information into an audit table I would like to be able to list the SQL commands that take place with this. Using the command text just gives a single SQL command with the parameters place holders
CurrentDataAdapter.UpdateCommand.CommandText
Gives
UPDATE [Table] Set F1=#P1 WHERE ID=#P2
However I'm more after a list of
UPDATE [Table] SET F1=a WHERE ID=1
UPDATE [Table] Set F2=b WHERE ID=2
UPDATE [Table] SET F3=c WHERE ID=3
Is this possible? (Multiple SQL statements in one are not supported with Access backend)
Many thanks
Each time I perform a query (INSERT, DELETE,UPDATE). After Do I need to do Select * From Table, so my info can be seen on the Grid control?
For example:
UniQuery1 is my dataset.
I'm using a TDBADvListView control.
UniQuery1.Close;
UniQuery1.SQL.Clear;
SQL_QUERY:= 'insert into ListaCamiones(Tablilla,Marca,Modelo,Color) Values ('
+QuotedStr(a1)+','+
QuotedStr(a2)+','+
QuotedStr(a3)+','+
QuotedStr(a4)+')';
UniQuery1.SQL.Text := SQL_QUERY;
UniQuery1.Execute;
Do I need to do, Select * From ListaCamiones;
So I can see the information back on my TDBADvListView?
The answer is both yes and no!
Yes in that you do have to perform a SELECT query again in order to aggregate the modified recordset, no in that you don't have to perform the query as a separate execution.
If you append a semicolon at the end of your INSERT/UPDATE/DELETE query string, and immediately follow that by the desired SELECT query, your call to Execute will simultainiously update the records and aggregate the updated recordset for display.
Additionally, I would change the way you're building your SQL string too!
const
INSERT_QUERY_STRING = 'INSERT INTO ListaCaminoes(Tablilla, Marca, Modelo, Color) VALUES ("%s", "%s", "%s", "%s"); SELECT * FROM ListaCaminoes';
// Now inside your method
UniQuery1.SQL.Text := Format(INSERT_QUERY_STRING, [a1, a2, a3, a4]);
UniQuery1.Execute;
Hope it helps!
In general, yes, because in my experience when you make database changes via SQL statements:
no database component automatically refreshes the query,
no database can refresh the data in your application when the data
has changed in the database.
I recommend that you use a separate query component (UniQuery2) to execute your SQL statement. The you can use the ReQuery method of your Query to re-execute your original query (UniQuery1). Depending on the database components you are using, your local cursor may be reset.
Alternately you can Append/Insert to add records and Edit to change records of UniQuery1. This avoids the need to re-execute your original query because the changes are added to the dataset records buffered locally by the Query component. But, re-executing the query is necessary to get records that were added/edited by other users since your query was last executed.
If you just inserted the Information to the Database you have got it already!
In some SQL-Variants (in mySQL I am shure) you can have the command "insert_id()" from the API, that returns the AUTO_INCREMENT - value of the last inserted Dataset.
If you just want to get this ID, it is the way to go (on mySQL, like I said), but if you want to have other data you have to Query it again. In a combined query (like posted before) or in two seperate queries.
Glad to help!
I am trying call a database-function from HQL. The HQL statement should just call the function and return its value, like this
select someFunction(:someParameter)
If I try to call select current_timestamp().
It fails with
NHibernate.Hql.Ast.ANTLR.QuerySyntaxException: Exception of type 'Antlr.Runtime.MismatchedTreeNodeException' was thrown. near line 1, column 24 [select current_timestamp()]
I know that there is not much reason for retrieving the current timestamp. But I have created a few user-defined database-functions that I would like to unit-test by calling them from HQL.
It seems to me that it's not possible to write a HQL statement without a FROM and WHERE clause. Can this be true?
IQuery query = unitOfWork.Session.CreateQuery("select current_timestamp()");
var ts = query.UniqueResult();
This could work if you explicitly make it an SQL Query, not an HQL query:
var query = unitOfWork.Session.CreateSQLQuery("select current_timestamp()");
It doesn't make much sense to call a function like that. Either you have a stored procedure which should be called using other methods, or you have a function which is not related to the DB at all, and therefore should not be running via the database to begin with.
In any case, if the function doesn't work on a set of rows, can't you just add some dummy FROM clause, for example on a small static table?
I'm trying using a TAdoTable component,
On form Create I call .Append() and in a button i call .Post()
but it loads the entire table! I don't need it to load anything, just need to insert a row into this table.
I was wondering if there is "good way" of inserting data into database with Ado, i already tried using the a "manual" approach with TAdoCommand but it doesn't seems right to me
I generate the INSERT query using Format() and all string fields are escaped with QuotedStr()
Thanks in advance!
Arthur.
You can use a TADODataset (or TADOQuery).
The way I do it sometimes is with by setting the CommandText to return 0 records from the table, i.e. SELECT TOP 0 * FROM [table], then use .Append and .Post
But personally, I prefer writing the SQL, such as with a TADOCommand
Use the TADOQuery object if you don't need to display the table's data.
Basically:
Use TADOQuery.SQL.Text to set the SQL command
Use TADOQuery.ExecSQL method to fire the SQL command
You can also use the TADOCommand component, and have it execute the specific SQL command. If you find yourself performing the same command over and over again (like inserts into a table) then consider using parameters rather than directly changing the SQL for every call. Parameters are easy to use, just place a :PARAMNAME in your sql, then use the parameters object on the ado component your using to set the value. For example:
Assuming the CommandText of the TAdoCommand component contains "INSERT INTO TABLENAME (FIELD1) VALUES (:FIELDVALUE1)"
AdoCommand1.Parameters.ParamByName('FIELDVALUE1').Value := 'TEST'
AdoCommand1.Execute;
When the above sql is executed, then the string "TEST" would be written to FIELD1.
var
CountVar: Integer;
begin
TADOConnection1.Execute(ASQLInsertStatement, CountVar, [adExecuteNoRecords]);
end;