5 use,
intrinsic :: iso_c_binding
15 character(:, c_char),
allocatable :: name
16 integer(SQLSMALLINT) :: type
17 integer(SQLULEN) :: size
18 integer(SQLSMALLINT) :: decim_size
19 integer(SQLSMALLINT) :: nullable
20 character(:),
allocatable :: content
30 type(column),
allocatable,
public :: items(:)
33 procedure, pass(this),
public :: add => columnset_add_column
34 procedure, pass(this),
public :: addrange => columnset_addrange_columns
36 procedure, pass(this),
public :: count => columnset_get_columns_count
37 procedure, pass(this),
private :: columnset_get_column_from_id
38 procedure, pass(this),
private :: columnset_get_column_from_name
39 generic,
public :: get => columnset_get_column_from_id, &
40 columnset_get_column_from_name
41 final :: columnset_finalize
54 type(sqlhstmt),
intent(inout) :: stmt
55 integer,
intent(in) :: col_no
57 integer(SQLRETURN) :: res
59 res = columnset_bind_internal(stmt, int(col_no, sqlusmallint), this%items(col_no)%content)
61 function columnset_bind_internal(stmt, col_no, buff)
result(res)
62 type(sqlhstmt),
intent(inout) :: stmt
63 integer(SQLUSMALLINT),
intent(in) :: col_no
64 character(*, SQLCHAR),
intent(inout),
target :: buff
66 integer(SQLLEN),
allocatable :: sz
67 integer(SQLRETURN) :: res
69 allocate(sz, source = 0)
71 res =
sqlbindcol(stmt, col_no, sql_char, c_loc(buff), &
72 len(buff, c_long), sz)
79 function columnset_get_columns_count(this)
result(res)
88 subroutine columnset_add_column(this, col)
90 type(
column),
intent(in) :: col
92 type(
column),
allocatable :: tmp(:)
94 if (.not.
allocated(this%items))
allocate(this%items(0))
95 this%ncols = this%ncols + 1
96 allocate(tmp(this%ncols))
97 tmp(:this%ncols-1) = this%items
99 call move_alloc(tmp, this%items)
105 subroutine columnset_addrange_columns(this, cols)
107 type(
column),
intent(in) :: cols(:)
109 type(
column),
allocatable :: tmp(:)
111 if (.not.
allocated(this%items))
allocate(this%items(0))
112 this%ncols = this%ncols +
size(cols)
113 allocate(tmp(this%ncols))
114 tmp(:this%ncols-
size(cols)) = this%items
115 tmp(this%ncols-
size(cols)+1:) = cols
116 call move_alloc(tmp, this%items)
124 function columnset_get_column_from_id(this, n)
result(res)
125 class(
columnset),
intent(inout),
target :: this
126 integer,
intent(in) :: n
127 type(
column),
pointer :: res
129 if (
size(this%items) <= 0)
then
141 function columnset_get_column_from_name(this, name)
result(res)
142 class(
columnset),
intent(inout),
target :: this
143 character(*),
intent(in) :: name
144 type(
column),
pointer :: res
148 sz =
size(this%items)
151 if (
trim(res%name) ==
trim(adjustl(name)))
then
158 subroutine columnset_finalize(this)
161 if (
allocated(this%items))
deallocate (this%items)
integer(sqlreturn) function columnset_bind(this, stmt, col_no)
Binds a odbc_columnset::column to an ODBC statement handle for data retrieval, using SQL_CHAR binding...
Triming of c-string returning fortran allocatable characters.
Represents metadata and data for a single column in a query result, storing name, type,...
Manages a collection of odbc_columnset::column objects in a query result set, providing methods to ad...