0

I am trying to start out using Notepad++ to run SQLite commands. I have tried following two brief YouTube tutorials to get me going. I can run the initial .bat file, but still cannot run the .sql file.

I have a Windows system environment Path variable set to the folder containing sqlite3.exe

"C:\Users\Adam\sqlite\"

I have saved the following file RunSQLite.bat in the folder containing sqlite3.exe

sqlite3.exe testDB.db

I have created a second file queries.sql

SELECT 34;

When I try to run queries.sql from Notepad++, using the RUN command:

C:\Users\Adam\sqlite\RunSQLite.bat "$(FULL_CURRENT_PATH)"

the only file that appears to run is RunSQLite.bat, giving the output:

SQLite version 3.36.0 2021-06-18 18:36:39 Enter ".help" for usage hints. sqlite>

Can anyone tell where I have gone wrong?

Thanks in advance.

aphopk

4
  • Seems you need to pipe in the SQL, per the manpage Commented Nov 27, 2021 at 5:02
  • Thanks @hd1. Could you please elaborate? My understanding is that the RUN command initiated from the queries.sql dialogue in Notepad++ should call RunSQLite.bat which will execute sqlite3.exe. Then the "$FULL_CURRENT_PATH" component of the RUN command should run through the commands contained in queries.sql . This would be in accordance with the "sqlite3 [options] [databasefile] [SQL]" format outlined in the man page. Commented Nov 27, 2021 at 5:24
  • I'm not a windows user, sorry, @AdamHopkins Commented Nov 27, 2021 at 5:25
  • @hd1 no prob. thanks for looking it over, regardless Commented Nov 27, 2021 at 6:20

2 Answers 2

1

This C:\Users\Adam\sqlite\RunSQLite.bat "$(FULL_CURRENT_PATH)" will do exactly the same thing if run at the shell. RunSQLite.bat does not take any arguments so the Run command in npp is working as expected.

sqlite3 takes input from an external file with the .read command.

Path issues notwithstanding a bat file something like this should accomplish the task:

sqlite3.exe testDB.db ".read %1"
Sign up to request clarification or add additional context in comments.

1 Comment

Fantastic. Thanks you!
0

Notepad++ is a text editor, so you can now use it to edit your SQL file. After selecting the Language > SQL, Notepad++ will highlight SQL syntax as you type. Try typing some SQL, like

SELECT "Hi"; SELECT * FROM mydatabase WHERE id LIKE 'ID%'; You will see color, bold, and other possible formatting applied to the text you type. If you save the file as something.sql, and then load something.sql in your SQL client, the client will run the SQL commands from that file. If you have an existing somethingElse.sql file, you can open it in Notepad++, which will auto-recognize that it’s SQL and apply the syntax highlighting, allowing you to edit it and save it.

By using the Run > Run dialog, you can run an arbitrary command. For example, if your SQL client has a command-line mode accessed thru sqlclient.exe, you could type

c:\path\to\sqlclient.exe $(FILE_NAME) If you just run it, that probably won’t show you any results… but if you ran

cmd /k c:\path\to\sqlclient.exe $(FILE_NAME) It will open a new cmd.exe Windows command prompt, and show the output from that file.

If instead of running, you hit “SAVE”, you can give it a name (which will end up later in the Run menu), and/or a keyboard shortcut, so that you can easily re-use that many times.

If you want to do something more fancy, use the NppExec plugin, which includes a better batch/scripting language. Once again, you can save the NppExec script, and make it show up in the Macro menu.

If Python is a programming language you know or could learn (or if, like me, you know enough other programming languages that you can fake the Python), then the Python Script plugin will allow you to do even fancier stuff. (Python is a complete programming language, and has many libraries written, which could act as an interface between your SQL source file and your database engine; PythonScript has access to a full python2.7 interpreter. For example, you could write a script in Python which executes the commands from your SQL, grabs the results from your database engine, and displays them in Notepad++, either inline with your original SQL code, or in a new text document. You are really limited only by your imagination and knowledge of Python.)

2 Comments

Thanks @suhdir. The RUN examples that you have provided incur the same problem. The process runs RunSQLite.bat, but does not then run queries.sql. What I would ultimately like to do is start an instance of sqlite3.exe running using RunSQLite.bat and then, using the separate file queries.sql have a series of commands that populate a database with tables and run queries. I would like these to run from Notepad++. It seems a straightforward proposition from the tutorials, only that I can't get it to work.
python2.7 is deprecrated, per pep0373. The good news is the sqlite3 module survived.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.