文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Extending the Database: C Functions

Extending the Database: C Functions

时间:2010-01-23  来源:admin126com

Extending the Database: C Functions

* You have to be a database superuser to insert C functions into the database.

* C functions are written in C and compiled into a shared library.

* You can use the Server Programming Interface (SPI) to access database data from within those routines.

* Example:

postgres:/home/postgres/lib# cat double.c
#include <stdio.h>

extern int double_me(int a)
{
    return a*2;
}
postgres:/home/postgres/lib# gcc -shared -Wl,-soname,libpgdouble.so.1 \ 
>                                  -o libpgdouble.so double.c
postgres:/home/postgres/lib# psql test
Welcome to the POSTGRESQL interactive sql monitor:
  Please read the file COPYRIGHT for copyright terms of POSTGRESQL
[PostgreSQL 6.5.2 on i686-pc-linux-gnu, compiled by gcc egcs-2.91.66]

   type \? for help on slash commands
   type \q to quit
   type \g or terminate with semicolon to execute query
 You are currently connected to the database: test

test=> CREATE FUNCTION double_me(int4) 
test-> RETURNS int4
test-> AS '/home/postgres/lib/libpgdouble.so' 
test-> LANGUAGE 'c' \g
CREATE
test=> SELECT double_me(5) \g
double_me
---------
       10
(1 row)

test=>
相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载