0

I am working towards creating a database template project in eclipse that contains all our SQL script files required for database deployment.

Keeping this in view, i have created a sample Java project in eclipse and added the SQL Development --> SQL files to the project. These SQL files contains a script for creating tables in the database. Now, I tried to clean and build the project to check if there are any build errors but i could not be able to clean and build the project(That contains SQL files) in eclipse.

Can you please let me know what needs to be done in order to clean and build the project (That contains SQL files) ? Also please suggest if a database template project can be created in eclipse?

Note: When i try to build the project it should validate the project to check if there are any errors in the SQL script files. Here i am using PostgreSQL database . Please suggest on what needs to be done

howlger
  • 31,050
  • 11
  • 59
  • 99
Kamal
  • 453
  • 1
  • 10
  • 22
  • Which plug-ins do you have installed for SQL, [SQL Development Tools](http://marketplace.eclipse.org/content/sql-development-tools)? – howlger Dec 27 '17 at 14:04
  • I have using the PostgreSQL for my SQL development – Kamal Dec 28 '17 at 04:28
  • I have using the PostgreSQL database for my SQL development. Will be creating a database project that contains SQL files for creating tables, Views, Functions etc... For this i am using a JAR file 'postgresql-42.1.4.jar'. Please suggest on how to create a database project, clean and build the project and validate errors in eclipse – Kamal Dec 28 '17 at 04:35
  • I am using Dbeaver Plugin for my development purpose. First i tried using the Java and Database Development Perspective but could not find auto completion(Intellisense) feature for PostgreSQL commands. So Installed the Dbeaver plugin but i could not be able to clean and build the project in order to check for errors in any of the SQL file – Kamal Dec 28 '17 at 04:39
  • Make sure you use the _SQL Editor_ (right-click + _Open With > ..._), which [supports autocomplete (Ctrl+Space)](https://dbeaver.jkiss.org/docs/features/#Working_with_SQL). – howlger Dec 28 '17 at 10:27
  • I know about this shortcut key but i found that it does not support most of the PostgreSQL commands. Dbeaver on other hand has the support to autocomplete the SQL command so i started using Dbeaver perspective in eclipse Java Project. But I could not be able to compile the project to check if there are any errors in any of my sql files. For ex. If i have 100 SQL files and few of the SQL files have errors, then it should show the list of files having errors while building the project. Is there any option such that it can be able to clean and build the project that contains the SQL files? – Kamal Dec 28 '17 at 11:06

1 Answers1

0

DBeaver does not have the functionality you're looking for. While it is an Eclipse plugin, it does not function like a traditional Java project where you can clean/build the source files.

The tool mentioned in this answer might be able to help you: https://stackoverflow.com/a/13209943

Point it to your Eclipse workspace directory that contains your script files, e.g.:

$ find ~/eclipse-workspace/General/Scripts/ -name '*.sql' | xargs pgsanity

Edit:

You can set up Eclipse to use pgsanity to "build" your script files and check them for syntax errors (if you're on Linux). I'm using Ubuntu with Eclipse Oxygen and this is how I set it up:

Install pgsanity (via https://github.com/markdrago/pgsanity)

sudo apt-get install libecpg-dev 
sudo apt-get python-pip
sudo pip-install pgsanity

Configure Eclipse

From the menu go to Project -> Properties, select Builders from the left-hand menu and click "New...". Select Program as the builder type and click OK.

Create a new builder with the following options.

Name: pgsanity (or choose your own)
Location: /usr/local/bin/pgsanity
Working directory: ${workspace_loc:${project_path}/Scripts}
Arguments: ${build_files:f}

${workspace_loc:${project_path}/Scripts} will return the absolute path to the Scripts folder in your current project. If you're using the default DBeaver project configuration, you should have a scripts folder.

${build_files:f} returns the set of files that make up this build, which is the files changed or added since the last build.

Eclipse Edit Configuration Window

Build Project

Go to Project -> Build Project. Any syntax errors will be shown in the console. If no errors are shown, no files were selected for build or no files had syntax errors.

enter image description here

Community
  • 1
  • 1
Kyle
  • 415
  • 1
  • 6
  • 11
  • I am using Windows OS... Does pgsanity support windows OS? f so, Please suggest the steps that need to be followed to install the pgsanity. – Kamal Dec 29 '17 at 04:25
  • I can be able to install the pgsanity on my machine that has windows Operating System but when i try to build the project, it got stuck at 28% for about an hour with no progress further . It is showing the message "Building all .....Launching delegate". Can you please let me know what needs to be done in order to fix this? – Kamal Jan 01 '18 at 06:22
  • Sounds like a configuration error. When you edit your build configuration, did you replace "usr/local/bin/pgsanity" with the Windows-style path? E.g. "C:/Program Files/..."? Can you run pgsanity from the command line outside of Eclipse to verify it's working? – Kyle Jan 02 '18 at 17:21
  • Yeah i have replaced the location with that of the path present in my machine only... We need to provide the path of the pgsanity.exe file. right??? if so i have provided the exact path where the pgsanity.exe is resided – Kamal Jan 03 '18 at 12:58
  • Yes. Can you run pgsanity for the command line with a .sql file as the input, e.g. C:\path\to\pgsanity.exe script1.sql ? Verifying it's working is step one. If that works, please provide a screenshot of your "Edit Configuration" window and provide your project directory structure. – Kyle Jan 03 '18 at 14:35
  • I have tried to run the pgsanity.exe as suggested in command prompt. I created a sample SQL file that contains a function definition where it deletes all the data from a particular table. I am getting an error while trying to execute it in command prompt itself – Kamal Jan 04 '18 at 05:19
  • Traceback (most recent call last): File "c:\python27\lib\runpy.py", line 162, in _run_module_as_main "__main__", fname, loader, pkg_name) File "c:\python27\lib\runpy.py", line 72, in _run_code exec code in run_globals File "C:\Python27\Scripts\pgsanity.exe\__main__.py", line 9, in File "c:\python27\lib\site-packages\pgsanity\pgsanity.py", line 71, in main return check_files(config.files, add_semicolon=config.add_semicolon) – Kamal Jan 04 '18 at 05:51
  • Perhaps you could ask for guidance on getting pgsanity working in Windows via the github [Issues page](https://github.com/markdrago/pgsanity/issues). I don't see any information on pgsanity running on Windows, so it may not be the best tool for you. – Kyle Jan 04 '18 at 14:43
  • Yes thats correct and i have already posted a question on their forum on how to install pgsanity on windows and use it in eclipse... Even if i found a work around on installing the pgsanity on windows, it may be a problem for us in the future so dropped the idea of using the pgsanity on windows. Thank you for your suggestions – Kamal Jan 08 '18 at 08:27