Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
2da2d347
Commit
2da2d347
authored
19 years ago
by
Tom Lane
Browse files
Options
Downloads
Patches
Plain Diff
Clean up version comparison/display code, per gripe from Michael Fuhr.
parent
03728942
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/bin/psql/startup.c
+51
-33
51 additions, 33 deletions
src/bin/psql/startup.c
with
51 additions
and
33 deletions
src/bin/psql/startup.c
+
51
−
33
View file @
2da2d347
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
*
*
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
*
*
* $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.12
1
2005/09/05 1
3:59:08 momjian
Exp $
* $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.12
2
2005/09/05 1
8:05:13 tgl
Exp $
*/
*/
#include
"postgres_fe.h"
#include
"postgres_fe.h"
...
@@ -78,6 +78,7 @@ struct adhoc_opts
...
@@ -78,6 +78,7 @@ struct adhoc_opts
bool
no_psqlrc
;
bool
no_psqlrc
;
};
};
static
int
parse_version
(
const
char
*
versionString
);
static
void
parse_psql_options
(
int
argc
,
char
*
argv
[],
static
void
parse_psql_options
(
int
argc
,
char
*
argv
[],
struct
adhoc_opts
*
options
);
struct
adhoc_opts
*
options
);
static
void
process_psqlrc
(
char
*
argv0
);
static
void
process_psqlrc
(
char
*
argv0
);
...
@@ -312,51 +313,46 @@ main(int argc, char *argv[])
...
@@ -312,51 +313,46 @@ main(int argc, char *argv[])
if
(
!
QUIET
()
&&
!
pset
.
notty
)
if
(
!
QUIET
()
&&
!
pset
.
notty
)
{
{
/*
int
client_ver
=
parse_version
(
PG_VERSION
);
* Server value for 8.12 is 80102.
* This code does not handle release numbers like
* 8.112. (Is that 8.1, version 12, or 8.11, version 2?
*/
int
client_ver_major_int
=
atoi
(
PG_VERSION
)
*
100
+
strchr
(
PG_VERSION
,
'.'
)[
1
]
-
'0'
;
int
client_ver_int
=
atoi
(
PG_VERSION
)
*
10000
+
(
strchr
(
PG_VERSION
,
'.'
)[
1
]
-
'0'
)
*
100
+
(
isdigit
(
strchr
(
PG_VERSION
,
'.'
)[
2
])
?
strchr
(
PG_VERSION
,
'.'
)[
2
]
-
'0'
:
'\0'
);
if
(
pset
.
sversion
/
100
!=
client_ver_major_int
)
{
printf
(
_
(
"WARNING: You are connected to a server with major version %d.%d,
\n
"
"but your %s client is major version %d.%d. Informational backslash
\n
"
"commands, like
\\
d, might not work properly.
\n\n
"
),
pset
.
sversion
/
10000
,
(
pset
.
sversion
/
100
)
%
10
,
pset
.
progname
,
atoi
(
PG_VERSION
),
strchr
(
PG_VERSION
,
'.'
)[
1
]
-
'0'
);
}
if
(
pset
.
sversion
!=
client_ver
_int
)
if
(
pset
.
sversion
!=
client_ver
)
{
{
const
char
*
server_version
;
char
server_ver_str
[
16
];
char
server_ver_str
[
16
];
snprintf
(
server_ver_str
,
16
,
"%d.%c%c"
,
pset
.
sversion
/
10000
,
/* Try to get full text form, might include "devel" etc */
(
pset
.
sversion
/
100
)
%
10
+
'0'
,
server_version
=
PQparameterStatus
(
pset
.
db
,
"server_version"
);
/* print last digit? */
if
(
!
server_version
)
(
pset
.
sversion
%
10
!=
0
)
?
{
pset
.
sversion
%
10
+
'0'
:
'\0'
);
snprintf
(
server_ver_str
,
sizeof
(
server_ver_str
),
"%d.%d.%d"
,
printf
(
_
(
"Welcome to %s, the PostgreSQL interactive terminal.
\n
"
),
pset
.
sversion
/
10000
,
pset
.
progname
);
(
pset
.
sversion
/
100
)
%
100
,
printf
(
_
(
"%s version %s, server version %s
\n\n
"
),
pset
.
sversion
%
100
);
pset
.
progname
,
PG_VERSION
,
server_ver_str
);
server_version
=
server_ver_str
;
}
printf
(
_
(
"Welcome to %s %s (server %s), the PostgreSQL interactive terminal.
\n\n
"
),
pset
.
progname
,
PG_VERSION
,
server_version
);
}
}
else
else
printf
(
_
(
"Welcome to %s %s, the PostgreSQL interactive terminal.
\n\n
"
),
printf
(
_
(
"Welcome to %s %s, the PostgreSQL interactive terminal.
\n\n
"
),
pset
.
progname
,
PG_VERSION
);
pset
.
progname
,
PG_VERSION
);
printf
(
_
(
"Type:
\\
copyright for distribution terms
\n
"
printf
(
_
(
"Type:
\\
copyright for distribution terms
\n
"
"
\\
h for help with SQL commands
\n
"
"
\\
h for help with SQL commands
\n
"
"
\\
? for help with psql commands
\n
"
"
\\
? for help with psql commands
\n
"
"
\\
g or terminate with semicolon to execute query
\n
"
"
\\
g or terminate with semicolon to execute query
\n
"
"
\\
q to quit
\n\n
"
));
"
\\
q to quit
\n\n
"
));
if
(
pset
.
sversion
/
100
!=
client_ver
/
100
)
printf
(
_
(
"WARNING: You are connected to a server with major version %d.%d,
\n
"
"but your %s client is major version %d.%d. Some backslash commands,
\n
"
"such as
\\
d, might not work properly.
\n\n
"
),
pset
.
sversion
/
10000
,
(
pset
.
sversion
/
100
)
%
100
,
pset
.
progname
,
client_ver
/
10000
,
(
client_ver
/
100
)
%
100
);
#ifdef USE_SSL
#ifdef USE_SSL
printSSLInfo
();
printSSLInfo
();
#endif
#endif
...
@@ -383,6 +379,28 @@ main(int argc, char *argv[])
...
@@ -383,6 +379,28 @@ main(int argc, char *argv[])
}
}
/*
* Convert a version string into a number.
*/
static
int
parse_version
(
const
char
*
versionString
)
{
int
cnt
;
int
vmaj
,
vmin
,
vrev
;
cnt
=
sscanf
(
versionString
,
"%d.%d.%d"
,
&
vmaj
,
&
vmin
,
&
vrev
);
if
(
cnt
<
2
)
return
-
1
;
if
(
cnt
==
2
)
vrev
=
0
;
return
(
100
*
vmaj
+
vmin
)
*
100
+
vrev
;
}
/*
/*
* Parse command line options
* Parse command line options
...
...
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