SQLite select statement assertion failure in iOS - ios

I get an assertion failiure on this statement;
SELECT keyphrase_id, keyphrase, url, googlename FROM keyphrases left join domains on keyphrases.domain_id = domains.domain_id where domain_id = ? and ifnull(keytime,'') != ? order by keyphrase desc;
I ran it through a SQL query checker and it highlighted the "!=" bit citing it wasn't correct syntax. This doesn't make sense to me since I was using this statement previously;
SELECT keyphrase_id, keyphrase, url, googlename FROM keyphrases left join domains on keyphrases.domain_id = domains.domain_id where ifnull(keytime,'') != ? order by keyphrase desc;
This is how I bind the where values;
sqlite3_bind_int(selStmt, 1, domain_ID);
sqlite3_bind_text(selStmt, 2, [dateString UTF8String] , -1, SQLITE_TRANSIENT);
I can't work this out at all and it's definitely nothing to do with the database being open or the statement being nil when executing etc. since the only component of the method I'm changing is the SQL statement.
Can anyone suggest any possible reasons for this?

If you get a return code from any sqlite3 function call that suggests an error, do another call to sqlite3_errmsg and look at the error message, e.g.
NSLog(#"%s err: %s", __FUNCTION__, sqlite3_errmsg(database));
This will tell you what's wrong.
Personally, I would have thought that the reference to domain_id in the where clause was ambiguous, but the sqlite3_errmsg will tell you precisely what's going on.

Related

EXECUTE FORMAT() USING in postgres is showing error for $

i will directly get to the code rather than explaining too much
execute format('
"$1" = select "Source1" from temp_tables._%s;
'::text, (translate("Song_Id_"::text, '-', '_')))
using "Source1__";
the table is dynamically created and the table name is all fine as i have used that table to insert some data into it. if i run this code, the error i am getting is
ERROR: syntax error at or near "$1"
LINE 1: $1 = select "Source1" from temp_tables._24af1593_3539_49fd_9...
^
QUERY: $1 = select "Source1" from temp_tables._24af1593_3539_49fd_9ef4_29307f301d38;
i have tried other method too like
execute
'$1 = select "Source1" from temp_tables._' || (translate("Song_Id_"::text, '-', '_')) ||';'
using "Source1__";
even this gives the same error.
note : "Source1__" is a variable of type text declared in the stored procedure where everything else is being executed too.
This is wrong. The EXECUTE command accepts only SQL statements. There is nothing statement like var = SELECT .... More - the you can pass just value by using clause USING. You cannot to pass any reference to variable. Solution is easy. Just use clause INTO
EXECUTE 'SELECT ... ' INTO target_plpgsql_variable
Please, read related documentation. Unfortunately, some parts the stored procedures are not extra intuitive because there is mix of two very different languages. It is good by reading documentation, because is hard to find correct solution without knowledge of possibilities and syntax.

TT X-trader API

Does anyone know how to query TT X-trader API to figure out if an order ( given order site-key ) is in the market?
Currently I'm doing a lookup on the siteKey, which should return an order object.
However, if the order is no longer in the market, an exception is thrown, which in MATLAB can be caught with a try|catch syntax.
try
...
ttOrderSet = xtrdr.OrderSet;
ttOrderObj = ttOrderSet.SiteKeyLookupEx( siteKey );
... % order is in the market
catch
... % Order isn't in the market
end
Problem with this mechanism is that I have bugs elsewhere in my code that need a breakpoint and this piece of code automatically causes a breakpoint to occur, which means that it unnecesarily stops everytime I query the order.
I'm sure a function exists such that one can query whether the order is live in the market or not.

Where not null for reference column showing error - rails

I want to query a table where multiple referenced column in not null.
I tried like this:
JobTypePresetting.where('comment_text == ?', nil)
JobTypePresetting.where('comment_text_id == ? OR part_listing_id == ?', nil, nil)
Even first is not working showing error like
ActiveRecord::StatementInvalid: PG::UndefinedFunction: ERROR: operator does not exist: integer == unknown
LINE 1: ...resettings"."template_id" = $2 AND (comment_text_id == NULL)
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
How do i query this, currently i'm using like
JobTypePresetting.where('comment_text_id is not null or part_listing_id is not null')
You need to use single(=) oprator.
JobTypePresetting.where('comment_text = ?', nil)
Hope this may work for you.
Try to use Arel, much easier to construct complex sql queries. They have been part of rails from 3 release. https://github.com/rails/arel
jtp = JobTypePresetting.arel_table
JobTypePresetting.where(jtp[:comment_text_id].not_eq(nil).or(jtp[: part_listing_id].not_eq(nil)))
Hope it helps

Where not null using Linq

I have a mySQL database with a Website field that is of type VarChar. Some of these fields will be null on the database.
I have an MVC application that I sending the database information to.
I am trying to set up a filter on the Index page so I can filter by certain columns. I am using the Request.QueryString to do this.
switch (Request.QueryString["FilterOptionSelect"])
{ case "CountyName":
if (!string.IsNullOrEmpty(filteredText))
{
filteredText = filteredText.ToUpper();
var modelFiltered = from n in model
where n.CountyName.ToUpper().Contains(filteredText)
select n;
return View(modelFiltered);
}
break;
case "Website":
if (!string.IsNullOrEmpty(filteredText))
{
filteredText = filteredText.ToUpper();
var modelFiltered = from n in model
where n.CountyWebsite.ToUpper().Contains(filteredText)
select n;
return View(modelFiltered);
}
break;
}
The only problem I have is on the Website case. It gives me a Object reference not set to an instance of an object. on the WHERE CLAUSE of the Website case. When I debug, my model is not null (it has 130+ items inside...some with website info and some without website info).
I have already tried using the Lambda method (which had the same problem). I have also tried using where n.CountyWebsite.ToUpper().Contains(filteredText) && n.CountyWebsite != null which did not work either.
You were on the right track with your second attempt, but you need to switch the order of those statements.
where n.CountyWebsite != null && n.CountyWebsite.Contains(filteredText)
Just like all the other && operators, you don't want to evaulate any websites that are null, so do that operation first.
Also, .Contains in EF automatically is case-insensitive, so you don't need the ToUpper().
Try this, I think this will solve.
!String.IsNullOrEmpty(n.CountyWebsite) && n.CountyWebsite.Contains(filteredText)

"FOR UPDATE" clause is throwing error in esql program

We are developing a migrate program. There are nearly 80 million records are there in DB. The code is as follows:
static int mymigration(struct progargs *args)
{
exec sql begin declare section;
const char *selectQuery;
const char *updateQuery;
long cur_start;
long cur_end;
long serial;
long number;
char frequency[3];
exec sql end declare section;
selectQuery = "select * from mytable where number >= ? and number <= ? for update of frequency ,status";
updateQuery = "update mytable set frequency = ?, "
" status = ? "
" where current of my_cursor";
cur_start= args->start;
cur_end = args->end;
exec sql prepare my_select_query from :selectQuery;
/* Verify the sql code for error here */
exec sql declare my_select_cursor cursor with hold for my_select_query;
exec sql open my_select_cursor using :cur_start, :cur_end;
/* Verify the sql code for error here */
exec sql prepare my_update_query from :updateQuery;
/* Verify the sql code for error here */
while (1)
{
number = 0;
serial = 0;
memset(frequency,0,sizeof(frequency));
exec sql fetch my_select_cursor into number,:serial,:frequency;
if (sqlca.sqlcode != SQL_OK)
break;
exec sql execute my_update_query using :frequency, :frequency;
}
exec sql close my_select_trade_cursor;
}
While implementing this, we are getting the error message "-255". We found one solution as to add being work and commit work. Since we have large amount of data, this might clutter the transaction log.
Is there any other solution available for this problem? The IBM website for informix shows the usage is correct.
Appreciate the help in advance.
Thanks,
Mathew Liju
Error -255 is "Not in transaction".
I see no BEGIN WORK (or COMMIT WORK or ROLLBACK WORK) statements.
You need to add BEGIN WORK before you open the cursor with the FOR UPDATE clause. You then need to decide whether to commit periodically to avoid overlong transactions. The fact that you use a FOR HOLD cursor shows that you had thought about using sub-transactions; if you were not going to do so, you would not use that clause.
Note that Informix has 3 primary database logging modes:
Unlogged (no transaction support)
Logged (by default, each statement is a singleton transaction; an explicit BEGIN WORK starts a multi-statement transaction terminated by COMMIT WORK or ROLLBACK WORK).
Logged MODE ANSI (slightly simplistically, you are automatically in a transaction; you need an explicit COMMIT or ROLLBACK to terminate a transaction, and may then, optionally, use an explicit BEGIN, but the BEGIN is not actually necessary).
From the symptoms you describe, you have a logged but not MODE ANSI database. Therefore, you must explicitly code the BEGIN WORK statements.

Resources