Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Database \ PostgreSQL with the C Completing the storage process instances     - OpenSUSE 13.1 OpenSUSE 12.3 and how to install Cinnamon 2.2 Desktop (Linux)

- Arduino UNO simulation development environment set up and run simulation (Linux)

- To deploy MySQL database with separate read and write OneProxy (Database)

- Linux Mint 17 set up the Ruby environment (Linux)

- Swift acquaintance of values and references, the circular reference, Agent Precautions (Programming)

- Linux system Perl Lite netstat (Linux)

- Install MATE desktop environment adjustment tools Mate Tweak 3.3.6 (Linux)

- Shell generated using automated configuration script Orabbix (Database)

- Ease of use "Explain Shell" script to understand Shell command (Linux)

- 7 JavaScript interview questions (Programming)

- Linux processes in memory and memory cgroup statistics (Linux)

- The official release method to upgrade to Ubuntu 15.04 (Linux)

- Embedded Linux to solve the problem in the time zone (Linux)

- GlusterFS distributed storage deployment (Server)

- Implement binary search algorithm in C language (Programming)

- 30 minutes with your Quick Start MySQL Tutorial (Database)

- Linux system monitoring tool set cpu (Linux)

- SA weak password security system of the security risks posed (Linux)

- Linux Workstation Security Checklist - from the Linux Foundation Internal (Linux)

- About Java 7 module system (Programming)

 
         
  PostgreSQL with the C Completing the storage process instances
     
  Add Date : 2018-11-21      
         
         
         
  Recent note to clients wrote a PostgreSQL stored procedures written in C for example, look at this record.

Objective: To complete a C stored procedure example, stored procedures to perform a certain period table update.

Ready to work

1, install the database

2, the establishment of table test

highgo = # create table test (id int, name text, label int);
CREATE TABLE

3, the establishment of the file C, C code is as follows:

#include "postgres.h"
#include "executor / spi.h"
#include "utils / builtins.h"
 
#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif
 
int mydelete (int key);
 
int
mydelete (int key)
{
    char command [128]; // create an array depends on the length of the command corresponding size
    int ret;
    // Operations on the data table rows; int proc
 
    / * Command assigned to command * /
    sprintf (command, "update test set label = 0 where id =% d and label = 1;", key);
 
    SPI_connect (); // internal links
    ret = SPI_exec (command, 0); // perform actions
    proc = SPI_processed; // assign the number of rows
    SPI_finish (); // Disconnect
    return (proc); // will return the number of rows as a result
}

Database api reference documentation: http: //www.postgresql.org/docs/9.4/static/spi.html

Compiled into the installation

4, gcc compiler

gcc -fpic -I / opt / HighGo / db / 20150401 / include / postgresql / server / -shared -o myapi.so myapi.c

5, into the lib directory

cp myapi.so / opt / HighGo / db / 20150401 / lib / postgresql /

6, is loaded into the server

highgo = # load 'myapi';
LOAD

7. Establish function

highgo = # create function mydele (integer) returns integer as '$ libdir / myapi.so', 'mydelete' language c strict;
CREATE FUNCTION
highgo = #

8, the effect

highgo = # insert into test values ​​(1, 'jim', 1);
INSERT 0 1
highgo = # insert into test values ​​(2, 'tom', 1);
INSERT 0 1
highgo = # select * from test;
 id | name | label
---- + ------ + -------
  1 | jim | 1
  2 | tom | 1
 
highgo = # select mydele (1);
 mydele
--------
      1
(1 row)
highgo = # select * from test;
 id | name | label
---- + ------ + -------
  2 | tom | 1
  1 | jim | 0
     
         
         
         
  More:      
 
- GitLab Guide installation under Ubuntu 14.04 (Server)
- shell script: a key optimization CentOS system (Linux)
- MySQL Tutorial: Philosophical Reflections on the unauthenticated user (Database)
- Use HugePages optimize memory performance (Database)
- XP virtual machine under VirtualBox solve occupy 100% CPU problem (Linux)
- Bash variable expansion modifier (Programming)
- Use Visual Studio to compile and use WinGDB remote debugging embedded Linux programs (Programming)
- tcpdump Linux system security tools (Linux)
- Build your own Git server under Linux (Server)
- Linux system performance and usage activity monitoring tools -Sysstat (Linux)
- Use OpenSSL for RSA encryption and decryption (Linux)
- Java string intern constant pool resolution Introduction (Programming)
- Ubuntu Gitolite management Git Server code base permissions (Server)
- APF firewall installation and configuration under Linux (Linux)
- Deploy the project to the server from GitHub (Server)
- Share Practical Tutorial GitHub (Linux)
- Ubuntu will be written in a command file, executable file, source command (Linux)
- count (*) function in MySQL optimization of InnoDB storage engine (Database)
- Zabbix installation under Linux (Server)
- How to track performance issues when using the Unity Game Development Android (Programming)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.