Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pike
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pikelang
pike
Commits
b8554be5
Commit
b8554be5
authored
Jul 8, 1998
by
Martin Stjernholm
Browse files
Options
Downloads
Patches
Plain Diff
Use function variables for query and friends.
Rev: lib/modules/Sql.pmod/sql.pike:1.26
parent
4f4851ac
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/modules/Sql.pmod/sql.pike
+29
-57
29 additions, 57 deletions
lib/modules/Sql.pmod/sql.pike
with
29 additions
and
57 deletions
lib/modules/Sql.pmod/sql.pike
+
29
−
57
View file @
b8554be5
/*
* $Id: sql.pike,v 1.2
5
1998/07/0
3
2
0
:0
3:51
mast Exp $
* $Id: sql.pike,v 1.2
6
1998/07/0
8
2
1
:0
5:20
mast Exp $
*
* Implements the generic parts of the SQL-interface
*
...
...
@@ -8,7 +8,7 @@
//.
//. File: sql.pike
//. RCSID: $Id: sql.pike,v 1.2
5
1998/07/0
3
2
0
:0
3:51
mast Exp $
//. RCSID: $Id: sql.pike,v 1.2
6
1998/07/0
8
2
1
:0
5:20
mast Exp $
//. Author: Henrik Grubbstrm (grubba@idonex.se)
//.
//. Synopsis: Implements the generic parts of the SQL-interface.
...
...
@@ -35,87 +35,49 @@ int case_convert;
//. - quote
//. Quote a string so that it can safely be put in a query.
//. > s - String to quote.
string quote
(string s)
function(string:string) quote = lambda
(string s)
{
if (master_sql && master_sql->quote) {
return(master_sql->quote(s));
}
// This lambda is overridden from master_sql in create().
return(replace(s, "\'", "\'\'"));
}
}
;
//. - encode_time
//. Converts a system time value to an appropriately formatted time
//. spec for the database.
//. >
time
- Time to encode.
//. >
date
- If nonzero then time is taken as a "full" unix time spec
//. >
arg 1
- Time to encode.
//. >
arg 2
- If nonzero then time is taken as a "full" unix time spec
//. (where the date part is ignored), otherwise it's converted as a
//. seconds-since-midnight value.
string encode_time (int time, void|int date)
{
if (functionp (master_sql->encode_time))
return master_sql->encode_time (time, date);
else
throw_error ("sql->encode_time(): Not supported by this database\n");
}
function(int,void|int:string) encode_time;
//. - decode_time
//. Converts a database time spec to a system time value.
//. >
timestr
- Time spec to decode.
//. >
date
- Take the date part from this system time value. If zero, a
//. >
arg 1
- Time spec to decode.
//. >
arg 2
- Take the date part from this system time value. If zero, a
//. seconds-since-midnight value is returned.
int decode_time (string timestr, void|int date)
{
if (functionp (master_sql->decode_time))
return master_sql->decode_time (timestr, date);
else
throw_error ("sql->decode_time(): Not supported by this database\n");
}
function(string,void|int:int) decode_time;
//. - encode_date
//. Converts a system time value to an appropriately formatted
//. date-only spec for the database.
//. > time - Time to encode.
string encode_date (int time)
{
if (functionp (master_sql->encode_date))
return master_sql->encode_date (time);
else
throw_error ("sql->encode_date(): Not supported by this database\n");
}
//. > arg 1 - Time to encode.
function(int:string) encode_date;
//. - decode_date
//. Converts a database date-only spec to a system time value.
//. > datestr - Date spec to decode.
int decode_date (string datestr)
{
if (functionp (master_sql->decode_date))
return master_sql->decode_date (datestr);
else
throw_error ("sql->decode_date(): Not supported by this database\n");
}
//. > arg 1 - Date spec to decode.
function(string:int) decode_date;
//. - encode_datetime
//. Converts a system time value to an appropriately formatted
//. date and time spec for the database.
//. > time - Time to encode.
string encode_datetime (int time)
{
if (functionp (master_sql->encode_datetime))
return master_sql->encode_datetime (time);
else
throw_error ("sql->encode_datetime(): Not supported by this database\n");
}
//. > arg 1 - Time to encode.
function(int:string) encode_datetime;
//. - decode_datetime
//. Converts a database date and time spec to a system time value.
//. > datestr - Date and time spec to decode.
int decode_datetime (string timestr)
{
if (functionp (master_sql->decode_datetime))
return master_sql->decode_datetime (timestr);
else
throw_error ("sql->decode_datetime(): Not supported by this database\n");
}
//. > arg 1 - Date and time spec to decode.
function(string:int) decode_datetime;
//. - create
//. Create a new generic SQL object.
...
...
@@ -284,6 +246,16 @@ void create(void|string|object host, void|string db,
throw_error("Sql.sql(): Couldn't connect using the " +
(program_names[0]/".pike")[0] + " database\n");
}
function fallback =
lambda () {throw_error ("Function not supported in this database.");};
if (master_sql->quote) quote = master_sql->quote;
encode_time = master_sql->encode_time || fallback;
decode_time = master_sql->decode_time || fallback;
encode_date = master_sql->encode_date || fallback;
decode_date = master_sql->decode_date || fallback;
encode_datetime = master_sql->encode_datetime || fallback;
decode_datetime = master_sql->decode_datetime || fallback;
}
static private array(mapping(string:mixed)) res_obj_to_array(object res_obj)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment