Sql Join does not show the new inserted rows in sqlite table - iphone

I have IPhone application in which I am inserting data. It works fine when I fetch all the data without any condition then it works fine if given any condition like
following query then it does not show anything.
NSString *select =
[NSString stringWithFormat:
#"SELECT * from ContentMaster As ml
LEFT JOIN ContentTagging As cat
ON cat.ContentID = ml.ContentID
where cat.ContenTagText= \'%#\'" ,appDelegate.tagInput];
const char *sql = [select UTF8String];
then it does not show any thing using this if i use the select * form ContentMaster then it shows all records added.

Try this.
SELECT * from ContentMaster
LEFT JOIN ContentTagging
ON ContentMaster.ContentID = ContentTagging.ContentID
WHERE ContentTagging.ContenTagText= \'%#\'"

Related

See Oracle SQL Developer Procedure's Details in Dbeaver

I am new for using DBeaver. Can I see Oracle SQL Developer Procedure's Details in Dbeaver?
like this
enter image description here
Use the data dictionary.
You can get details of the object using:
SELECT *
FROM ALL_OBJECTS
WHERE object_name = 'PROCEDURE_NAME';
You can get further details on the procedure using:
SELECT *
FROM ALL_PROCEDURES
WHERE object_name = 'PROCEDURE_NAME';
You can get even more details on the compilation settings using:
SELECT *
FROM all_plsql_object_settings
WHERE name = 'PROCEDURE_NAME'
You can combine it all into one query:
SELECT o.owner,
o.object_name,
o.subobject_name,
o.object_id,
o.data_object_id,
o.object_type,
o.created,
o.last_ddl_time,
o.timestamp,
o.status,
o.temporary,
o.generated,
o.secondary,
o.namespace,
o.edition_name,
s.nls_length_semantics,
s.plsql_ccflags,
s.plsql_code_type,
s.plsql_debug,
s.plsql_optimize_level,
s.plsql_warnings
FROM all_objects o
LEFT OUTER JOIN all_plsql_object_settings s
ON (o.owner = s.owner AND o.object_name = s.name AND o.object_type = s.type)
WHERE o.object_name = 'PROCEDURE_NAME';
fiddle

AS400 index configuration table

How can I view index of particular table in AS400? In which table index description of table is stored?
If your "index" is really a logical file, you can see a list of these using:
select * from qsys2.systables
where table_schema = 'YOURLIBNAME' and table_type = 'L'
To complete the previous answers: if your AS400/IBMi's files are "IBM's old style" Physical and Logical files, the qsys2.syskeys and qsys2.sysindexes are empty.
==> you retrieve index infos in QADBKFLD (for "indexes" info) and QADBXREF(for fields list) tables
select * from QSYS.QADBXREF where DBXFIL = 'YOUR_LOGICAL_FILE_NAME' and DBXLIB = 'YOUR_LIBRARY'
select * from QSYS.QADBKFLD where DBKFIL = 'YOUR_LOGICAL_FILE_NAME' and DBKLB2 = 'YOUR_LIBRARY'
WARNING: YOUR_LOGICAL_FILE_NAME is not your "table name", but the name of the file ! You have to join another table QSYS.QADBFDEP to match LOGICAL_FILE_NAME / TABLE_NAME :
To found indexes from your table's name:
Select r.*
from QSYS.QADBXREF r, QSYS.QADBFDEP d
where d.DBFFDP = r.DBXFIL and d.DBFLIB=r.DBXLIB
and d.DBFFIL = 'YOUR_TABLE_NAME' and d.DBFLIB = 'YOUR_LIBRARY'
To found all indexes' fields from your table:
Select DBXFIL , f.DBKFLD, DBKPOS , t.DBXUNQ
from QSYS.QADBXREF t
INNER JOIN QSYS.QADBKFLD f on DBXFIL = DBKFIL and DBXLIB = DBKLIB
INNER JOIN QSYS.QADBFDEP d on d.DBFFDP = t.DBXFIL and d.DBFLIB=t.DBXLIB
where d.DBFFIL = 'YOUR_TABLE_NAME' and d.DBFLIB = 'YOUR_LIBRARY'
order by DBXFIL, DBKPOS
if your indexes is create with SQL you can see liste of index in sysindexes system view
SELECT * FROM qsys2.sysindexes WHERE TABLE_SCHEMA='YOURLIBNAME' and
TABLE_NAME = 'YOURTABLENAME'
if you want detail columns for index you can join syskeys tables
SELECT KEYS.INDEX_NAME, KEYS.COLUMN_NAME
FROM qsys2.syskeys KEYS
JOIN qsys2.sysindexes IX ON KEYS.ixname = IX.name
WHERE TABLE_SCHEMA='YOURLIBNAME' and TABLE_NAME = 'YOURTABLENAME'
order by INDEX_NAME
You could also use commands to get the information. Command DSPDBR FILE(LIBNAME/FILENAME) will show a list of the objects dependent on a physical file. The objects that show a data dependency can then be further explored by running DSPFD FILE(LIBNAME/FILENAME). This will show the access paths of the logical file.

OR operator not working in query sqlite iphone

I am using Join operator to check two values in table but it does not work
select = [[NSString alloc] initWithFormat:#"select * FROM ContentMaster LEFT JOIN Category ON ContentMaster.CategoryID= Category.CategoryID where ContentMaster.ContentTitle='%#' || ContentMaster.ContentTagText='%#' ",appDelegate.tagInput,appDelegate.tagInput];
If i do not use operator and use one in where clause then it shows result.
like
select = [[NSString alloc] initWithFormat:#"select * FROM ContentMaster LEFT JOIN Category ON ContentMaster.CategoryID= Category.CategoryID where ContentMaster.ContentTitle='%#'",appDelegate.tagInput];
select = [[NSString alloc] initWithFormat:#"select * FROM ContentMaster LEFT JOIN Category ON ContentMaster.CategoryID= Category.CategoryID where ContentMaster.ContentTagText='%#'",appDelegate.tagInput];
Any idea how to fix this issue so that or operator works
In SQL (and SQLite in particular), operator || typically means string concatenation.
If you want logical or, use operator OR.
In sqlite just use or for logical or operation:
SELECT *
FROM ContentMaster
LEFT JOIN Category ON ContentMaster.CategoryID = Category.CategoryID
WHERE ContentMaster.ContentTitle = '%#' OR ContentMaster.ContentTagText= '%#'

How to run SQLite Query even if Input is Blank

I am doing an iPad project, there are 3 tables in UI. if i select row in each table. Sqlite query will take the value from table and run the query. please find my Query below.
NSString * str3=tableFou.string4;
NSString * str4=tableFiv.string5;
NSString * str2=tablethr.string3;
sqlite3 *database;
favorite=[[NSMutableArray alloc]init];
if(sqlite3_open([databasePath UTF8String], &database)== SQLITE_OK){
NSString *sql=[NSString stringWithFormat:#"Create view prizeview as SELECT country.name,item_country.id,text.text,substr(text,1,2) FROM country,item_country,prize,item_prize,gender,item_gender,text WHERE country.name = '%#' AND text.item = item_country.item AND country.id = item_country.id AND prize.name = '%#' and text.item=item_prize.item and prize.id = item_prize.id and gender.name = '%#' and text.item=item_gender.item and gender.id = item_gender.id ",str3,str4,str2];
const char *sqlStatement = [sql UTF8String];;
problem is that, the query is running if i select all the tables only.. but i want results if i select even one table. how can i do that?
Try with if condition use with and condition and pass all your str in if condition only.
use your if condition like this.
if(([propertyTypeLabel.text length]==0) || ([cityLabel.text length]==0 ) ||( [locationLabel.text length]==0 )|| ([priceLabel.text length] ==0)||([postedLabel.text length]==0))
In this like any of text is zero condition true you also use if ant of the table cell is tap your query run.
You can't search for empty fields unless the field is actually empty. F.ex. if you search
select * from mytable where username = "";
You won't find it, but if you are ok with the field being empty or whatever result, you must use like instead of =
select * from mytable where username like "%";
or better yet, you can create your query like this, lets say you have three fields to search for, username, firstname and lastname. The code below needs a few more if's and buts, but you should be able to make this work and only add the parameters to where if they fulfill the requirements.
NSMutableString *query = [[NSMutableString alloc] init];
[query appendString:#"select * from table where "];
if (username.text.lenghth >1) [query appendString:[NSString stringWithFormat:#"username = '%#'"]];
if (firstname.text.length >1) [query appendString:[NSString stringWithFormat:#"&& firstname = '%#'"]];
if (lastname.text.length >1) [query appendString:[NSString stringWithFormat:#"&& lastname = '%#'"]];
Hope this helps

How to use LIKE query in sqlite & iPhone

I'm using the following for a LIKE query. Is this technique for LIKE correct?
selectstmtSearch = nil;
if(selectstmtSearch == nil){
const char *sql = "SELECT col1, col2 FROM table1 t1 JOIN table2 t2 ON t1.cityid = t2.cityid where t1.cityname like ?001 order by t1.cityname";
if(sqlite3_prepare_v2(databaseSearch, sql, -1, &selectstmtSearch, NULL) == SQLITE_OK)
{
sqlite3_bind_text(selectstmtSearch, 1, [[NSString stringWithFormat:#"%%%#%%", searchText] UTF8String], -1, SQLITE_TRANSIENT);
}
}
The problem I'm having is after a few uses of this, I get an error 14 on sqlite3_open(), which is unable to open database. If I replace the LIKE with something such as:
SELECT col1, col2
FROM table1 t1
JOIN table2 t2 ON t1.cityid = t2.cityid
where t1.cityname = ?
order by t1.cityname
It works fine. I do open/close the DB before after the above code. Is there a way to troubleshoot exactly why the database can't be opened and what its relationship to my LIKE syntax is?
You must sqlite3_reset or sqlite3_finalize(selectstmtSearch) before you close the database connection.