Select data from variable_tableName in Sqlite - iphone

I am using Fmdb wrapper around Sqlite, everything is working fine.
Now I want to load data from a variable table, the table name is stored in an NSString. I don't know how to write query for that. Please help!

I never used FMDB Wrapper. But reading the Documetation, it looks like -executeQuery is a method from FMDatabase Class that takes the QueryString as a parameter and returns an object of FMResultSet Class. So, argument is of NSString type and you can use %# operator to add the dynamic string values in your QueryString.
Sample Code :
FMResultSet *results = nil;
results = [yourDB executeQuery:[NSString stringWithFormat:#"SELECT * FROM %#",variable_tableName]];

Related

QuickDialog not showing dates in correct way

I am using quickdialog to consume dynamic forms.
A webservice builds up a form with the quickdialog JSON.
For a QDateTimeInlineElement he provides me this JSON.
{"type":"QDateTimeInlineElement","title":"datum","placeholder":"vul in","bind":"textValue:datum","key":"datum","mode":"Date"},
{"type":"QDateTimeInlineElement","title":"tijd","placeholder":"vul in","bind":"textValue:tijd","key":"tijd","mode":"Time"},
{"type":"QDateTimeInlineElement","title":"datumtijd","placeholder":"vul in","bind":"textValue:datumtijd","key":"datumtijd","mode":"DateAndTime"},
In my code I put all the values in a dictionary using the following piece of code.
NSMutableDictionary *script = [NSMutableDictionary new];
[self.root fetchValueUsingBindingsIntoObject:script];
But when I look at an output of this dictionary I notice the following LOG
Date = "00:00:-34";
DateTime = "00:00:-34";
TIME = "00:00:-34";
Can anybody help me with this? Kind regards !

Parsing NSArray that has single value generated from a JSON message

I've combed the questions on here hoping to find a similar situation that I am in, but couldn't find one. My question deals with the NSJSONSerialization class in iOS 5, and how to handle parsing a single value returned from the JSONObjectWithData:options:error: method. The JSON data returned is a single value in an array that looks like this:
[1]
The data will either be 1 (as seen above) or 0, depending on the logic being done in the web service I'm using. As a side note, the web service is a WCF REST service. In XCode, the debugger displays the following after the deserialized JSON is assigned to a temporary NSArray object:
po parsedData
(NSArray *) $43 = 0x06e2ee70 <__NSCFArray 0x6e2ee70>( 1 )
When I try to get the value from the array using ObjectAtIndex:, I get this:
po [parsedData objectAtIndex:0]
(id) $44 = 0x06b1dad0 1
My question is: what is the hex value (0x06b1dad0) before the 1? Maybe a key or index that I am not accessing (I was thinking that I just didn't go far enough into the array to get the real value)? Does it have something to do with how the JSON is formatted? As I've been thinking about it, I have a feeling that the formatting is off.
The problem I am having is that I cannot get the actual value that is stored in the JSON message--when I access the element in the array parsedData and assign it to a variable, it is returning just the hex value and not 1.
Casting to NSInteger gives this:
po (NSInteger)[parsedData objectAtIndex:0]
(NSInteger) $45 = 112319184 1
Any insight into this would be greatly appreciated. I apologize if this has been addressed elsewhere in the forum.
Thanks.
Its likely that the object is an NSNumber try this:
[[parsedData objectAtIndex:0] intValue];

iphone sqlite quotes problem

I have a problem with a following sqlite query:
sql = [NSString stringWithFormat:#"Insert into table_name(height)values('%#')",heightarray];
I am getting heightarray from XML, the value of heightarray is:
array = ( "5'0\"-5'3\"",
"5'4\"-5'8\"",
"5'9\"-6'0\"" )
The \" is added implicitly for some reason, I don't know why?
It is causing problem. please help.
try to use
sql = [NSString stringWithFormat:#"Insert into table_name(height)values(?)"];
and then use
sqlite3_bind_text
If you're using sqlite try this wrapper it helps a lot
https://github.com/ccgus/fmdb
There are detailed examples how to use it.

Cannot convert to a pointer type

I'm trying to consume an ASP.net Web service, and found a utility called WSDL2ObjC.
Now I'm trying to use it, and basic use is working (asking for simple data types, such as booleans or strings), but now I'm requesting an array of the "EmailServiceSvc_Email" structure, which contains "subject", "from" and "message" properties.
The app won't compile, with the message above, and here's the code on wich it gets stuck:
EmailServiceSvc_Email * eml = (EmailServiceSvc_Email *) arrEmails[[indexPath row]];
This is the explanation of the variables:
eml : the new variable I'm trying to get out of arrEmails.
arrEmails: an NSMutableArray of the EmailServiceSvc_Email object
indexPath: the indexPath parameter, this is from the cellForRowAtIndexPath function.
As you can see probably, I want to display all the "subject"s from the "EmailServiceSvc_Email" structure in a TableView, on the iPhone.
To get an element out of an NSMutableArray you must use -objectAtIndex:. The a[i] syntax does not work with NSArrays.
EmailServiceSvc_Email* eml = [arrEmails objectAtIndex:indexPath.row];
I wrote a tutorial about Wsdl2objc and complex types:
http://brismith66.blogspot.com/2010/07/iphone-development-accessing-soap.html

Parsing XML, details and attributes, iphone

I'm not sure about parsing an xml with attributes. have seen a similar question here
But it shows to get an attribute of intValue. But i need to get the attributes of string type,How to do that?? Images of xml and the relevant portions are given in the following links
Click here for xml and here for required data
This answer to the linked question should work for you as well. The contents of attributeDict are already NStrings. All that is going on extra in the linked answer that they are calling the intValue method on the returned NSString to parse that string into an int. In your case, you don't need this little bit of an extra step. If you just do this:
NSString * stringValue = [attributeDict objectForKey:#"attribute"];
you'll have the value of the attribute called "attribute" in a string.