我的代码很简单,只需创建一个空表.这是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <sqlite3.h>
int main(int argc, char *argv[])
{
sqlite3 *ppdb;
int retval;
retval = sqlite3_open_v2("v2.db", &ppdb,
SQLITE_OPEN_CREATE, "unix-none");
if (retval != SQLITE_OK)
{
printf(stderr, "%s\n", sqlite3_errmsg(ppdb));
return 1;
}
retval = sqlite3_exec(ppdb,
"CREATE TABLE IF NOT EXISTS userinfo \
(id TEXT PRIMARY KEY, pass TEXT NOT NULL)",
NULL, NULL, NULL);
if (retval != SQLITE_OK)
{
fprintf(stderr, "%s\n", sqlite3_errmsg(ppdb));
return 1;
}
sqlite3_close(ppdb);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时,我收到此错误消息:
Out of memory
我调试了这段代码,我发现sqlite3_open_v2已经返回21(库使用不正确)
怎么解决?
我在Delphi中观看了与创建和使用数据库相关的视频.该视频指出您可以使用代码,数据资源管理器或SQLite3控制台应用程序创建数据库,但我无法找到如何使用数据资源管理器创建数据库.有谁知道我可以这样做的方式?
先谢谢你.
这两种语言中的哪一种接口更好,并为使用sqlite数据库提供了更好的性能/工具集?我熟悉这两种语言,但需要为我正在开发的项目选择一种语言,所以我想我会问这里.我不相信这是自以为是的,因为语言的表现是非常客观的.
我想null在SQLite中分配一个字段但是没有得到任何地方:
update t set n=null where n=0;
Run Code Online (Sandbox Code Playgroud) 可能重复:
在onCreate之前,活动无法使用系统服务?
我试图将数据库的值返回到listview,但我收到一个错误.我使用游标从表中获取数据,使用SimpleCursorAdapter读取游标.这是执行此操作的方法:
public void getData(){
String[] columns = new String[] {ModuleDB.KEY_ROWID,
ModuleDB.KEY_MODCODE,
ModuleDB.KEY_MODNAME,
ModuleDB.KEY_LECPRAC,
ModuleDB.KEY_DAYS,
ModuleDB.KEY_TIMESTART,
ModuleDB.KEY_TIMEEND,
ModuleDB.KEY_LOCATION,
ModuleDB.KEY_INFO};
int[] to = new int[]{R.id.modcode_entry,
R.id.modname_entry,
R.id.modlecprac_entry,
R.id.modday_entry,
R.id.modtimestart_entry,
R.id.modtimeend_entry,
R.id.modlocation_entry,
R.id.modaddinfo_entry};
Cursor curs = myDatabase.query(ModuleDB.DB_TABLE, columns, null, null, null, null, null);
if (curs != null)
curs.moveToFirst();
SimpleCursorAdapter dataSource = new SimpleCursorAdapter(ModuleDataSource.this, R.layout.list_entry, curs, columns, to);
this.setListAdapter(dataSource);
// Make sure to close the cursor
curs.close();
}
Run Code Online (Sandbox Code Playgroud)
此方法导致异常: "System Services not available to activites before onCreate()"
谁能帮我这个?我找不到任何关于游标和cursoradapter的好教程,我真的完全迷失了
编辑:
这可能有所帮助.
MainActivity.java
public …Run Code Online (Sandbox Code Playgroud) 我正在使用SQLite来处理我正在处理的数据输入Windows 8应用程序.我可以创建数据库,插入数据,检索列数和读取数据,但无法获取列名.
底层框架来自这篇文章.
我读到了关于PRAGMA table_info(table_name);命令但我似乎无法正确发送和回读此查询.我一直在谷歌搜索3天!
MainPage.xaml.cs中:
using SQLite;
using SqlLiteTest.Model;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Windows.Storage;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace SqlLiteTest
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
txtPath.Text = ApplicationData.Current.LocalFolder.Path;
}
private async void createDB(object sender, RoutedEventArgs e)
{
// access local folder
var qvLocalFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
try
{
//Create a blank carrier file
StorageFile qvLocalFileCarrier = await qvLocalFolder.CreateFileAsync("qvdbLocal.db", CreationCollisionOption.FailIfExists);
//Write the …Run Code Online (Sandbox Code Playgroud) 要使用MySQL创建Rails应用程序,我执行以下操作:
rails new application -database=mysql
Run Code Online (Sandbox Code Playgroud)
但这不起作用,而是它给了我的SQLite.我不想要SQLite,我想要MySQL.
我怎么解决这个问题?
所以我能够在我的数据库中创建一个新表并从文件中获取所有信息,以使用游标填充除表中最后一列之外的所有信息,并按照通常的方式执行.
最后一列信息来自不同的来源,并在我的代码中作为整数列表.我将如何将这个整数列表添加到我的上一栏?
我已经尝试了各种循环和迭代,但我只是错过了一些东西(可能很明显),如何正确地表达它.
connection = sqlite3.connect('database.db')
cursor = connection.cursor()
for j in list:
cursor.execute('insert into Table (column) values (?)', j)
connection.commit()
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Traceback (most recent call last):
File "Homework/Homework7/bam_counting.py", line 157, in <module>
cursor.execute('insert into Genes (counts) values (?)', j)
ValueError: parameters are of unsupported type
Run Code Online (Sandbox Code Playgroud) 我使用PDO连接到sqlite3,但由于某种原因我无法使外键工作.根据文档,这个"PRAGMA short_column_names = 1"应该可以实现.我这样做:
$con = new PDO('sqlite:z:/testing.db');
$res = $con->exec('PRAGMA foreign_keys=ON');
var_dump($res);die();
Run Code Online (Sandbox Code Playgroud)
返回给我0.我尝试使用外键创建实际表,但它不起作用.对SQLite3类的直接请求有效:
$con = new SQLite3('z:/testing.db');
$con->exec('PRAGMA foreign_keys = ON;');
var_dump($con->query('PRAGMA foreign_keys;')->fetchArray());
Run Code Online (Sandbox Code Playgroud)
这个reutrns数组(2){[0] => int(1)["foreign_keys"] => int(1)}
根据SQLite3 :: version(),我有sqlite版本3.7.7.1.我的PHP版本是5.3.18,在Windows上运行.
请帮我用PDO运行它.谢谢!
我正在将SQL内容(具有特殊字符,如项目符号等)插入到SQLite数据库中.
当我尝试在视图上获取内容时,它不会正确显示特殊字符.它向我展示了垃圾文本.
如何确保我在数据库中插入的任何文本都在视图中正确显示.
谢谢!
我的插入代码:
//此查询方法实现位于不同的文件中
- (NSArray *)executeQuery:(NSString *)sql arguments:(NSArray *)args {
sqlite3_stmt *sqlStmt;
if (![self prepareSql:sql inStatament:(&sqlStmt)])
return nil;
int i = 0;
int queryParamCount = sqlite3_bind_parameter_count(sqlStmt);
while (i++ < queryParamCount)
[self bindObject:[args objectAtIndex:(i - 1)] toColumn:i inStatament:sqlStmt];
NSMutableArray *arrayList = [[NSMutableArray alloc] init]; // By Devang
int columnCount = sqlite3_column_count(sqlStmt);
while ([self hasData:sqlStmt]) {
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
for (i = 0; i < columnCount; ++i) {
id columnName = [self columnName:sqlStmt columnIndex:i];
id columnData …Run Code Online (Sandbox Code Playgroud)