forked from tada/pljava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQLOutputToTuple.c
More file actions
53 lines (47 loc) · 1.63 KB
/
Copy pathSQLOutputToTuple.c
File metadata and controls
53 lines (47 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* Copyright (c) 2004-2019 Tada AB and other contributors, as listed below.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the The BSD 3-Clause License
* which accompanies this distribution, and is available at
* http://opensource.org/licenses/BSD-3-Clause
*
* Contributors:
* Tada AB
* Chapman Flack
*
* @author Thomas Hallgren
*/
#include <postgres.h>
#include "pljava/type/Type.h"
#include "pljava/type/TupleDesc.h"
#include "pljava/SQLOutputToTuple.h"
static jclass s_SQLOutputToTuple_class;
static jmethodID s_SQLOutputToTuple_init;
static jmethodID s_SQLOutputToTuple_getTuple;
jobject SQLOutputToTuple_create(TupleDesc td)
{
jobject tupleDesc = pljava_TupleDesc_create(td);
jobject result = JNI_newObject(s_SQLOutputToTuple_class, s_SQLOutputToTuple_init, tupleDesc);
JNI_deleteLocalRef(tupleDesc);
return result;
}
HeapTuple SQLOutputToTuple_getTuple(jobject sqlOutput)
{
Ptr2Long p2l;
if(sqlOutput == 0)
return 0;
p2l.longVal = JNI_callLongMethod(sqlOutput, s_SQLOutputToTuple_getTuple);
if(p2l.longVal == 0)
return 0;
return (HeapTuple)p2l.ptrVal;
}
/* Make this datatype available to the postgres system.
*/
extern void SQLOutputToTuple_initialize(void);
void SQLOutputToTuple_initialize(void)
{
s_SQLOutputToTuple_class = JNI_newGlobalRef(PgObject_getJavaClass("org/postgresql/pljava/jdbc/SQLOutputToTuple"));
s_SQLOutputToTuple_init = PgObject_getJavaMethod(s_SQLOutputToTuple_class, "<init>", "(Lorg/postgresql/pljava/internal/TupleDesc;)V");
s_SQLOutputToTuple_getTuple = PgObject_getJavaMethod(s_SQLOutputToTuple_class, "getTuple", "()J");
}