Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
node-sqlite3
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
node-sqlite3
Commits
edf899c5
Commit
edf899c5
authored
Mar 22, 2010
by
Orlando Vazquez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allocate once and reuse stored column count, names and type data
parent
f1fbcd91
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
10 deletions
+21
-10
sqlite3_bindings.cc
sqlite3_bindings.cc
+21
-10
No files found.
sqlite3_bindings.cc
View file @
edf899c5
...
@@ -848,10 +848,6 @@ protected:
...
@@ -848,10 +848,6 @@ protected:
if
(
req
->
result
==
SQLITE_ROW
&&
step_req
->
column_count
)
{
if
(
req
->
result
==
SQLITE_ROW
&&
step_req
->
column_count
)
{
free
((
void
**
)
step_req
->
column_data
);
free
((
void
**
)
step_req
->
column_data
);
step_req
->
column_data
=
NULL
;
step_req
->
column_data
=
NULL
;
free
((
int
*
)
step_req
->
column_types
);
step_req
->
column_types
=
NULL
;
free
((
char
**
)
step_req
->
column_names
);
step_req
->
column_names
=
NULL
;
}
}
step_req
->
sto
->
Unref
();
step_req
->
sto
->
Unref
();
...
@@ -875,23 +871,35 @@ protected:
...
@@ -875,23 +871,35 @@ protected:
assert
(
step_req
);
assert
(
step_req
);
if
(
rc
==
SQLITE_ROW
)
{
if
(
rc
==
SQLITE_ROW
)
{
// would be nice to cache the column names and type data somewhere
// If these pointers are NULL, look up and store the number of columns
if
(
step_req
->
column_count
=
sqlite3_column_count
(
stmt
))
{
// their names and types.
// Otherwise that means we have already looked up the column types and
// names so we can simply re-use that info.
if
(
!
step_req
->
column_types
&&
!
step_req
->
column_names
)
{
step_req
->
column_count
=
sqlite3_column_count
(
stmt
);
step_req
->
column_types
=
step_req
->
column_types
=
(
int
*
)
calloc
(
step_req
->
column_count
,
sizeof
(
int
));
(
int
*
)
calloc
(
step_req
->
column_count
,
sizeof
(
int
));
step_req
->
column_data
=
(
void
**
)
calloc
(
step_req
->
column_count
,
sizeof
(
void
*
));
step_req
->
column_names
=
step_req
->
column_names
=
(
char
**
)
calloc
(
step_req
->
column_count
,
sizeof
(
char
*
));
(
char
**
)
calloc
(
step_req
->
column_count
,
sizeof
(
char
*
));
for
(
int
i
=
0
;
i
<
step_req
->
column_count
;
i
++
)
{
step_req
->
column_types
[
i
]
=
sqlite3_column_type
(
stmt
,
i
);
step_req
->
column_names
[
i
]
=
(
char
*
)
sqlite3_column_name
(
stmt
,
i
);
}
}
if
(
step_req
->
column_count
)
{
step_req
->
column_data
=
(
void
**
)
calloc
(
step_req
->
column_count
,
sizeof
(
void
*
));
}
}
assert
(
step_req
->
column_types
assert
(
step_req
->
column_types
&&
step_req
->
column_data
&&
step_req
->
column_data
&&
step_req
->
column_names
);
&&
step_req
->
column_names
);
for
(
int
i
=
0
;
i
<
step_req
->
column_count
;
i
++
)
{
for
(
int
i
=
0
;
i
<
step_req
->
column_count
;
i
++
)
{
int
type
=
step_req
->
column_types
[
i
]
=
sqlite3_column_type
(
stmt
,
i
);
int
type
=
step_req
->
column_types
[
i
];
step_req
->
column_names
[
i
]
=
(
char
*
)
sqlite3_column_name
(
stmt
,
i
);
switch
(
type
)
{
switch
(
type
)
{
case
SQLITE_INTEGER
:
{
case
SQLITE_INTEGER
:
{
...
@@ -951,6 +959,9 @@ protected:
...
@@ -951,6 +959,9 @@ protected:
if
(
!
step_req
)
{
if
(
!
step_req
)
{
sto
->
step_req
=
step_req
=
(
struct
step_request
*
)
sto
->
step_req
=
step_req
=
(
struct
step_request
*
)
calloc
(
1
,
sizeof
(
struct
step_request
));
calloc
(
1
,
sizeof
(
struct
step_request
));
step_req
->
column_types
=
NULL
;
step_req
->
column_names
=
NULL
;
step_req
->
column_data
=
NULL
;
}
}
if
(
!
step_req
)
{
if
(
!
step_req
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment