GVKun编程网logo

PHP SQLite :: 转义双引号(sql双引号转义字符)

1

对于想了解PHPSQLite::转义双引号的读者,本文将提供新的信息,我们将详细介绍sql双引号转义字符,并且为您提供关于01.SQLite教程(http://www.w3cschool.cc/sql

对于想了解PHP SQLite :: 转义双引号的读者,本文将提供新的信息,我们将详细介绍sql双引号转义字符,并且为您提供关于01.SQLite 教程(http://www.w3cschool.cc/sqlite/sqlite-tutorial.html)、android-sqlite – Android :: SQLite,没有找到这样的列?、C# 使用 System.Data.SQLite 操作 SQLite、C++ 中的 SQLite:无法在使用多线程编译的 SQLite 的程序中在启动时设置单线程模式的有价值信息。

本文目录一览:

PHP SQLite :: 转义双引号(sql双引号转义字符)

PHP SQLite :: 转义双引号(sql双引号转义字符)

如何解决PHP SQLite :: 转义双引号?

我正在尝试将用户给定的字符串插入到 PHP 环境中的 sqlite 数据库中。

由于不知道有多少个字符串(每个字符串在一个数据库行中划分),因此使用预配语句并不理想,除非有一种方法可以预配动态数量的行。

因此,我在构建查询字符串时,使用 PDO 或静态转义函数,使用严格的方法在单个位置对每个插入的值进行转义。

示例:

$value = ''\''''. sqlite3::escapestring($value).''\'''';
$value = $pdo->quote($value);

不幸的是,双引号 (") 没有转义,因为它们的含义很特别。尽管我认为一个字符串不能包含这些特殊字符,但它们在任何一个版本中都没有被转义。

我知道它可以通过双引号转义,但出于安全原因,如果可能,我不想做繁重的工作。

那么在 PHP 中是否有正确转义字符串的好方法?


编辑: 根据要求举个例子。

我有一个表/结构小部件,它代表不同的飞溅文本/行。沿着文本还有一些其他属性,它们基本上是绑定到该字符串的设置/元数据。

保存时,我将整个表推送到服务器,所有内容都存储在一个指定的数据库表中。

所以在代码中我基本上有一个关联数组,它看起来像:

[
    0 => [
        ''text'' => ''some "string" containing all kinds of characters \'' '',''wheight'' => 5
        \\ and some other properties
    ],1 => [
        ''text'' => ''some other @random text'',''wheight'' => 3
        \\ and some other properties
    ],]

表的大小是动态的,因此像 INSERT INTO table VALUES (?,?,?) ; 这样的预成语句将不起作用,因为每行只有 3 个变量的空间。除非有办法允许动态数量的值。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

01.SQLite 教程(http://www.w3cschool.cc/sqlite/sqlite-tutorial.html)

01.SQLite 教程(http://www.w3cschool.cc/sqlite/sqlite-tutorial.html)

sqlite教程

sqlite 是一个软件库,实现了自给自足的、无服务器的、零配置的、事务性的 sql 数据库引擎。sqlite 是在世界上最广泛部署的 sql 数据库引擎。sqlite 源代码不受版权限制。

本教程将告诉您如何使用 sqlite 编程,并让你迅速上手。

现在开始学习 SQLite!

谁适合阅读本教程?

本教程有助于初学者了解 sqlite 数据库引擎相关的基础知识和先进理念。

阅读本教程前,你需要了解的知识:

在开始使用本教程提供的各类实例进行练习之前,您需要了解什么是数据库,尤其是 RDBMS,以及什么是计算机编程语言。

编译/执行 sqlite 程序

如果您想要通过 sqlite DBMS 编译/执行 sql 程序,但是您没有相关设置,那么可以访问compileonline.com。您只需进行简单的点击动作,即可在高端的服务器上体验真实的编程经验。这是完全免费的在线工具。

sqlite 函数参考手册

本教程提供了所有重要的内置的 sqlite 函数的参考手册。

SQLite 常用函数

sqlite 有用的资源

本教程列出了 sqlite 数据库网站和书籍。

sqlite 有用的网站

  • SQLite Home Page- sqlite 官方网站提供了最新的 sqlite 安装版本,最新的 sqlite 资讯以及完整的 sqlite 教程。

  • PHP SQLite3- 网站提供了 sqlite 3 数据库的 PHP 支持的完整细节。

  • SQLite JDBC Driver:- sqlite JDBC,由 Taro L. Saito 开发的,是一个用于 Java 中访问和创建 sqlite 数据库文件的库。

  • DBD-SQLite-0.31- sqlite Perl driver 驱动程序与 Perl DBI 模块一起使用。

  • DBI-1.625- Perl DBI 模块为包括 sqlite 在内的任何数据库提供了通用接口。

  • SQLite Python- sqlite3 python 模块由 Gerhard Haring 编写的。它提供了与 DB-API 2.0 规范兼容的 sql 接口。

sqlite 有用的书籍

android-sqlite – Android :: SQLite,没有找到这样的列?

android-sqlite – Android :: SQLite,没有找到这样的列?

嘿所有我是一个新手安卓,并希望对此有所帮助?

android.database.sqlite.sqliteException:没有这样的列:asd :,编译时:DELETE FROM标签WHERE name = asd

这是我面临的错误,这是代码:

这是DBhelper中的方法:

/**
 * Delete a label table
 * */
public void deleteLabel(String label) {
    sqliteDatabase db = this.getWritableDatabase();

    // ContentValues values = new ContentValues();
    // values.remove(label);

    // Deleting Row
    db.delete(TABLE_LABELS,KEY_NAME + "=" + label,null);
    db.close(); // Closing database connection
}

这是调用该方法的主要Activity代码:

// for spinner onItemListener
// and here is what label is

final String label = parent.getItemAtPosition(position).toString();

Button dialogDeletelButton = (Button) dialog
                .findViewById(R.id.deleteButton);
        dialogDeletelButton.setonClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // database handler
                DatabaseHandler db = new DatabaseHandler(
                        getApplicationContext());

                // inserting new label into database
                db.deleteLabel(label);

                // Hiding the keyboard
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(inputLabel.getwindowToken(),0);

                // loading spinner without the deleted data
                loadSpinnerData();

            }
        });

解决方法

您几乎肯定需要引用’asd'(即代码中的label变量).如果它被引用,它是一个与名称列进行比较的字符串.

如果它没有引用,sql只会将其视为另一个列名.

您可以在以下活动中执行以下操作:

db.deleteLabel ("'" + label + "'");

但是更改辅助函数可能更干净:

db.delete (TABLE_LABELS,KEY_NAME + "='" + label + "'",null);

因为看起来你可能想要在那里的某个点处使用未加引号的标签(当前被注释掉的ContentValues内容).

C# 使用 System.Data.SQLite 操作 SQLite

C# 使用 System.Data.SQLite 操作 SQLite

使用 System.Data.SQLite
下载地址:http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki

 

得到 System.Data.SQLite.dll 添加到工程引用;


 建表,插入操作

static void Main(string[] args)
        {
            SQLiteConnection conn = null;

            string dbPath = "Data Source =" + Environment.CurrentDirectory + "/test.db";
            conn = new SQLiteConnection(dbPath);//创建数据库实例,指定文件位置
            conn.Open();//打开数据库,若文件不存在会自动创建

            string sql = "CREATE TABLE IF NOT EXISTS student(id integer, name varchar(20), sex varchar(2));";//建表语句
            SQLiteCommand cmdCreateTable = new SQLiteCommand(sql, conn);
            cmdCreateTable.ExecuteNonQuery();//如果表不存在,创建数据表

            SQLiteCommand cmdInsert = new SQLiteCommand(conn);
            cmdInsert.CommandText = "INSERT INTO student VALUES(1, ''小红'', ''男'')";//插入几条数据
            cmdInsert.ExecuteNonQuery();
            cmdInsert.CommandText = "INSERT INTO student VALUES(2, ''小李'', ''女'')";
            cmdInsert.ExecuteNonQuery();
            cmdInsert.CommandText = "INSERT INTO student VALUES(3, ''小明'', ''男'')";
            cmdInsert.ExecuteNonQuery();

            conn.Close();
        }


 可以使用 SQLite Database Browser 来查看数据:

 建表成功。

当然这种方法插入数据效率不高,数据量大的话要使用下面这种方法

 static void Main(string[] args)
        {
            string dbPath = Environment.CurrentDirectory + "/test.db";//指定数据库路径
            
            using(SQLiteConnection conn = new SQLiteConnection("Data Source =" + dbPath))//创建连接
            {
                conn.Open();//打开连接
                using(SQLiteTransaction tran = conn.BeginTransaction())//实例化一个事务
                {
                    for (int i = 0; i < 100000; i++ )
                    {
                        SQLiteCommand cmd = new SQLiteCommand(conn);//实例化SQL命令
                        cmd.Transaction = tran;
                        cmd.CommandText = "insert into student values(@id, @name, @sex)";//设置带参SQL语句
                        cmd.Parameters.AddRange(new[] {//添加参数
                            new SQLiteParameter("@id", i),
                            new SQLiteParameter("@name", "中国人"),
                            new SQLiteParameter("@sex", "男")
                        });
                        cmd.ExecuteNonQuery();//执行查询
                    }
                    tran.Commit();//提交
                }
            }
        }

插入这样的十万条数据只需要 5 秒左右。

 

读取数据:

static void Main(string[] args)
        {
            SQLiteConnection conn = null;

            string dbPath = "Data Source =" + Environment.CurrentDirectory + "/test.db";
            conn = new SQLiteConnection(dbPath);//创建数据库实例,指定文件位置
            conn.Open();//打开数据库,若文件不存在会自动创建

            string sql = "select * from student";
            SQLiteCommand cmdQ = new SQLiteCommand(sql, conn);

            SQLiteDataReader reader = cmdQ.ExecuteReader();

            while (reader.Read())
            {
                Console.WriteLine(reader.GetInt32(0) + " " + reader.GetString(1) + " " + reader.GetString(2));
            }
            conn.Close();

            Console.ReadKey();
        }


 数据读取成功。

C++ 中的 SQLite:无法在使用多线程编译的 SQLite 的程序中在启动时设置单线程模式

C++ 中的 SQLite:无法在使用多线程编译的 SQLite 的程序中在启动时设置单线程模式

如何解决C++ 中的 SQLite:无法在使用多线程编译的 SQLite 的程序中在启动时设置单线程模式

我正在尝试在使用多线程编译的 sqlite 的程序中在启动时设置单线程模式。代码如下:

#include <iostream>
#include <sqlite3.h>

using namespace std;

int main() {
  cout << "threadsafe: " << sqlite3_threadsafe() << endl;
  int mode = sqlITE_CONfig_SINGLETHREAD;
  sqlite3_shutdown();
  int res = sqlite3_config(mode);
  if (res) {
    cout << "Failed to set threading mode,error code: " + to_string(res);
  } else {
    cout << "threading mode successfully set to " + to_string(mode);
  }
  sqlite3_initialize();

  cout << endl;
  return 0;
}

// command used to compile and run
// g++ repro.cpp -o repro.out -lsqlite3 && ./repro.out

输出为:

threadsafe: 2
Failed to set threading mode,error code: 21

现在,根据我从 here 和其他 sqlite 文档中了解到的,编译时模式决定了 sqlite 的编译文件中是否存在互斥体代码。另一方面,启动时和运行时设置要么告诉程序使用/省略互斥锁代码(如果它明显存在)。 现在,如果我得到 2 作为 sqlite3_threadsafe() 调用的结果,则意味着 sqlite 代码已在多线程模式下编译。这意味着互斥锁代码已编译并可用。但是,为了关心性能,我想告诉程序跳过互斥锁代码,因为我将只在一个线程上使用 sqlite。为此,我遵循了文档并使用了 sqlite3_config() 和选项 sqlITE_CONfig_SINGLETHREAD。这不起作用,我从调用中得到了结果 21。错误代码表示 sqlITE_MISUSE。我到了 this SO answer,所以我把配置调用放在 sqlite3_shutdownsqlite3_initialize 之间。这没有用。

我不确定为什么这不起作用,在链接的文档中他们说:

无法将单个数据库连接降级为单线程模式

但它是关于一个单独的连接,我试图让它适用于程序中的所有 sqlite 调用。我在文档或互联网上找不到答案。我错过了什么吗?

编辑:抱歉,忘了放版本:

  • mac 操作系统:11.2.3
  • Apple clang 版本 12.0.5
  • sqlite3:3.32.3

关于PHP SQLite :: 转义双引号sql双引号转义字符的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于01.SQLite 教程(http://www.w3cschool.cc/sqlite/sqlite-tutorial.html)、android-sqlite – Android :: SQLite,没有找到这样的列?、C# 使用 System.Data.SQLite 操作 SQLite、C++ 中的 SQLite:无法在使用多线程编译的 SQLite 的程序中在启动时设置单线程模式等相关内容,可以在本站寻找。

本文标签: