Memory leak in method - ios

I've got a memory leak in method that reads data from db. If I do understand right, the whole evil lives in this particular string:
whole method listing:
-(NSMutableArray*)returnNominals:(int)subCountryID
{
NSArray *paths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path =
[documentsDirectory stringByAppendingPathComponent:databaseName];
NSMutableArray *nominals=[[[NSMutableArray alloc]init]autorelease];
if (sqlite3_open([path UTF8String], &database) == SQLITE_OK)
{
const char* sqlNominals=sqlite3_mprintf("SELECT noms.nominalID, noms.nominal,noms.nominalName,rel.nominalImg,noms.priority\
FROM nominals AS noms\
INNER JOIN NominalsAndSubCountriesRelation as rel\
ON noms.nominalID=rel.NominalID\
WHERE rel.SubcountryID=%i\
ORDER BY noms.priority",subCountryID);
sqlite3_stmt *statement;
int sqlResult = sqlite3_prepare_v2(database, sqlNominals, -1, &statement, NULL);
if ( sqlResult== SQLITE_OK)
{
while (sqlite3_step(statement) == SQLITE_ROW)
{
Nominal *nom=[[Nominal alloc]init];
nom.nominalID=sqlite3_column_int(statement, 0);
char *nominal=(char *)sqlite3_column_text(statement, 1);
char *nominalName=(char*)sqlite3_column_text(statement, 2);
char *nominalImg=(char*)sqlite3_column_text(statement, 3);
nom.nominal=(nominal)?[NSString stringWithUTF8String:nominal]: #"";
nom.nominalName=(nominalName)?[NSString stringWithUTF8String:nominalName]: #"";
nom.nominalImg=(nominalImg)?[NSString stringWithUTF8String:nominalImg]: #"noimg";
[nominals addObject:nom];
[nom release];
}
sqlite3_finalize(statement);
}
}
else
{
[self dbConnectionError];
}
return nominals;
}
And finally when viewDidLoad in another class uses this method:
.h
#interface Nominals : UIViewController
{
NSMutableArray *nominalsArr;
NSInteger subCountryID;
}
#property(nonatomic,retain)NSMutableArray *nominalsArr;
#property(nonatomic)NSInteger subCountryID;
.m
- (void)viewDidLoad
{
[super viewDidLoad];
[[self navigationController]setToolbarHidden:YES animated:YES];
DBAccess *dbAccsess=[[DBAccess alloc]init];
self.nominalsArr=[dbAccsess returnNominals:subCountryID];
[dbAccsess closeDataBase];
[dbAccsess release];
}
- (void)dealloc
{
[tableView release];
[searchBar release];
[_toolBar release];
[nominalsArr release];
[searchController release];
[filteredItems release];
[super dealloc];
}
I've checked my code with analyzer and it says I've got no issues.
Please help me to solve this leak.

You have a leak on sqlNominals.
The sqlite3_mprintf() and sqlite3_vmprintf() routines write their results into memory obtained from sqlite3_malloc(). The strings returned by these two routines should be released by sqlite3_free().

Related

Open DB in documents folder

