从UITextfield中给出的输入中搜索iPhone中的SQLite3数据库(Searching SQLite3 DB in iPhone from input given in UITextfield)
我是iOS开发的新手。 我正在尝试构建在sqllite3 DB中搜索给定搜索词的应用程序。 我遇到了将参数绑定到该sql语句的问题。以下是我从数据库中读取数据的代码。
-(void) readPlayersFromDatabase { NSString * strTemp=[[NSString alloc]init]; strTemp=@"ben"; sqlite3 *database; players = [[NSMutableArray alloc] init]; if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) { char *sqlStatement = "SELECT * FROM Player WHERE LENGTH (lastname)>0 AND LENGTH (firstname)>0 AND ( lastname LIKE '%?%' OR firstname LIKE'%?%' OR Height LIKE '%?%' OR Weight LIKE '%?%') ORDER BY lastname,firstname"; sqlite3_stmt *compiledStatement; if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) { sqlite3_bind_text(compiledStatement, 1, [strTemp UTF8String],-1, SQLITE_TRANSIENT ); sqlite3_bind_text(compiledStatement, 2, [strTemp UTF8String],-1, SQLITE_TRANSIENT ); sqlite3_bind_text(compiledStatement, 3, [strTemp UTF8String],-1, SQLITE_TRANSIENT ); sqlite3_bind_text(compiledStatement, 4, [strTemp UTF8String],-1, SQLITE_TRANSIENT ); while(sqlite3_step(compiledStatement) == SQLITE_ROW) { NSString *playerId = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)]; NSString *playerName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)]; Player *temp = [[Player alloc] initWithID:playerId name:playerName]; [players addObject:temp]; [temp release]; } } sqlite3_finalize(compiledStatement); } sqlite3_close(database); }
我到底得到的只是玩家的名字? 以他们的名义。 有人可以帮我从这里出去吗。 你能告诉我如何在上面的代码
UITextfield
输入连接到strTemp
吗?谢谢。
I am fairly new to iOS development. I am trying to build application which searches given search term in sqllite3 DB. I am having trouble with binding parameter to that sql statement.Following is my code to read data from database.
-(void) readPlayersFromDatabase { NSString * strTemp=[[NSString alloc]init]; strTemp=@"ben"; sqlite3 *database; players = [[NSMutableArray alloc] init]; if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) { char *sqlStatement = "SELECT * FROM Player WHERE LENGTH (lastname)>0 AND LENGTH (firstname)>0 AND ( lastname LIKE '%?%' OR firstname LIKE'%?%' OR Height LIKE '%?%' OR Weight LIKE '%?%') ORDER BY lastname,firstname"; sqlite3_stmt *compiledStatement; if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) { sqlite3_bind_text(compiledStatement, 1, [strTemp UTF8String],-1, SQLITE_TRANSIENT ); sqlite3_bind_text(compiledStatement, 2, [strTemp UTF8String],-1, SQLITE_TRANSIENT ); sqlite3_bind_text(compiledStatement, 3, [strTemp UTF8String],-1, SQLITE_TRANSIENT ); sqlite3_bind_text(compiledStatement, 4, [strTemp UTF8String],-1, SQLITE_TRANSIENT ); while(sqlite3_step(compiledStatement) == SQLITE_ROW) { NSString *playerId = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)]; NSString *playerName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)]; Player *temp = [[Player alloc] initWithID:playerId name:playerName]; [players addObject:temp]; [temp release]; } } sqlite3_finalize(compiledStatement); } sqlite3_close(database); }
All I am getting at the end is name of player which has ? in their name. Can anyone help me out here. Can you also tell me how can I connect
UITextfield
input to thestrTemp
in above code ?Thanks.
原文:https://stackoverflow.com/questions/6386546
最满意答案
最后,对数的实际用途。
记住这一点
log(X^Y) = log(X) * Y
所以
log(X) = log(X^Y) / Y
所以
X = exp(log(X^Y) / Y)
在这种情况下,X是每个步骤的比例。 Y是步数。 X ^ Y是您想要的总比例。 例如,
Steps = 10; TotalScale = 0.5; ScaleEachTime = exp(log(TotalScale) / Steps);
给出(点......因为我在例子中四舍五入)
= exp(log(0.5) / 10) = exp(-0.693... / 10) = exp(-0.0693...) = 0.9330....
因此,按0.9330缩放10次......总得分为0.5
At last, a practical use for logarithms.
Remember that
log(X^Y) = log(X) * Y
So
log(X) = log(X^Y) / Y
So
X = exp(log(X^Y) / Y)
In this case, X is the scale to make at each step. Y is the number of steps. X^Y is the total scale you want to make. For example,
Steps = 10; TotalScale = 0.5; ScaleEachTime = exp(log(TotalScale) / Steps);
gives (dots... because I am rounding off in the example)
= exp(log(0.5) / 10) = exp(-0.693... / 10) = exp(-0.0693...) = 0.9330....
So scaling 10 times by 0.9330... gives a total scale of 0.5
相关问答
更多-
它取决于您使用的存储引擎以及为该表选择的行格式 ,以及您的索引。 但它不是一个非常有用的信息。 编辑: 我建议只有当你确切地知道你在做什么时才会反对正常化。 DBMS被创建来处理大量的数据。 您可能不需要将您的结构化数据序列化到单个字段中。 请记住,您的应用程序层必须标记(或更糟糕)序列化的字段数据以获取原始含义,这比从数据库获取结构化表单中的数据的开销要大得多。 我能想到的唯一例外是客户端架构,当将处理移动到客户端时实际上会减轻服务器的负担,并且为了传输的目的您将序列化我们的数据。 - 在服务器端代码(如 ...
-
从excel中的尺寸/进度信息计算厚度的公式(Formula to calculate thickness from size/schedule information in excel)[2023-01-13]
我想这应该适合你 = VLOOKUP(L2,Test,MATCH(O2,Test,0),FALSE)。 I guess this should work for you =VLOOKUP(L2, Test, MATCH(O2,Test,0), FALSE). -
对此没有金科玉律。 从doc中提取: 在单个批量呼叫中没有执行“正确”的操作次数。 您应该尝试不同的设置以找到适合您特定工作负载的最佳尺寸。 There is no golden rule for this. Extracted from the doc: There is no “correct” number of actions to perform in a single bulk call. You should experiment with different settings to find ...
-
我在这里回答我自己的Q,因为互联网似乎似乎没有问,所以我错过了某个地方的某个文件。 你不能使用Affines他们只是不喜欢动画师。 所以我发现你从动态中删除视图并更改“边界”或“框架”然后将视图添加回动画师。 [_gravity removeItem:_wrapperWolfBox]; CGRect frameZr = _wrapperWolfBox.bounds; frameZr.size.height += 60.0f; frameZr.size.width += 60.0f; ...
-
代码依赖于对位的一些假设,然后用于查找最大size_t值的众所周知的hack(假设size_t不能容纳比寄存器更多的位,在许多机器上是安全的赌注)。 首先,它以1位填充寄存器,然后将其转换为size_t数据类型,因此比较将起作用。 只要该寄存器的位数大于size_t数据类型,那么(如果有的话)未使用的1位将被截断,并且您将获得可以适合size_t位的最大无符号数。 在你有了它之后,它除以2来获得该数字的一半,并进行比较,看看在不超过“最大” size_t情况下增加大小似乎是安全的。 但到那时,它正在划分si ...
-
如果你只是想缩小尺寸,使用CGAffineTransformMakeScale很容易,并且会解决你的问题。 if you just want to scale the size , use CGAffineTransformMakeScale is easy and will solve your problem.
-
Swift CGAffineTransformScale扩展到一个比例尺,而不是一个比例尺(Swift CGAffineTransformScale to a scale, not by a scale)[2022-04-04]
Swift 3 : text.transform = CGAffineTransform.identity UIView.animate(withDuration: 0.25, animations: { self.text.transform = CGAffineTransform(scaleX: scale, y: scale) }) Swift 3: text.transform = CGAffineTransform.identity UIView.animate(withDuration: ... -
最后,对数的实际用途。 记住这一点 log(X^Y) = log(X) * Y 所以 log(X) = log(X^Y) / Y 所以 X = exp(log(X^Y) / Y) 在这种情况下,X是每个步骤的比例。 Y是步数。 X ^ Y是您想要的总比例。 例如, Steps = 10; TotalScale = 0.5; ScaleEachTime = exp(log(TotalScale) / Steps); 给出(点......因为我在例子中四舍五入) = exp( ...
-
通常不会,因为您的数据可能会以任意方式存在偏差。 如果你有一个真正的随机分布(统一),那么任何具有相等面积的n/x单元格的均匀网格将是好的(分布保证你在每个单元格中获得大致相同的点数)。 只需确保网格正确覆盖点分布区域(如果所有点都为[0,1],则网格应覆盖[0,1]而不是[0,100])。 如果您希望轴在每个方向上与相同数量的单元格对齐,那么您应该按sqrt(n/x)单元格生成sqrt(n/x)单元格。 In general no, because you data might be biased in ...
-
通过程序访问大型复杂公式的大尺寸excel文件(Access big size excel file with much complex formula by program)[2021-07-24]
尝试优化Excel工作表。 通常在休闲构建的Excel表格中有很大的改进空间。 例如,从您发布的一个公式我看到您可以将VLOOKUP中的表从$ A:$ Z限制为更小的值(这将获取Sheet中的所有行)。 Try to optimize Excel sheet. Normally in casual constructed Excel Sheet there is large space for improvement. For example, from the very one formula you p ...