I have three fields say F1, F2, F3. I want to find all the documents which have all three fields values as null. Can I achieve this by using BooleanQuery? If I use MUST_NOT clause for all three fields then It will not return the documents which have one of these fields as non null value.
I'm talking about implementing something like this
BooleanQuery booleanQuery = new BooleanQuery();
booleanQuery.add(new TermQuery(new Term(F1,"")), BooleanClause.Occur.MUST_NOT);
booleanQuery.add(new TermQuery(new Term(F2,"")), BooleanClause.Occur.MUST_NOT);
booleanQuery.add(new TermQuery(new Term(F3,"")), BooleanClause.Occur.MUST_NOT);
This surely is not going to work.How can i achieve this ? any help would be helpful.
Not sure how your index looks like but you wanna achieve this right?
you wanna have a query which is searching with this fields and this fields have to be empty
BooleanQuery booleanQuery = new BooleanQuery();
booleanQuery.add(new TermQuery(new Term(F1,"")), BooleanClause.Occur.MUST);
booleanQuery.add(new TermQuery(new Term(F2,"")), BooleanClause.Occur.MUST);
booleanQuery.add(new TermQuery(new Term(F3,"")), BooleanClause.Occur.MUST);
This boolean query is searching for a empty terms (second param of term is "") in this field, for each field it has to be a must.
Related
I have a {"Name":[{"value":"First Name"}],"City":[{"value":"Delhi"},{"value":"London"]} varchar value stored in a column of db. I need to search every Person having city Delhi using JPQL. Is it good to store JSON string in db?
Well, substring matching can work for you in the most of the cases, but it's not precise and will be slow.
You can try something like that:
StringBuilder sb = new StringBuilder();
sb.append("SELECT table FROM Table table ");
sb.append("WHERE table.columnWithJson like '%\"City\":[%:city%]}' ");
Query q = em.createQuery(sb.toString())
q.setParameter("city", ""Delhi);
If you are using some database with support for regular expression and don't mind to abandon JPQL and use native query, this is an alternative for you too.
I have a Datatable with the columns
Name|Age|Job
I query that Datatable with Linq and do some manipulations.
Dim query = From row in dt.AsEnumerable.where(...)
The returned object is a datatable that I need for further procedures.
But now I have to change the column sequence to
Age|Name|Job
and do not know how to do that.
I tried:
Dim query1 = From column In query
Select column.Age, column.Name, column.Job
But query1 is not a Datatable object anymore. Could anyone help me get the resorting of the columns done that I still have a datatable object?
You can use DataColumn.SetOrdinal() method to reorder columns. Assuming that query is a datatable with columns Name|Age|Job, the following will reorder the columns to Age|Name|Job :
query.Columns("Age").SetOrdinal(0)
query.Columns("Name").SetOrdinal(1)
I'm using FillSchema on a OracleDataAdapter in .net. The SelectCommand works on a global temporary table.
For the first run, this works great. I will get the schema of the global temporary table
Then I drop that temporary table and great a new temporary table with a different schema.
After that, for the second run, the FillSchema method will still return the schema from the old dropped temporary table.
Am I missing something? Shouldn't the select command query the schema from the new version of the temp table?
Thanks for any help!
What did not work:
The OracleDataAdapter.SelectCommand that was used by
FillSchema was:
Select * from TableName
What works:
I needed to change that query to the exact schema,
then it works:
Select column1,column2,column3 from TableName
I don't understand exactly why, but that solved my problem.
It will return the schema of the new global temporary table.
Is this a caching problem of the oracle server? Because the
tableName is always the same?
To use procedure ways to solve this Problem
OracleParameter inputParam = new OracleParameter("TABLE_NAME_IN",OracleDbType.Varchar2,"TEST",ParameterDirection.Input); //Query TableName
OracleParameter refParam = new OracleParameter("OUTPUT",OracleDbType.RefCursor,ParameterDirection.Output);//RefCursor
DataTable dt = new DataTable();//Fill DataTable
using (OracleCommand dbCommand = new OracleCommand("PKG_SYS.SELECT_TABLE_DATA",orclConnection))
{
dbCommand.CommandType = CommandType.StoredProcedure;
dbCommand.Parameters.Add(inputParam);
dbCommand.Parameters.Add(refParam);
using (OracleDataAdapter da = new OracleDataAdapter())
{
da.SelectCommand = dbCommand;
da.Fill(dt);
}
}
I have exactly the same problem like in this question (attempt to use CDbCriteria with column named key, which is a reserved word in MySQL). However, provided solution:
$criteria = new CDbCriteria;
$criteria->condition = 't.key=:key';
$criteria->params = array(':key'=>$this->key);
$criteria->compare('position', $this->position);
$criteria->compare('dictionary', $this->dictionary);
works for me only partially. I don't get exception anymore, but search works for key column only. All other are ignored (if key is set, respects only this value in search, if it is not set -- always returns empty results set).
What am I missing? How should I construct CDbCriteria queries, when my table contains reserverd words as column names, so search would respect all other (non-reserved) columns as well, not only this one?
CDbCriteria::compare() adds condition only if parameter is set otherwise no action is taken.See Here
$criteria->condition = 't.key=:key';
$criteria->params = array(':key'=>$this->key);
However this logic works irrespective of whether key is set or not. So basically your condition becomes
SELECT * FROM `some_table` t WHERE t.key =:key
even though the key value being blank resulting in your query breaking when key attribute is not set
So if you modify your statement like this then it work
if(isset($this->key){
$criteria->condition = 't.key=:key';
$criteria->params = array(':key'=>$this->key);
}
in this case this statement is only activated when key attribute is set, it is ignored otherwise, and your query will not break
suppose i have a field with counts and when I get some updated counts I want to delete the fields where the count went down
$query = "DELETE FROM $table
WHERE id='$id' AND ($count-count)<0;";
how would i do something like this (I don't think this works)
It's hard to tell without more information, but this seems typical:
$query = "DELETE FROM $table WHERE count < $count";