开发者

Avoid message "-​- Loading resources from .sqliterc"

Minor problem, nevertheless irritating : Is there a way to avoid the following messa开发者_C百科ge from appearing each time I make a query :

-- Loading resources from /Users/ThG/.sqliterc


As a stupid workaround, this works:

<. sqlite your_sqlite.db 'select * from your_table'

This is because the current code does this:

 if( stdin_is_interactive ){
   utf8_printf(stderr,"-- Loading resources from %s\n",sqliterc);
 }

Forcing a stdin redirect thwarts this due to this piece of code:

stdin_is_interactive = isatty(0);

This works as well:

sqlite -batch your_sqlite.db 'select * from your_table'

due to this piece of code:

}else if( strcmp(z,"-batch")==0 ){
  /* Need to check for batch mode here to so we can avoid printing
  ** informational messages (like from process_sqliterc) before
  ** we do the actual processing of arguments later in a second pass.
  */
  stdin_is_interactive = 0;
}

but it's longer, so kind of defeats the purpose.


I know that this question is PRETTY old now, but simply deleting '/Users/ThG/.sqliterc' should solve the problem. '.sqliterc' is a configuration file for sqlite's interactive command line front-end. If you don't spend a lot of time in there, you won't miss the file.


That resource msg comes out on stderr, and it's followed by a blank line, so you could get rid of it with something like this (wrapped up in a script file of its own):

#!/bin/bash
sqlite3 -init /your/init/file /your/sqlite3/file.db "
    your
    SQL
    cmds
" 2>/dev/null | sed -e1d


When using sqlite in shell scripts, you usually don't even want your ~/.sqliterc to be loaded at all. This works well for me:

sqlite3 -init <(echo)

Explanation:

  • -init specifies the file to load instead of ~/.sqliterc.
  • <(echo) uses Process Substitution to provide a path to a temporary empty file.


A bit late but @levant pied almost had the solution, you need to pass an additional -interactive to silence the --loading resources from.

$ sqlite3 -batch -interactive
SQLite version 3.31.1 2020-01-27 19:55:54
Enter ".help" for usage hints.
sqlite> .q


You can simply rename your config file to disable the warning. And revert the rename to keep the configuration after use.

I use the following:

#suppress default configuration warnings
mv $HOME/.sqliterc $HOME/.backup.sqliterc 

# sqlite3 scripts...

#revert
mv $HOME/.backup.sqliterc $HOME/.sqliterc
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