Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

implemented GetLength() and any funcs.

  • Loading branch information...
commit 117b3c160de9c06baa89989dfa72e7c2c1c08095 1 parent f5a59e8
@oibore authored
View
6 CHANGES
@@ -1,4 +1,8 @@
-* 0.0.1 2009/11/15 oibore
+* 0.0.3 2009/11/17 oibore
+ implemented GetLength(), FName(), FNumber(), FType(), FSize(), FMod().
+
+* 0.0.2 2009/11/15 oibore
+ add type PgResults, and return by pg.Exec().
add type PgResults, and return by pg.Exec().
GetIsNull() return bool.
implemented FetchRow().
View
12 README
@@ -1,10 +1,14 @@
PostgreSQL bindings for golang
-$ cd ./src
-$ make
-$ ./runner
+This module is PostgreSQL bindings for golang. It is near compatible in CPAN Pg module.
-Read runner.go
+o INSTALL
+ $ cd ./src
+ $ make
+ $ ./runner
+
+o SAMPLE OF USAGE
+ src/runner.go
--
oibore
View
33 src/pg.go
@@ -1,3 +1,6 @@
+//
+// pg.go
+//
package pg
// #include "pg_wrapper.h"
@@ -54,9 +57,33 @@ func GetIsNull(res *PgResults, row_number int, column_number int) bool {
}
func GetValue(res *PgResults, row_number int, column_number int) string {
- value := C.GoString(C.PgGetValue(res.result, _C_int(row_number),
- _C_int(column_number)));
- return value;
+ return C.GoString(C.PgGetValue(res.result, _C_int(row_number),
+ _C_int(column_number)));
+}
+
+func GetLength(res *PgResults, row_number int, column_number int) int {
+ return int(C.PgGetLength(res.result, _C_int(row_number),
+ _C_int(column_number)));
+}
+
+func FName(res *PgResults, column_number int) string {
+ return C.GoString(C.PgFName(res.result, _C_int(column_number)));
+}
+
+func FNumber(res *PgResults, column_name string) int {
+ return int(C.PgFNumber(res.result, C.CString(column_name)));
+}
+
+func FType(res *PgResults, column_number int) int {
+ return int(C.PgFType(res.result, _C_int(column_number)));
+}
+
+func FSize(res *PgResults, column_number int) int {
+ return int(C.PgFSize(res.result, _C_int(column_number)));
+}
+
+func FMod(res *PgResults, column_number int) int {
+ return int(C.PgFMod(res.result, _C_int(column_number)));
}
func FetchRow(res *PgResults) []string {
View
42 src/pg_wrapper.c
@@ -1,3 +1,7 @@
+/*
+ * pg_wrapper.c
+ */
+
#include <libpq-fe.h>
#include "pg_wrapper.h"
@@ -27,22 +31,52 @@ void *PgGetResult(void *conn)
return PQgetResult(conn);
}
-int PgNFields(void *res)
+int PgNFields(const void *res)
{
return PQnfields(res);
}
-int PgNTuples(void *res)
+int PgNTuples(const void *res)
{
return PQntuples(res);
}
-int PgGetIsNull(void *res, int row_number, int column_number)
+int PgGetIsNull(const void *res, int row_number, int column_number)
{
return PQgetisnull(res, row_number, column_number);
}
-char *PgGetValue(void *res, int row_number, int column_number)
+char *PgGetValue(const void *res, int row_number, int column_number)
{
return PQgetvalue(res, row_number, column_number);
}
+
+int PgGetLength(const void *res, int row_number, int column_number)
+{
+ return PQgetlength(res, row_number, column_number);
+}
+
+char *PgFName(const void *res, int column_number)
+{
+ return PQfname(res, column_number);
+}
+
+int PgFNumber(const void *res, const char *column_name)
+{
+ return PQfnumber(res, column_name);
+}
+
+int PgFType(const void *res, int column_number)
+{
+ return PQftype(res, column_number);
+}
+
+int PgFSize(const void *res, int column_number)
+{
+ return PQfsize(res, column_number);
+}
+
+int PgFMod(const void *res, int column_number)
+{
+ return PQfmod(res, column_number);
+}
View
18 src/pg_wrapper.h
@@ -1,3 +1,7 @@
+/*
+ * pg_wrapper.h
+ */
+
#ifndef __PG_WRAPPER_H__
#define __PG_WRAPPER_H__
@@ -6,10 +10,16 @@ void PgFinish(void *conn);
int PgStatus(void *conn);
void *PgExec(void *conn, const char *command);
void *PgGetResult(void *conn);
-int PgNFields(void *res);
-int PgNTuples(void *res);
-int PgGetIsNull(void *res, int row_number, int column_number);
-char *PgGetValue(void *res, int row_number, int column_number);
+int PgNFields(const void *res);
+int PgNTuples(const void *res);
+int PgGetIsNull(const void *res, int row_number, int column_number);
+char *PgGetValue(const void *res, int row_number, int column_number);
+int PgGetLength(const void *res, int row_number, int column_number);
+char *PgFName(const void *res, int column_number);
+int PgFNumber(const void *res, const char *column_name);
+int PgFType(const void *res, int column_number);
+int PgFSize(const void *res, int column_number);
+int PgFMod(const void *res, int column_number);
#endif /* __PG_WRAPPER_H__ */
View
BIN  src/runner
Binary file not shown
View
17 src/runner.go
@@ -1,3 +1,6 @@
+//
+// runner.go
+//
package main
import (
@@ -30,10 +33,16 @@ func main() {
fmt.Printf("values = %s\n", values);
}
- res = pg.Exec(conn, "select count(*) from users;");
- row := pg.FetchRow(res);
- values := strings.Join(row, ",");
- fmt.Printf("values = %s\n", values);
+ res = pg.Exec(conn, "select * from users;");
+ len := pg.GetLength(res, 0, 0);
+ fmt.Printf("length = %d\n", len);
+ fname := pg.FName(res, 0);
+ ftype := pg.FType(res, 0);
+ fnumber := pg.FNumber(res, "name");
+ fsize := pg.FSize(res, 0);
+ fmod := pg.FMod(res, 0);
+ fmt.Printf("fname=%s, ftype=%d, fnumber=%d, fsize=%d, fmod=%d\n",
+ fname, ftype, fnumber, fsize, fmod);
pg.Close(conn);
}
Please sign in to comment.
Something went wrong with that request. Please try again.