mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-05 04:30:38 +03:00
Merge updates from trunk.
FossilOrigin-Name: 3e363f405655e2e39588029d797496a952cca11d
This commit is contained in:
67
src/shell.c
67
src/shell.c
@@ -24,6 +24,13 @@
|
||||
#include "msvc.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
** No support for loadable extensions in VxWorks.
|
||||
*/
|
||||
#if defined(_WRS_KERNEL) && !SQLITE_OMIT_LOAD_EXTENSION
|
||||
# define SQLITE_OMIT_LOAD_EXTENSION 1
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Enable large-file support for fopen() and friends on unix.
|
||||
*/
|
||||
@@ -107,10 +114,15 @@
|
||||
*/
|
||||
extern int isatty(int);
|
||||
|
||||
/* popen and pclose are not C89 functions and so are sometimes omitted from
|
||||
** the <stdio.h> header */
|
||||
extern FILE *popen(const char*,const char*);
|
||||
extern int pclose(FILE*);
|
||||
#if !defined(__RTP__) && !defined(_WRS_KERNEL)
|
||||
/* popen and pclose are not C89 functions and so are sometimes omitted from
|
||||
** the <stdio.h> header */
|
||||
extern FILE *popen(const char*,const char*);
|
||||
extern int pclose(FILE*);
|
||||
#else
|
||||
# define SQLITE_OMIT_POPEN 1
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32_WCE)
|
||||
@@ -165,11 +177,19 @@ static sqlite3_int64 timeOfDay(void){
|
||||
return t;
|
||||
}
|
||||
|
||||
#if !defined(_WIN32) && !defined(WIN32) && !defined(_WRS_KERNEL) \
|
||||
&& !defined(__minux)
|
||||
#if !defined(_WIN32) && !defined(WIN32) && !defined(__minux)
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
/* VxWorks does not support getrusage() as far as we can determine */
|
||||
#if defined(_WRS_KERNEL) || defined(__RTP__)
|
||||
struct rusage {
|
||||
struct timeval ru_utime; /* user CPU time used */
|
||||
struct timeval ru_stime; /* system CPU time used */
|
||||
};
|
||||
#define getrusage(A,B) memset(B,0,sizeof(*B))
|
||||
#endif
|
||||
|
||||
/* Saved resource information for the beginning of an operation */
|
||||
static struct rusage sBegin; /* CPU time at start */
|
||||
static sqlite3_int64 iBegin; /* Wall-clock time at start */
|
||||
@@ -195,8 +215,8 @@ static double timeDiff(struct timeval *pStart, struct timeval *pEnd){
|
||||
*/
|
||||
static void endTimer(void){
|
||||
if( enableTimer ){
|
||||
struct rusage sEnd;
|
||||
sqlite3_int64 iEnd = timeOfDay();
|
||||
struct rusage sEnd;
|
||||
getrusage(RUSAGE_SELF, &sEnd);
|
||||
printf("Run Time: real %.3f user %f sys %f\n",
|
||||
(iEnd - iBegin)*0.001,
|
||||
@@ -2458,7 +2478,9 @@ static void tryToClone(ShellState *p, const char *zNewDb){
|
||||
*/
|
||||
static void output_reset(ShellState *p){
|
||||
if( p->outfile[0]=='|' ){
|
||||
#ifndef SQLITE_OMIT_POPEN
|
||||
pclose(p->out);
|
||||
#endif
|
||||
}else{
|
||||
output_file_close(p->out);
|
||||
}
|
||||
@@ -2964,9 +2986,14 @@ static int do_meta_command(char *zLine, ShellState *p){
|
||||
sCtx.zFile = zFile;
|
||||
sCtx.nLine = 1;
|
||||
if( sCtx.zFile[0]=='|' ){
|
||||
#ifdef SQLITE_OMIT_POPEN
|
||||
fprintf(stderr, "Error: pipes are not supporte in this OS\n");
|
||||
return 1;
|
||||
#else
|
||||
sCtx.in = popen(sCtx.zFile+1, "r");
|
||||
sCtx.zFile = "<pipe>";
|
||||
xCloser = pclose;
|
||||
#endif
|
||||
}else{
|
||||
sCtx.in = fopen(sCtx.zFile, "rb");
|
||||
xCloser = fclose;
|
||||
@@ -3289,6 +3316,11 @@ static int do_meta_command(char *zLine, ShellState *p){
|
||||
}
|
||||
output_reset(p);
|
||||
if( zFile[0]=='|' ){
|
||||
#ifdef SQLITE_OMIT_POPEN
|
||||
fprintf(stderr,"Error: pipes are not supported in this OS\n");
|
||||
rc = 1;
|
||||
p->out = stdout;
|
||||
#else
|
||||
p->out = popen(zFile + 1, "w");
|
||||
if( p->out==0 ){
|
||||
fprintf(stderr,"Error: cannot open pipe \"%s\"\n", zFile + 1);
|
||||
@@ -3297,6 +3329,7 @@ static int do_meta_command(char *zLine, ShellState *p){
|
||||
}else{
|
||||
sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
|
||||
}
|
||||
#endif
|
||||
}else{
|
||||
p->out = output_file_open(zFile);
|
||||
if( p->out==0 ){
|
||||
@@ -3840,12 +3873,12 @@ static int do_meta_command(char *zLine, ShellState *p){
|
||||
|
||||
if( c=='t' && strncmp(azArg[0], "trace", n)==0 ){
|
||||
open_db(p, 0);
|
||||
output_file_close(p->traceOut);
|
||||
if( nArg!=2 ){
|
||||
fprintf(stderr, "Usage: .trace FILE|off\n");
|
||||
rc = 1;
|
||||
goto meta_command_exit;
|
||||
}
|
||||
output_file_close(p->traceOut);
|
||||
p->traceOut = output_file_open(azArg[1]);
|
||||
#if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT)
|
||||
if( p->traceOut==0 ){
|
||||
@@ -4221,7 +4254,7 @@ static char *find_home_dir(void){
|
||||
**
|
||||
** Returns the number of errors.
|
||||
*/
|
||||
static int process_sqliterc(
|
||||
static void process_sqliterc(
|
||||
ShellState *p, /* Configuration data */
|
||||
const char *sqliterc_override /* Name of config file. NULL to use default */
|
||||
){
|
||||
@@ -4229,15 +4262,13 @@ static int process_sqliterc(
|
||||
const char *sqliterc = sqliterc_override;
|
||||
char *zBuf = 0;
|
||||
FILE *in = NULL;
|
||||
int rc = 0;
|
||||
|
||||
if (sqliterc == NULL) {
|
||||
home_dir = find_home_dir();
|
||||
if( home_dir==0 ){
|
||||
#if !defined(__RTP__) && !defined(_WRS_KERNEL)
|
||||
fprintf(stderr,"%s: Error: cannot locate your home directory\n", Argv0);
|
||||
#endif
|
||||
return 1;
|
||||
fprintf(stderr, "-- warning: cannot find home directory;"
|
||||
" cannot read ~/.sqliterc\n");
|
||||
return;
|
||||
}
|
||||
sqlite3_initialize();
|
||||
zBuf = sqlite3_mprintf("%s/.sqliterc",home_dir);
|
||||
@@ -4248,11 +4279,10 @@ static int process_sqliterc(
|
||||
if( stdin_is_interactive ){
|
||||
fprintf(stderr,"-- Loading resources from %s\n",sqliterc);
|
||||
}
|
||||
rc = process_input(p,in);
|
||||
process_input(p,in);
|
||||
fclose(in);
|
||||
}
|
||||
sqlite3_free(zBuf);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -4528,10 +4558,7 @@ int main(int argc, char **argv){
|
||||
** is given on the command line, look for a file named ~/.sqliterc and
|
||||
** try to process it.
|
||||
*/
|
||||
rc = process_sqliterc(&data,zInitFile);
|
||||
if( rc>0 ){
|
||||
return rc;
|
||||
}
|
||||
process_sqliterc(&data,zInitFile);
|
||||
|
||||
/* Make a second pass through the command-line argument and set
|
||||
** options. This second pass is delayed until after the initialization
|
||||
|
||||
Reference in New Issue
Block a user