我正在使用PL/pgSQL编写SP.
我想返回一个记录,由几个不同的表中的字段组成.看起来像这样:
CREATE OR REPLACE FUNCTION get_object_fields(name text)
RETURNS RECORD AS $$
BEGIN
-- fetch fields f1, f2 and f3 from table t1
-- fetch fields f4, f5 from table t2
-- fetch fields f6, f7 and f8 from table t3
-- return fields f1 ... f8 as a record
END
$$ language plpgsql;
Run Code Online (Sandbox Code Playgroud)
如何将不同表中的字段作为单个记录中的字段返回?
[编辑]
我已经意识到我上面给出的例子有点过于简单了.我需要检索的一些字段将被保存为要查询的数据库表中的单独行,但我想在"展平"记录结构中返回它们.
下面的代码应该有助于进一步说明:
CREATE TABLE user (id int, school_id int, name varchar(32));
CREATE TYPE my_type (
user1_id int,
user1_name varchar(32),
user2_id int,
user2_name varchar(32)
); …Run Code Online (Sandbox Code Playgroud) 我写了以下课程:
class myClass(object):
def __init__(self):
pass
def foo(self, arg1, arg2):
pp = foobar(self, arg1, arg2)
if pp:
return 42
else
return -666
def foobar(self, arg1, arg2):
if arg1 == arg2:
return 42
else:
return None
Run Code Online (Sandbox Code Playgroud)
逻辑是荒谬的 - 忽略它.我想要的是从另一个实例方法调用实例方法 - 我得到了一个NameError.我原本以为这是因为它在定义之前foo()调用foobar()了 - 但是在脚本中切换函数定义的顺序没有任何区别.
是否有人导致此错误,以及如何解决它?
我试图在Linux Ubuntu 10.x机器上构建fastcgi.
我运行以下命令:
./configure make
我收到以下错误:
fcgio.cpp: In destructor 'virtual fcgi_streambuf::~fcgi_streambuf()':
fcgio.cpp:50: error: 'EOF' was not declared in this scope
fcgio.cpp: In member function 'virtual int fcgi_streambuf::overflow(int)':
fcgio.cpp:70: error: 'EOF' was not declared in this scope
fcgio.cpp:75: error: 'EOF' was not declared in this scope
fcgio.cpp: In member function 'virtual int fcgi_streambuf::sync()':
fcgio.cpp:86: error: 'EOF' was not declared in this scope
fcgio.cpp:87: error: 'EOF' was not declared in this scope
fcgio.cpp: In member function 'virtual int fcgi_streambuf::underflow()':
fcgio.cpp:107: error: …Run Code Online (Sandbox Code Playgroud) 我正在Linux上构建C++可执行文件.可执行文件链接到一些boost库.
这是我尝试运行二进制文件时的输出:
root@yourbox:~/work/dev/c++/projects/testfgci/dist/Debug/GNU-Linux-x86$ ./testfgci
./testfgci: error while loading shared libraries: libboost_system.so.1.45.0: cannot open shared object file: No such file or directory
Run Code Online (Sandbox Code Playgroud)
然后我在二进制文件上运行ldd来检查依赖项:
root@yourbox:~/work/dev/c++/projects/testfgci/dist/Debug/GNU-Linux-x86$ ldd testfgci
linux-gate.so.1 => (0x00380000)
libboost_system.so.1.45.0 => not found
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00b50000)
libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0x005f6000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x0099a000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x001b3000)
libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0x00110000)
/lib/ld-linux.so.2 (0x00ea2000)
Run Code Online (Sandbox Code Playgroud)
我不确定为什么找不到liboos_system.sl.1.45.0 SO.我今天早些时候成功地建造了它.谁能解释一下?
通过完全删除以前的boost目录,下载1.45源并重建我想要的库,我最近从boost 1.40升级到1.45.然后我使用bjam install安装了libs.
我的机器上没有其他任何改变,但是,现在当我构建我的C++程序时,我收到以下链接错误:
/usr/bin/ld: cannot find -lboost_system-mt
Run Code Online (Sandbox Code Playgroud)
我搜索过,文件确实不存在.似乎mt库不再是库的一部分 - 或者我错过了什么?
我怎么解决这个问题?
我已经有一段时间没有使用C++的高级功能了,并且正在刷新我的C++知识.话虽如此,基于特征和策略编程的概念是我从未真正设法解决的问题.
我想改变这一点.我正在写一个通用容器.我想强制执行一个策略,即容器只存储从特定基类派生的类.这是因为当尝试访问向量边界外的项时,容器返回无效对象(而不是抛出).
template <class T>
class GenericContainer
{
private:
typedef std::vector<T> TypeVect;
void addElement(const T& elem);
TypeVect m_elems;
public:
unsigned int size() const;
T& elementAt(const unsigned int pos);
const T elementAt(const unsigned int pos) const;
};
Run Code Online (Sandbox Code Playgroud)
我如何使用traits来限制这个泛型容器只包含类'ContainerItem'的子类?
我正在尝试在Ubuntu 10.x上构建jsoncpp - 但是'指令'有时是模糊的.例如,在构建lib之前,不清楚scons.py文件需要驻留在哪个文件夹中.
有人可以概述构建jsoncpp库所需的步骤吗?在Linux上,或者如果没有这个,如果有人知道有这个信息的任何在线资源,请分享链接.
我对django比较新.我已经定义了我的数据库模式并验证了它没有错误(manage.py验证报告找到0错误).
然而,当我运行./manage.py syncdb时
我得到以下堆栈跟踪:
Creating table demo_foobar_one
Creating table demo_foobar_two
<snip>...</snip>
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 218, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 347, in handle
return self.handle_noargs(**options)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/commands/syncdb.py", line 103, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive, db)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/sql.py", line 185, in emit_post_sync_signal
interactive=interactive, …Run Code Online (Sandbox Code Playgroud) 我熟悉Django.
我已经成功安装并测试了一个演示站点.我现在想要打开管理模块,看看会发生什么.
我采取的步骤(授予,一些是不必要的,但我只是想确保我从一个干净的石板开始):
这是我的mysite/settings.py文件的样子(仅限相关部分)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# The next lines are my models
'mysite.foo',
'mysite.foobar',
)
Run Code Online (Sandbox Code Playgroud)
这是我的mysite/urls.py文件的样子:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Example:
# (r'^mysite/', include('mysite.foo.urls')),
# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin: …Run Code Online (Sandbox Code Playgroud) 我刚遇到Codemirror.
我想知道如何创建自己的语法文件(用于玩具语言),或者使用新关键字扩展现有语言的语法文件 - 但是,我找不到任何关于如何开始的文档.
有没有人在文档上显示如何做到这一点?
c++ ×5
python ×3
django ×2
linux ×2
boost ×1
c ×1
codemirror ×1
django-admin ×1
django-urls ×1
fastcgi ×1
g++ ×1
javascript ×1
json ×1
ld ×1
ldd ×1
makefile ×1
nameerror ×1
namespaces ×1
plpgsql ×1
postgresql ×1
scons ×1
sql ×1
templates ×1
traits ×1
types ×1
ubuntu ×1