首页 \ 问答 \ SQL CASE语句与编程语言中的条件语句(SQL CASE Statement Versus Conditional Statements In Programming Language)

SQL CASE语句与编程语言中的条件语句(SQL CASE Statement Versus Conditional Statements In Programming Language)

我在工作中经历了一些旧的存储过程并且经常遇到

CASE MyColumn WHEN 'Y' THEN 'Yes' WHEN 'N' THEN 'No' ELSE 'Unknown' END

如果这不是一个单词,而是一个颜色,那就更糟了。

CASE MyColumn WHEN 'Y' THEN 'style="background-color:pink"' ELSE '' END

这样做的原因是旧的ASP 1页面,其中所有内容都必须内联,但由于它是如此庞大的系统,因此无法跟上更新所有页面的步伐。

任何人都可以提供任何有效的证据证明对条件语句使用SQL查询超过了其他语言(如C#或Java)吗? 这是速度的好习惯吗? 是否应该返回普通值并且表示层决定应该做什么?


I'm going through some old stored procedures at work and constantly come across

CASE MyColumn WHEN 'Y' THEN 'Yes' WHEN 'N' THEN 'No' ELSE 'Unknown' END

It gets even worse when this is tied not to a word, but instead a colour.

CASE MyColumn WHEN 'Y' THEN 'style="background-color:pink"' ELSE '' END

The reason this was done was for older ASP 1 pages where everything had to be done inline, but as it's such a large system it's impossible to keep up with updating all the pages.

Can anyone give any valid evidence that using a SQL query for conditional statements surpasses that in other languages such as C# or Java? Is this good practice for speed? Should the plain value be returned and the presentation layer decide what should be done?


原文:https://stackoverflow.com/questions/487770
更新时间:2022-11-28 13:11

最满意答案

我在CentOS 6.3上遇到了同样的问题。 问题最终是EPEL yum repo中没有collectd-dbi rpm。 你必须从其他地方获得dbi插件。

检查您已安装的collectd版本

$ yum info collectd

这就是结果对我而言

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Installed Packages
Name        : collectd
Arch        : x86_64
Version     : 4.10.7
Release     : 1.el6
Size        : 1.3 M
Repo        : installed
From repo   : epel

您可以尝试在网络上搜索某人建立的RPM,但在我的情况下,我找不到我的确切版本。 因此,我认为唯一的解决方案是从源代码编译collectd。 以下是我编译collectd并安装dbi插件的步骤

克隆collectd仓库并签出您已安装的版本

git clone https://github.com/collectd/collectd.git
cd collectd/
git checkout collectd-4.10.7

安装依赖项以编译collectd。 以下是我需要安装以进行编译的所有内容,但您可能需要安装更多内容。 注意,libdbi-devel是必需的。 如果没有安装,那么在运行configure脚本时,dbi插件将不会启用而不会被编译。

sudo yum install autoconf automake flex ppl cloog-ppl cpp libgomp mpfr glibc-devel glibc-headers kernel-headers gcc libtool libtool-ltdl libtool-ltdl-devel libgcrypt-devel libgpg-error-devel libdbi libdbi-devel bison byacc db4-cxx db4-devel gdbm-devel perl-ExtUtils-MakeMaker perl-ExtUtils-ParseXS perl-Test-Harness perl-devel

运行以下命令并确保没有错误

./build.sh && ./configure && make

假设编译没有问题,那么你应该编译dbi插件。 你可以在src/.libs/dbi.so找到它

检查是否已安装所有链接库

$ ldd src/.libs/dbi.so
linux-vdso.so.1 =>  (0x00007fff109ff000)
libdbi.so.0 => /usr/lib64/libdbi.so.0 (0x00007fca4a53c000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fca4a338000)
libc.so.6 => /lib64/libc.so.6 (0x00007fca49fa3000)
libm.so.6 => /lib64/libm.so.6 (0x00007fca49d1f000)
/lib64/ld-linux-x86-64.so.2 (0x00007fca4a95a000)

如果看起来不错,可以将dbi.so共享对象安装到collectd lib目录,如下所示:

sudo install -o root -g root src/.libs/dbi.so /usr/lib64/collectd/

您现在应该可以重新启动collectd并加载dbi库

$ sudo service collectd restart
Stopping collectd:                                         [  OK  ]
Starting collectd:                                         [  OK  ]

希望有所帮助


I had the same issue on CentOS 6.3. The problem ended up being that there is no collectd-dbi rpm in the EPEL yum repo. You'll have to get the dbi plugin from elsewhere.

Check which version of collectd you have installed

$ yum info collectd

This is what the results were for me

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Installed Packages
Name        : collectd
Arch        : x86_64
Version     : 4.10.7
Release     : 1.el6
Size        : 1.3 M
Repo        : installed
From repo   : epel

You can try searching around the web for an RPM that someone built, but in my case I couldn't find one for my exact version. Because of this, I think the only solution is to compile collectd from source. The following are the steps I took to compile collectd and get the dbi plugin installed

Clone the collectd repo and checkout the version that you already have installed

git clone https://github.com/collectd/collectd.git
cd collectd/
git checkout collectd-4.10.7

Install dependencies to compile collectd. Below is everything I needed to install for compiling this, but there might be more you need to install. Note, libdbi-devel is required. If it doesn't get installed, then when running configure script, the dbi plugin will not enabled and not compiled.

sudo yum install autoconf automake flex ppl cloog-ppl cpp libgomp mpfr glibc-devel glibc-headers kernel-headers gcc libtool libtool-ltdl libtool-ltdl-devel libgcrypt-devel libgpg-error-devel libdbi libdbi-devel bison byacc db4-cxx db4-devel gdbm-devel perl-ExtUtils-MakeMaker perl-ExtUtils-ParseXS perl-Test-Harness perl-devel

Run the following and make sure there are no errors

./build.sh && ./configure && make

Assuming there were no issues compiling, then you should have the dbi plugin compiled. You can find it in src/.libs/dbi.so

Check that you have all the linked libraries installed

$ ldd src/.libs/dbi.so
linux-vdso.so.1 =>  (0x00007fff109ff000)
libdbi.so.0 => /usr/lib64/libdbi.so.0 (0x00007fca4a53c000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fca4a338000)
libc.so.6 => /lib64/libc.so.6 (0x00007fca49fa3000)
libm.so.6 => /lib64/libm.so.6 (0x00007fca49d1f000)
/lib64/ld-linux-x86-64.so.2 (0x00007fca4a95a000)

If that looks good, you can install the dbi.so shared object to the collectd lib directory like so:

sudo install -o root -g root src/.libs/dbi.so /usr/lib64/collectd/

You should now be able to restart collectd and have the dbi library loaded

$ sudo service collectd restart
Stopping collectd:                                         [  OK  ]
Starting collectd:                                         [  OK  ]

Hope that helps

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)