首页 \ 问答 \ 使用database / sql包创建通用代码?(Creating generic code using database/sql package?)

使用database / sql包创建通用代码?(Creating generic code using database/sql package?)

我最近实现了一个使用database/sql包的包。 通过将SQL限制为非常简单的select / update / insert语句,我假设该包可以与database/sql支持的所有DBMS一起使用。

但是,事实证明有些数据库使用? 作为占位符值,而其他人使用$1$2等,这意味着准备好的语句将与某些DBMS一起使用,但不能与其他DBMS一起使用。

所以我想知道是否有任何技术可以通过所有支持的驱动程序以通用的方式工作? 或者是否有必要在任何地方使用特定于DBMS的代码? (我认为这会使database/sql提供的抽象有点无意义)。 我想使用非预处理语句也不是一个选项,因为不同的DBMS有不同的方法来转义参数。

有什么建议吗?


I've recently implemented a package that uses the database/sql package. By limiting the SQL to very simple select/update/insert statements I assumed the package would work with all the DBMS supported by database/sql.

However, it turns out that some databases use ? as placeholder value while others use $1, $2, etc., which means the prepared statements will work with some DBMS but not with others.

So I'm wondering is there any technique to make this work in a generic way with all the supported drivers? Or is it necessary to have DBMS-specific code everywhere? (which I think would make the abstraction provided by database/sql a bit pointless). I guess using non-prepared statements is not an option either since different DBMS have different ways to escape parameters.

Any suggestion?


原文:
更新时间:2021-09-11 14:09

最满意答案

你的策略听起来不错,但是它需要一个站点在“只读”模式下一段时间。 这并不总是可行的。 另外我不太清楚为什么要打开和关闭所有模块?

我可以提出一个稍微不同的方法

  1. 将prod数据库复制到dev
  2. 在开发中复制prod代码
  3. 在开发中升级核心Drupal
  4. 运行update.php
  5. 测试
  6. 对于每个模块
  7. 。 在dev中升级模块
  8. 。 运行update.php
  9. 。 测试
  10. 进入维护模式
  11. 备份数据库
  12. 将代码迁移到生产
  13. 运行update.php
  14. 放回在线测试

通过这种方式可以进行更多的测试,但停机时间更短,如果出现错误,您也可以计算出哪些模块可以解决问题。 它也不依赖于你将数据库从dev上传到live。


Your strategy sounds good, but it would require a site to be in “read only” mode for quite a while. This is not always feasible. Also I am not quite sure why you would turn on and off all of the modules?

May I propose a slightly different approach

  1. copy prod database to dev
  2. replicate prod code in dev
  3. upgrade core Drupal in dev
  4. run update.php
  5. test
  6. For each module
  7. . Upgrade modules in dev
  8. . Run update.php
  9. . Test
  10. Put into maintenance mode
  11. Backup database
  12. Migrate code to production
  13. Run update.php
  14. Put back online test

This way there is a lot more testing but less downtime, also you will be able to work out which module breaks things if there is an error. It also dosn't rely on you uploading the DB from dev to live.

相关问答

