zoukankan      html  css  js  c++  java
  • QSqlQuery绑定查询

    Approaches to Binding Values
    Below we present the same example using each of the four different binding approaches, as well as one example of binding values to a stored procedure.
    Named binding using named placeholders:
         QSqlQuery query;
         query.prepare("INSERT INTO person (id, forename, surname) "
                       "VALUES (:id, :forename, :surname)");
         query.bindValue(":id", 1001);
         query.bindValue(":forename", "Bart");
         query.bindValue(":surname", "Simpson");
         query.exec();
    Positional binding using named placeholders:
         QSqlQuery query;
         query.prepare("INSERT INTO person (id, forename, surname) "
                       "VALUES (:id, :forename, :surname)");
         query.bindValue(0, 1001);
         query.bindValue(1, "Bart");
         query.bindValue(2, "Simpson");
         query.exec();
    Binding values using positional placeholders (version 1):
         QSqlQuery query;
         query.prepare("INSERT INTO person (id, forename, surname) "
                       "VALUES (?, ?, ?)");
         query.bindValue(0, 1001);
         query.bindValue(1, "Bart");
         query.bindValue(2, "Simpson");
         query.exec();
    Binding values using positional placeholders (version 2):
         QSqlQuery query;
         query.prepare("INSERT INTO person (id, forename, surname) "
                       "VALUES (?, ?, ?)");
         query.addBindValue(1001);
         query.addBindValue("Bart");
         query.addBindValue("Simpson");
         query.exec();
    Binding values to a stored procedure:
    This code calls a stored procedure called AsciiToInt(), passing it a character through its in parameter, and taking its result in the out parameter.
         QSqlQuery query;
         query.prepare("CALL AsciiToInt(?, ?)");
         query.bindValue(0, "A");
         query.bindValue(1, 0, QSql::Out);
         query.exec();
         int i = query.boundValue(1).toInt(); // i is 65
    Note that unbound parameters will retain their values.
    More information to see QT Help.

  • 相关阅读:
    【原创】自己动手写工具----签到器[Beta 1.0]
    都2020了,还不好好学学泛型?
    ThreadLocal = 本地线程?
    从BWM生产学习工厂模式
    你还在用BeanUtils进行对象属性拷贝?
    JDK 1.8 之 Map.merge()
    Spring Boot认证:整合Jwt
    以商品超卖为例讲解Redis分布式锁
    如何从 if-else 的参数校验中解放出来?
    分布式全局唯一ID生成策略​
  • 原文地址:https://www.cnblogs.com/wiessharling/p/2874270.html
Copyright © 2011-2022 走看看