使用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 bydatabase/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?
原文:
最满意答案
你的策略听起来不错,但是它需要一个站点在“只读”模式下一段时间。 这并不总是可行的。 另外我不太清楚为什么要打开和关闭所有模块?
我可以提出一个稍微不同的方法
- 将prod数据库复制到dev
- 在开发中复制prod代码
- 在开发中升级核心Drupal
- 运行update.php
- 测试
- 对于每个模块
- 。 在dev中升级模块
- 。 运行update.php
- 。 测试
- 进入维护模式
- 备份数据库
- 将代码迁移到生产
- 运行update.php
- 放回在线测试
通过这种方式可以进行更多的测试,但停机时间更短,如果出现错误,您也可以计算出哪些模块可以解决问题。 它也不依赖于你将数据库从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
- copy prod database to dev
- replicate prod code in dev
- upgrade core Drupal in dev
- run update.php
- test
- For each module
- . Upgrade modules in dev
- . Run update.php
- . Test
- Put into maintenance mode
- Backup database
- Migrate code to production
- Run update.php
- 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.
相关问答
更多-
如何在本地设置drupal站点,然后转移到生产服务器...(how to setup drupal site locally and then move to production server…)[2022-01-01]
我假设你正在运行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网站迁移到Drupal Commons?(How do I migrate an existing Drupal site to Drupal Commons?)[2021-12-23]
我很确定,大部分预配置的东西都是功能。 所以你应该能够用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开箱即带的 ...
-
在生产中升级到Drupal(Upgrades to Drupal in production)[2023-06-30]
你的策略听起来不错,但是它需要一个站点在“只读”模式下一段时间。 这并不总是可行的。 另外我不太清楚为什么要打开和关闭所有模块? 我可以提出一个稍微不同的方法 将prod数据库复制到dev 在开发中复制prod代码 在开发中升级核心Drupal 运行update.php 测试 对于每个模块 。 在dev中升级模块 。 运行update.php 。 测试 进入维护模式 备份数据库 将代码迁移到生产 运行update.php 放回在线测试 通过这种方式可以进行更多的测试,但停机时间更短,如果出现错误,您也可以计 ...