I have an sqlite file in my documents folder (I cheched and it's there). The issue is that the function openDatabase always prints Yes, even if I give it wrong path, so this is wierd.
The second thing is
if (sqlite3_prepare_v2(localDB,query_stmt, -1, &statement, NULL) == SQLITE_OK)
it always goes to else and print "Error on SQLITE_OK". Can you please help me with my code:
#interface SQLReader ()
{
sqlite3 *localDB;
}
#end
#implementation SQLReader
- (void)viewDidLoad {
[super viewDidLoad];
[self openDatabase];
sqlite3_stmt *statement;
NSString *querySQL = #"SELECT * FROM Animations";
const char *query_stmt = [querySQL UTF8String];
if (sqlite3_prepare_v2(localDB,query_stmt, -1, &statement, NULL) == SQLITE_OK)
{
if (sqlite3_step(statement) == SQLITE_ROW)
{
NSString *addressField = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)];
NSString *phoneField = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 1)];
NSLog(#"%#",addressField);
NSLog(#"%#",phoneField);
}
else
{
NSLog(#"%s","Match not found");
}
sqlite3_finalize(statement);
}
else
{
NSLog(#"%s","Error on SQLITE_OK");
}
}
- (void)openDatabase
{
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
char *dbpath = (char *)[[documentsPath stringByAppendingPathComponent: #"Bemad/IR_World/DB/IRRMobile.sqlite"] UTF8String];
BOOL openDatabaseResult = sqlite3_open(dbpath, &localDB);
NSLog(openDatabaseResult ? #"DB: Yes" : #"DB: No");
}

sqlite3_prepare not ok in xcode

I have the following code inside a .m file and i can get to where NSLog says OK BEFORE PREPARE but i cant get to NSLog OK INSIDE PREPARE. What is wrong with the if statement line that is not working? I know i have an sqlite database. I do have a table called school. It has one row of data in the school table.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
arrayOfSchools = [[NSMutableArray alloc]init];
[[self schoolTableView]setDelegate:self];
[[self schoolTableView]setDataSource:self];
sqlite3_stmt *statement;
if(sqlite3_open([dbPathString UTF8String], &eduLogDB)==SQLITE_OK){
[arrayOfSchools removeAllObjects];
NSString *querySql = [NSString stringWithFormat:#"SELECT * FROM school"];
const char *query_sql = [querySql UTF8String];
NSLog(#"OK BEFORE PEPARE");
if(sqlite3_prepare(eduLogDB, query_sql, -1, &statement, NULL)==SQLITE_OK){
NSLog(#"OK INSIDE PREPARE");
while (sqlite3_step(statement)==SQLITE_ROW){
NSString *schoolName = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement,1)];
School *school = [[School alloc]init];
[school setSchoolName:schoolName];
[arrayOfSchools addObject:school];
}
}
}
[[self schoolTableView]reloadData];
}

Store String from SQLite to NSMutableArray

I'm working on an app that displays various feeds using ASIHTTPRequest. The user can add new sources to the app that are stored in an SQLite database. Currently I give the feeds to the app in the viewDidLoad method of my FeedsViewController but i want to be able to retrieve the data that contains the link for the source and store it in an array to use it.
Currently the app looks like and below the current code:
- (void)viewDidLoad
{
[super viewDidLoad];
self.title =#"Lajmet";
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
//self.tabBarController.tabBar.tintColor = [UIColor blackColor];
self.allEntries = [NSMutableArray array];
self.queue = [[NSOperationQueue alloc] init];
self.feeds = [NSMutableArray arrayWithObjects:#"http://pcworld.al/feed",#"http://geek.com/feed", #"http://feeds.feedburner.com/Mobilecrunch",#"http://zeri.info/rss/rss-5.xml",
nil];
[self.tableView reloadData];
[self refresh];
}
My view that contains the function (AddSourcesViewController) to add and delete new sources looks like this and here the code:
- (void)viewDidLoad
{
[super viewDidLoad];
arrayOfSource = [[NSMutableArray alloc]init];
[[self myTableView]setDelegate:self];
[[self myTableView]setDataSource:self];
[self createOrOpenDB];
// Display sources in table view
sqlite3_stmt *statement;
if (sqlite3_open([dbPathString UTF8String], &sourceDB)==SQLITE_OK) {
[arrayOfSource removeAllObjects];
NSString *querySql = [NSString stringWithFormat:#"SELECT * FROM SOURCES"];
const char* query_sql = [querySql UTF8String];
if (sqlite3_prepare(sourceDB, query_sql, -1, &statement, NULL)==SQLITE_OK) {
while (sqlite3_step(statement)==SQLITE_ROW) {
NSString *name = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 1)];
NSString *link = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 2)];
NSString *category = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 3)];
SourceDB *source = [[SourceDB alloc]init];
[source setName:name];
[source setLink:link];
[source setCategory:category];
[arrayOfSource addObject:source];
}
}
}
[[self myTableView]reloadData];
}
- (void)createOrOpenDB
{
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docPath = [path objectAtIndex:0];
dbPathString = [docPath stringByAppendingPathComponent:#"sources.db"];
char *error;
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:dbPathString]) {
const char *dbPath = [dbPathString UTF8String];
//creat db here
if (sqlite3_open(dbPath, &sourceDB)==SQLITE_OK) {
const char *sql_stmt = "CREATE TABLE IF NOT EXISTS SOURCES (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT, LINK TEXT, CATEGORY TEXT)";
sqlite3_exec(sourceDB, sql_stmt, NULL, NULL, &error);
sqlite3_close(sourceDB);
}
}
}
- (IBAction)addSourceButton:(id)sender
{
char *error;
if (sqlite3_open([dbPathString UTF8String], &sourceDB)==SQLITE_OK) {
NSString *inserStmt = [NSString stringWithFormat:#"INSERT INTO SOURCES(NAME,LINK,CATEGORY) values ('%s', '%s','%s')",[self.nameField.text UTF8String], [self.linkField.text UTF8String],[self.categoryField.text UTF8String]];
const char *insert_stmt = [inserStmt UTF8String];
if (sqlite3_exec(sourceDB, insert_stmt, NULL, NULL, &error)==SQLITE_OK) {
NSLog(#"Source added");
SourceDB *source = [[SourceDB alloc]init];
[source setName:self.nameField.text];
[source setLink:self.linkField.text];
[source setCategory:self.categoryField.text];
[arrayOfSource addObject:source];
}
sqlite3_close(sourceDB);
}
}
- (IBAction)deleteSourceButton:(id)sender
{
[[self myTableView]setEditing:!self.myTableView.editing animated:YES];
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
SourceDB *s = [arrayOfSource objectAtIndex:indexPath.row];
[self deleteData:[NSString stringWithFormat:#"Delete from sources where name is '%s'", [s.name UTF8String]]];
[arrayOfSource removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
-(void)deleteData:(NSString *)deleteQuery
{
char *error;
if (sqlite3_exec(sourceDB, [deleteQuery UTF8String], NULL, NULL, &error)==SQLITE_OK) {
NSLog(#"Source deleted");
}
}
- (IBAction)showSourceButton:(id)sender
{
sqlite3_stmt *statement;
if (sqlite3_open([dbPathString UTF8String], &sourceDB)==SQLITE_OK) {
[arrayOfSource removeAllObjects];
NSString *querySql = [NSString stringWithFormat:#"SELECT * FROM SOURCES"];
const char* query_sql = [querySql UTF8String];
if (sqlite3_prepare(sourceDB, query_sql, -1, &statement, NULL)==SQLITE_OK) {
while (sqlite3_step(statement)==SQLITE_ROW) {
NSString *name = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 1)];
NSString *link = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 2)];
NSString *category = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 3)];
SourceDB *source = [[SourceDB alloc]init];
[source setName:name];
[source setLink:link];
[source setCategory:category];
[arrayOfSource addObject:source];
}
}
}
[[self myTableView]reloadData];
}
Now i created a method in my FeedsViewConrtoller:
-(void)ReadData
{
[self createOrOpenDB];
feedsArray = [[NSMutableArray alloc] init];
const char *dbPath = [dbPathString UTF8String];
if (sqlite3_open(dbPath, &sourceDB)==SQLITE_OK)
{
const char *sqlstmt = "SELECT LINK FROM SOURCES";
sqlite3_stmt *completedstmt;
if (sqlite3_prepare_v2(sourceDB, sqlstmt, -1, &completedstmt, NULL)==SQLITE_OK)
{
while(sqlite3_step(completedstmt)==SQLITE_ROW)
{
NSString *link = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(completedstmt, 2)];
SourceDB *source = [[SourceDB alloc]init];
[source setLink:link];
[feedsArray addObject:link];
}
}
}
}
And when i change
self.feeds = [NSMutableArray arrayWithObjects:#"http://pcworld.al/feed",#"http://geek.com/feed", #"http://feeds.feedburner.com/Mobilecrunch",#"http://zeri.info/rss/rss-5.xml",
nil];
to:
self.feeds = [NSMutableArray arrayWithArray:feedsArray];
i get the following error:
2013-08-14 15:03:55.328 ShqipCom[3128:c07] (null)
What am i doing wrong here?
Thanks a lot!
Granit
In ReadData, you're returning one column, but then retrieving the third column with:
NSString *link = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(completedstmt, 2)];
That should be:
NSString *link = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(completedstmt, 0)];
A couple of other thoughts:
Part of the reason it's hard for us to answer this is that you aren't reporting SQLite errors. I'd suggest logging when a SQLite test failed, e.g.:
if (sqlite3_prepare_v2(sourceDB, sqlstmt, -1, &completedstmt, NULL)==SQLITE_OK
{
while(sqlite3_step(completedstmt)==SQLITE_ROW)
{
NSString *link = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(completedstmt, 2)];
SourceDB *source = [[SourceDB alloc]init];
[source setLink:link];
[feedsArray addObject:link];
}
}
whereas you might want something like:
if (sqlite3_prepare_v2(sourceDB, sqlstmt, -1, &completedstmt, NULL)!=SQLITE_OK
{
NSLog(#"%s: prepare error: %s", __FUNCTION__, sqlite3_errmsg(sourceDB));
return;
}
int rc;
while ((rc = sqlite3_step(completedstmt)) == SQLITE_ROW)
{
NSString *link = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(completedstmt, 2)];
SourceDB *source = [[SourceDB alloc]init];
[source setLink:link];
[feedsArray addObject:link];
}
if (rc != SQLITE_DONE)
{
NSLog(#"%s: step error: %s", __FUNCTION__, sqlite3_errmsg(sourceDB));
return;
}
You really should be checking the result of every SQLite call, and reporting an error message if not successful. Otherwise you're flying blind.
On your INSERT statement, are you 100% sure that those three fields will never have an apostrophe in them? (Also, if the user is entering any of this data, you have to be concerned about SQL injection attacks.) Generally you'd use ? placeholders in your SQL, you'd prepare the SQL with sqlite3_prepare_v2, and then use sqlite3_bind_text to bind text values to those placeholders, and then you'd sqlite3_step and confirm a return value of SQLITE_DONE.
Note, checking each and every sqlite3_xxx function call return result and doing all of the necessary sqlite3_bind_xxx calls is a little cumbersome. In your next project, if you want to streamline your SQLite code, you might want to consider using FMDB.
Your can add any object in NSMutableArray by
[myArray name addObject:mYString]; // add whatever object here;
if you want to add Array to you NSMutableArray
[myArray addObjectsFromArray:anOtherArray];

how to check data in sqlite table using primary ID [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I create one application that use sqlite DB in it.
I have one problem and it is any time run my application add NSDictionary in my table sqlite. I want once check sqlite and if data exist in table sqlite not add else add it.
this my code:
ViewController.h
#import <UIKit/UIKit.h>
#import "sqlite3.h"
#interface ViewController : UIViewController
{
sqlite3 * database;
}
#end
ViewController.m
#import "ViewController.h"
#define DatabaseName #"data.sqlite"
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *idd = [NSArray arrayWithObjects:#"122",#"234",#"453", nil];
NSArray *name = [NSArray arrayWithObjects:#"janatan",#"fred",#"john", nil];
NSArray *age = [NSArray arrayWithObjects:#"23",#"35",#"12", nil];
NSArray *sex = [NSArray arrayWithObjects:#"male",#"male",#"male", nil];
for (int i = 0; i < [idd count]; i++)
{
NSString * a = [idd objectAtIndex:i];
NSString * b = [name objectAtIndex:i];
NSString * c = [age objectAtIndex:i];
NSString * d = [sex objectAtIndex:i];
NSDictionary * dic = [NSDictionary dictionaryWithObjectsAndKeys:a,#"id",b,#"name",c,#"age",d,#"sex", nil];
NSString *query = [NSString stringWithFormat:#"insert into table1 (id,name,age,sex) values('%#','%#','%#','%#')",[dic objectForKey:#"id"],[dic objectForKey:#"name"],[dic objectForKey:#"age"],[dic objectForKey:#"sex"]];
NSLog(#"%#",query);
[self executeQuery:query];
}
}
-(NSString *) dataFilePath
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSLog(#"PATH %#",[documentsDirectory stringByAppendingPathComponent:DatabaseName]);
return [documentsDirectory stringByAppendingPathComponent:DatabaseName];
}
/*==================================================================
METHOD FOR INSERTING DATA IN DATABASE
==================================================================*/
-(void)executeQuery:(NSString *)query
{
//NSLog(#"QUERY : %#",query);
sqlite3_stmt *statement;
if(sqlite3_open([[self dataFilePath] UTF8String], &database) == SQLITE_OK)
{
if (sqlite3_prepare_v2(database, [query UTF8String], -1, &statement, NULL) == SQLITE_OK)
{
if (sqlite3_step(statement) != SQLITE_DONE)
{
sqlite3_finalize(statement);
}
}
else
{
NSLog(#"query Statement Not Compiled");
}
sqlite3_finalize(statement);
sqlite3_close(database);
}
else
{
NSLog(#"Data not Opened");
}
}
#end
also I want when NSDictionary changed for example arrays is Dictionary increase value update sqlite complete.
please explain me .
Use this method :
/*==================================================================
METHOD FOR CHECKING WHETHER RECORD EXISTS OR NOT IN DATABASE
==================================================================*/
-(BOOL)recordExistOrNot:(NSString *)query{
BOOL recordExist=NO;
if(sqlite3_open([[self dataFilePath] UTF8String], &database) == SQLITE_OK)
{
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(database, [query UTF8String], -1, &statement, nil)==SQLITE_OK)
{
if (sqlite3_step(statement)==SQLITE_ROW)
{
recordExist=YES;
}
else
{
//////NSLog(#"%s,",sqlite3_errmsg(database));
}
sqlite3_finalize(statement);
sqlite3_close(database);
}
}
return recordExist;
}
It will return YES if record exists else not.
Ex :
NSString *query = [NSString stringWithFormat:#"select * from yourtable where column_name = 'column_name'"];
NSLog(#"query : %#",query);
BOOL recordExist = [self recordExistOrNot:query];
if (!recordExist) {
// Insert your data
}
Hope it helps you.

Load data SQlite into htmlString iOS

I have an app that reads from sqlite database,data is read and included in the objects using this method ....I checked with NSLog
#import "ViewController1.h"
#import "Ricetta.h"
#import "AppDelegate.h"
static sqlite3_stmt *leggiStatement = nil;
#interface ViewController1 ()
#end
#implementation ViewController1
#synthesize Webmain, oggetto2;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//percorso file su cartella documents
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
NSString *path = [documentsDir stringByAppendingPathComponent:#"Rice.sqlite"];
//controllo se il file esiste
if(![[NSFileManager defaultManager] fileExistsAtPath:path])
{
//se non esiste lo copio nella cartella documenti
NSString *pathLocale=[[NSBundle mainBundle] pathForResource:#"Rice" ofType:#"sqlite"];
if ([[NSFileManager defaultManager] copyItemAtPath:pathLocale toPath:path error:nil] == YES)
{
NSLog(#"copia eseguita");
}
}
[self personalizzaAspetto];
[self carica_ID];
// NSString * query = #" SELECT Immagine, Titolo, Descrizione FROM LIBRO";
// NSArray * arrayQuery = [[NSArray alloc] initWithObjects:#"Immagine",#"Titolo",#"Descrizione",nil];
// NSArray * arrayElementi = [self caricaValoriMain:query :arrayQuery];
Webmain= [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 365)];
NSString *htmlString =[NSString stringWithFormat:#"<html> \n"
"<head> \n"
"<style type=\"text/css\"> \n"
"body {font-family: \"%#\"; font-size: %#;}\n"
"</style> \n"
"</head> \n"
"<body><center><img src='%#'/></center></body><center><h1>%#</h1></center><body bgcolor=\"#FFFFFF\" text=\" #ffa500\">%#</body></html>" ,#"futura",[NSNumber numberWithInt:15],oggetto2.Immagine,oggetto2.Titolo,oggetto2.Descrizione];
[Webmain loadHTMLString:htmlString baseURL:nil];
[self.view addSubview:Webmain];
-(void)carica_ID{
sqlite3 *database = NULL;
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
NSString *dbPath = [documentsDir stringByAppendingPathComponent:#"Rice.sqlite"];
if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK)
{
if(leggiStatement==nil){
const char *sql = "select Immagine,Titolo,Descrizione from LIBRO WHERE RicettaID=1";
if(sqlite3_prepare_v2(database, sql, -1, &leggiStatement, NULL) != SQLITE_OK)
NSAssert1(0, #"Errore creazione compiledState '%s'", sqlite3_errmsg(database));
}
//while(sqlite3_step(leggiStatement) == SQLITE_ROW)
if(SQLITE_DONE != sqlite3_step(leggiStatement))
{
NSString *titolo = [[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(leggiStatement, 1)];
NSLog(#"%#",titolo);
oggetto2.Titolo=titolo;
NSString *descrizione = [[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(leggiStatement, 2)];
NSLog(#"%#",descrizione);
oggetto2.Descrizione = descrizione;
NSString *image= [[NSString alloc]initWithUTF8String:(char *)sqlite3_column_text(leggiStatement, 0)];
NSLog(#"%#",image);
oggetto2.Immagine= image;
}
sqlite3_finalize(leggiStatement);
}
sqlite3_close(database);
}
#end
My problem is that I can not put them in webMain...objects in webMain remain empty.
I do not use Xib.
In the code snippet provided, you never perform the alloc and init of oggetto2. Thus, it is nil, and thus attempts to set its properties will achieve nothing.
In addition to your existing NSLog statements, I'd also suggest doing a NSLog of the htmlString right before you perform loadHTMLString, because it's easier to see what's going on with your HTML by looking at the source, rather than trying to make inferences from a blank web view.
Unrelated to your problem, but you probably should not have code that could potentially reusing your static sqlite3_stmt after you've finalized it. The first time you call carica_ID you would initialize the static leggiStatement. But you end up doing a sqlite_finalize but don't set leggiStatement to nil. If you ever called this method a second time, it won't sqlite3_prepare_v2 again, but you will have freed the resources associated with your prior leggiStatement.
A couple of easy fixes:
do not make leggiStatement a static global, but rather make it a local, non-static variable of the method;
if you do sqlite3_finalize, make sure you set leggiStatement to nil as well; or
don't call sqlite3_finalize, but rather just call sqlite3_reset, which will reset the prepared statement, but won't release its resources.

Resources