I am new to SQLite3.
I am trying to create a DB in the shell. When I run the shell, it already shows:
SQLite version 3..
Enter ".help" for instructions ..
Enter SQL...
Enter SQL statements terminated with a ";"
I read somewhere that I should be able to type "$" and codes like "$ sqlite3 mynotes.db"
Now, I need to be able to name my DB (like "mynotes.db") and be able to decide in which folder I want it to be saved.
Can someone help me? Cheers!
The $ somewhere was supposed to be a prompt of some shell (command processor), where you start sqlite3 and specify database name (which is created if does not exists).
If you're running sqlite3 without a shell (by clicking on sqlite3.exe?), it's time to try another way. CMD.EXE on Windows is as good for this job as a typical Unix shell.
As of the folder where the database will be: either cd to this folder before you run sqlite3 mynotes.db, or specify full pathname to the database: sqlite3 "C:\Users\Me\Documents and Settings\mynotes.db" (double quotes are needed when argument contains spaces).
When sqlite3 is started with no parameters, the database will be in memory. Sqlite3 supports "attaching" other databases (see ATTACH DATABASE description). This way, you can create and open on-disks databases even if starting sqlite3 with parameters is impossible for some reason (or too hard).
Related
I am trying to run a simple query on many servers. I know 100% that the file and directory in question exist.
I can do simple commands, such as ls, pwd, whoami, etc, and I can run the sqlite command on the remote host itself.
The playbook task:
- name: Do a test SELECT statement
become: yes
become_user: root
command: sqlite3 /usr/local/share/sqlite/dbfile.sqlite3 "SELECT * FROM db WHERE hostname="{{ db_server_prompt }}""
register: query_result
- debug: var=query_result.stdout_lines
The error I'm receiving is "msg": "[Errno 2] No such file or directory: b'sqlite3'",.
Is there something wrong with my syntax? Why is it telling me there's "No such file or directory" when using the sqlite3 command? I've tried the absolute path to the executable (/usr/bin/sqlite3), but I get the same error.
I tried to use chdir as an argument per this answer, but I get Unable to change directory before execution. None of these things are working. I would really like to use Ansible, since there are 20+ servers where this is needed.
Update I can run it as an adhoc command:
ansible sqlite_servers_test -m command -a "sqlite3 /usr/local/share/sqlite/dbfile.sqlite3 "SELECT * FROM db_pool WHERE hostname=myhostname" "
What is the difference in trying to run it via a playbook?
If you are working with window and do not want to install sqlite3 permanently (in my case, I just want to update some table fields of *.db sqlite file stored in window, do not want to install sqlite3 at the window), I downloaded sqlite3.exe and copy to window to execute my ansible. After that sqlite3 is deleted from window.
Download link.
Sample code.
I am trying to execute a simple db2 command in Linux command prompt. but Linux command prompt is not recognizing the command it is giving - bash db2 command not found. but db2 is installed in the Linux machine.
command I am trying to execute from Linux command line processor is db2 "create database smaple"
Error I am getting is below "If db2 in not a typo you can run the following command to lookup the package that contains the binary" command-not-found db2 -bash: db2: command not found"
Is this because of environment variable problem ?? or there is only one instance of db2 ie db2inst1 is running in the machine.my user name in appsusr and db2 instance name is db2inst1 are different is this causing problem?? and I am not having super user access.Is this is causing any problem?? do I need super user access is required ??
Just type, echo $PATH in your command prompt , where you can see all the exported paths in your system.
If the db2 path is not found in your environment variable list, then do the following.
export PATH=$PATH:/opt/IBM/db2/V10.1/bin
and then press enter.
I hope this will resolve your issue.
On Linux and UNIX DB2 platforms, the proper way to set your environment variables to run DB2 commands is to source the sqllib/db2profile script belonging to the local DB2 instance owner. That will set not only your PATH but also other important variables that DB2 requires.
In your case, the instance is owned by the db2inst1 user, so your login startup file or batch script should run this command:
. ~db2inst1/sqllib/db2profile
The leading dot is necessary to set the variables in your current shell process, not the sub-process that quickly vanishes after db2profile finishes.
It's more than likely that, if DB2 is installed, it's simply not in your path.
Your path should contain something like:
/opt/IBM/db2/V10.1/bin
which is where the executables live (depending on which version you're running).
Changing your path will probably entail changes to one of the startup files, such as .bashrc or .bash_profile.
I downloaded the binaries for windos for sqlite and extracted them. There were three files
a shell
dll
analyzer
when I try to run to create a database and a table from the sqlite shell i get....
SQLite version 3.7.8 2011-09-19 14:49:19
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> sqlite3 test.db
...> create table tbl1(one varchar(10), two smallint);
Error: near "sqlite3": syntax error
sqlite>
when I try to run to create a database and a table from the command line(Vista) shell I get....
Microsoft Windows [Version 6.0.6000]
Copyright (c) 2006 Microsoft Corporation. All rights reserved.
C:\Users\codenamejupiterx>sqlite3 test.db
'sqlite3' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\codenamejupiterx>
does anyone have any ideas?????
There is no "installation".
The error is that "sqlite3.exe" was not found in the search path as defined by the (Windows) PATH environment variable. Either add it to %PATH% (see How do I set or change the PATH system variable?) or use a complete file qualification that does not rely on %PATH%. A fully qualified invocation may look like:
C:\path\to\sqlite\sqlite3.exe test.db
Running sqlite3 by "double clicking" the executable in Windows Explorer is the same as above [as it uses an absolute path to run the sqlite3 executable] -- albeit without the ability to specify the database name or other options. (These can be specified in a "shortcut" to sqlite3, if desired.)
Happy coding.
You run the command sqlite3 test.db to start the sqlite shell. (your first example) From in there, you do not need that part of the command again, just issue the "create table " command.
I think you need this:
SQLite-1.0.66.0-setup.exe And sqliteadmin to open sqlite database
Regards
I have my sqlite3.exe file in C:\ and i want to create an sqlite database in C:\db\sqlite.I have tried sqlite3 ex1 as suggested on the docs http://www.sqlite.org/sqlite.html but i get the error Error Near "sqlite3".
What is the correct way of creating a new database from the shell?.
Here is one way to use SQLite3 from the command prompt in Windows.
First you need to know the path to the folder where you installed the SQLite ODBC Driver. If you used the default settings this would be C:\Program Files\SQLite ODBC Driver on Windows XP
Go to Start -> Run -> type cmd -> click OK
This opens the command prompt.
In the Shell, type in the following command. You can use Alt + Space if you prefer to use cut and paste. Remember to modify the path for your setup if you installed SQLite in another folder.
cd C:\Program Files\SQLite ODBC Driver
This brings you to the SQLite install folder. Now you are ready to call SQLite. Type the following command at the SQLite prompt.
sqlite3
This opens the File menu where you can choose a database to connect to, or create a new database file.
Navigate to C:\db\sqlite and create myDatabase.db, and click Open to close the file menu.
Now you are ready to work on your new database, run your queries, e.g. create a table.
As new file is created in current directory, for creating file at different location you should follow this format:
eg. for storing file FILENAME.db at c:/users/xyz/abc
you should type
sqlite>.open c:/users/xyz/abc/FILENAME.db
and then press enter a new file will be created at the mentioned path.
and now when you will type .databases you will see your file listed in the list of databases.
You can use following command to create the sqlite database
.open databasename.db
or
.open c:/somefolder/databasename.db
I use the command line sqlite3 executable to check queries I make from my code.
Is there a way to read in pragma statements or other session setup (".mode csv" for example) when the executable starts up?
I know I can do a ".read " once I'm in, but that's tedious.
Put a .sqliterc file in your home directory with
the commands you want executed each time you start
the sqlite3 command line tool.
Unix and Linux use ~/.sqliterc; Windows tries to find the
location of .sqliterc using the environment variables
USERPROFILE HOME HOMEDRIVE and HOMEPATH.