更多
  • 我假设你正在运行Windows我使用wamp,我尝试了其他几个解决方案,这是最好的明确请参阅此文档[如何在Windows上逐步安装wamp&drupal] [1] [1]: https : //drupal.org/node/1995312 “如何在Windows上逐步安装wamp&drupal” 当您成功完成此操作时,您将阅读足够的资料来帮助您恢复drupal安装和数据库到服务器。 I'm assuming you're running windows I Use wamp , i tried sever ...
  • Pressflow将以下功能添加到Drupal。 支持数据库复制 支持Squid和Varnish反向代理缓存 MySQL的优化 PHP 5的优化 Pressflow是标准Drupal核心的100%api兼容替代品。 没有数据库模式更改。 只要您运行正常的Drupal内核并满足其他系统要求(PHP5.x,MySQL 5.x),Pressflow就是一个“放下”的替代品。 Pressflow adds the following features to Drupal. Support for database ...
  • 我很确定,大部分预配置的东西都是功能。 所以你应该能够用drupal commons替换你现有的drupal文件,并启用你想要的附加功能。 未经测试,但我知道https://github.com/acquia/commons/tree/master/docroot/profiles/drupal_commons/modules/features中有大量功能“模块”。 To summarize the relevant portions of the approach we took, the first t ...
  • 很高兴你正在使用Drupal。 它是一个具有略微尖锐学习曲线的CMS。 我建议你从Drupal那里拿一两本书(来自Oreilly或Packtpub)。 在Stack Overflow上提出这样的一般性问题不会对你有太多帮助。 你在谈论漂亮的网址。 您可以使用Pathauto模块启用它们。 它将允许您的页面自动命名。 如果您只想显式命名页面,则使用Path模块 是的,Drupal提供了从其他CMS迁移内容的功能。 它还有一些复杂的模块可以从CSV(逗号分隔文件)导入节点导入( http://drupal.or ...
  • 简短的回答:它不会回溯到D6。 Drupal电子商务基于(强烈依赖)Drupal 7实体系统。 不可能将它恢复到Drupal 6.它也不是商业目标。 顺便说一句:有一个专门针对drupal问题的Q + A网站 。 考虑在那里发布你的Drupal相关问题。 干杯。 Short answer: It won't be backported to D6. Drupal commerce is based (strongly dependent) on drupal 7 entity system. Is not ...
  • 除非有真正需要的模块只存在于Drupal 6中并且在Drupal 7中没有稳定版本,否则我会说去Drupal 7。 你需要迟早升级,从一开始就用7开始 无需先学习即可在7中获得更多经验6 让网站制作7,而不是6制,然后转换为7。 另外,7还有一些香草6没有的东西。 看到超过一年半前被问过的这个问题 ,其中6被推荐,直到稳定的7出来。 Drupal现在是7.8 - 应该足够稳定。 Unless there are modules you really need that only exist in Drupa ...
  • 这可能是关于Drupal的薄雾问题之一 - 这是Drupal相当弱的一个领域。 你可能想看看Aegir 。 这是一个基于Drupal的平台,旨在简化部署和更新。 它在幕后使用Drush ,所以如果Aegir看起来像是满足你的需求,Drush可能就是你所需要的。 Drush是Drupal的命令行shell,它允许您使用命令提示符或批处理脚本在Drupal站点上执行操作。 在它们之间,这两个软件是Drupal推荐的管理部署的方式。 请注意,Drush(以及Aegir)具有一些仅在Linux平台上运行时才有效的功 ...
  • 试试这个: RewriteEngine On RewriteBase /example.com RewriteRule ^$ drupal/ [L] # rewrite rules for drupal files RewriteCond %{DOCUMENT_ROOT}/example.com/drupal/$1 -f RewriteRule ^(.*)$ drupal/$1 [L,QSA] # rewrite rules for drupal paths RewriteCond %{REQUEST ...
  • Drupal非常适合社区网站 - 但它的学习曲线陡峭。 如果你知道足够的PHP来创建你自己的网站,那么你应该没问题,尽管开始使用Drupal。 为什么不安装它并且有一点戏剧性? Drupal中的论坛有点平均,但PHPBB集成得相当好,并且有一些贡献模块来缓解集成。 主题也是一项不重要的任务 - 但是有很多这样的在线教程: http : //www.lullabot.com/videos/advanced-theming-drupal-7 ,它解释了许多技术性的东西。 如果你想跳进去,就开始看看D7开箱即带的 ...
  • 你的策略听起来不错,但是它需要一个站点在“只读”模式下一段时间。 这并不总是可行的。 另外我不太清楚为什么要打开和关闭所有模块? 我可以提出一个稍微不同的方法 将prod数据库复制到dev 在开发中复制prod代码 在开发中升级核心Drupal 运行update.php 测试 对于每个模块 。 在dev中升级模块 。 运行update.php 。 测试 进入维护模式 备份数据库 将代码迁移到生产 运行update.php 放回在线测试 通过这种方式可以进行更多的测试,但停机时间更短,如果出现错误,您也可以计 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。