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
31d6ecf5
Commit
31d6ecf5
authored
Mar 26, 2010
by
Orlando Vazquez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allocate memory for row cells once per statement execution
parent
025b75e4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
20 deletions
+28
-20
sqlite3_bindings.cc
sqlite3_bindings.cc
+28
-20
No files found.
sqlite3_bindings.cc
View file @
31d6ecf5
...
...
@@ -864,15 +864,32 @@ protected:
sto
->
column_names_
=
(
char
**
)
calloc
(
sto
->
column_count_
,
sizeof
(
char
*
));
if
(
sto
->
column_count_
)
{
sto
->
column_data_
=
(
void
**
)
calloc
(
sto
->
column_count_
,
sizeof
(
void
*
));
}
for
(
int
i
=
0
;
i
<
sto
->
column_count_
;
i
++
)
{
sto
->
column_types_
[
i
]
=
sqlite3_column_type
(
stmt
,
i
);
sto
->
column_names_
[
i
]
=
(
char
*
)
sqlite3_column_name
(
stmt
,
i
);
}
}
if
(
sto
->
column_count_
)
{
sto
->
column_data_
=
(
void
**
)
calloc
(
sto
->
column_count_
,
sizeof
(
void
*
));
switch
(
sto
->
column_types_
[
i
])
{
case
SQLITE_INTEGER
:
// XXX reuse this space instead of allocating every time
sto
->
column_data_
[
i
]
=
(
int
*
)
malloc
(
sizeof
(
int
));
break
;
case
SQLITE_FLOAT
:
sto
->
column_data_
[
i
]
=
(
double
*
)
malloc
(
sizeof
(
double
));
break
;
// no need to allocate memory for strings
default
:
{
// unsupported type
}
}
}
}
assert
(
sto
->
column_types_
&&
sto
->
column_data_
&&
sto
->
column_names_
);
...
...
@@ -881,21 +898,13 @@ protected:
int
type
=
sto
->
column_types_
[
i
];
switch
(
type
)
{
case
SQLITE_INTEGER
:
{
// XXX reuse this space instead of allocating every time
sto
->
column_data_
[
i
]
=
(
int
*
)
malloc
(
sizeof
(
int
));
int
value
=
sqlite3_column_int
(
stmt
,
i
);
*
(
int
*
)(
sto
->
column_data_
[
i
])
=
value
;
assert
(
sto
->
column_data_
[
i
]);
}
case
SQLITE_INTEGER
:
*
(
int
*
)(
sto
->
column_data_
[
i
])
=
sqlite3_column_int
(
stmt
,
i
);
assert
(
sto
->
column_data_
[
i
]);
break
;
case
SQLITE_FLOAT
:
{
double
*
value
=
(
double
*
)
malloc
(
sizeof
(
double
));
*
value
=
sqlite3_column_double
(
stmt
,
i
);
sto
->
column_data_
[
i
]
=
value
;
}
case
SQLITE_FLOAT
:
*
(
double
*
)(
sto
->
column_data_
[
i
])
=
sqlite3_column_double
(
stmt
,
i
);
break
;
case
SQLITE_TEXT
:
{
...
...
@@ -904,8 +913,7 @@ protected:
// it will be reclaimed on the next step, reset, or finalize.
// I'm going to assume it's okay to keep this pointer around
// until it is used in `EIO_AfterStep`
char
*
value
=
(
char
*
)
sqlite3_column_text
(
stmt
,
i
);
sto
->
column_data_
[
i
]
=
value
;
sto
->
column_data_
[
i
]
=
(
char
*
)
sqlite3_column_text
(
stmt
,
i
);
}
break
;
...
...
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