预备语句,同时获取预备语句 [英] Prepared statements while fetching prepared statement

查看:91
本文介绍了预备语句,同时获取预备语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用一个带有INSERT查询的循环为上一个具有准备好的语句的前一个查询的每行获取一个INSERT查询.以更直观的方式:

I want to make a loop with one INSERT query for each fetched row from a previous query with prepared statements. In a more visual way:

进行查询
   正在提取
   -进行新查询

MAKE QUERY
  While Fetching
    - Make new query

我无法关闭我的声明,因为我需要它来继续工作... 问题在于,当我们使用预处理语句时,必须在执行新的prepare()之前获取所有数据.那么,我该怎么做呢?也许没有声明,但这不是一个很好的解决方案.

I can't close my statement since I need it to keep working... The problem is that when we use prepared statements, we have to fetch all data before doing a new prepare(). So, how could I do this? Maybe without statements, but it's not a nice solution.

推荐答案

如果您尝试执行此操作,则将杀死DB(如果拥有DBA,则DBA将杀死您).问题是您要执行的操作是每行向数据库发送一个插入请求.您必须为每一行数据一次又一次地创建和处理所有这些命令.那是昂贵的.

You are going to kill your DB (and if you have a DBA your DBA is going to kill you) if you try to do this. The problem is that what you want to do is send one inser request per line to the database. You have to create and dispose of all these commands over and over again for each line of data. That is expensive.

如果您很难做到这一点,那么什么都不会阻止您在从第一个循环读取的循环中创建第二个预备语句(当然具有不同的名称),但是我强烈建议您这样做.至少要缓冲传入的数据并一次插入几百行.

If you are hard-set on doing it, Nothing prevents you from creating a second prepared statement (with a different name of course) within a loop which reads from the first, but I highly advise against it. At the very least, buffer your incoming data and insert a few hundred rows at a time.

这篇关于预备语句,同时获取预备语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