executing a .sql file in sql plus terminal - sqlplus

I have written couple of sql scripts in a text file and saved them with a .sql extension. I want to execute these scripts in the sql plus terminal without having to manually type the standalone sql scripts, but i'm struggling with it. If someone could list out the steps involved I would be very grateful.
I could copy and paste those scripts in the terminal but that is not what I am looking at, I want to see if there is a way to provide the path to the scripts in the sql plus editor.

If your filename is myQueries.sql, just type
SQL>#/path/to/my/query/myQueries.sql
SQL>/

Related

Running a lua program from a text file

I've just started learning Lua, and I'm trying to get the native Lua interpreter to run a program that has been saved to a .txt file. I'm running Windows Vista with Lua 5.1.4.
Perhaps I'm missing something, but the only thing my book (Programming in Lua) says is that all you have to do to run your program is to call the interpreter with the name of the text file that contains your program. Then it gives this supposedly handy piece of code:
% lua filename.lua
Which I can't get to work in cmd or in the Lua interpreter. Further research I've done indicates that I might need to use a
dofile("filename.lua")
command, but I'm not sure how to do this. Specifically, what information do I need to put in the argument? Any help you can give is greatly appreciated.
You need to download a Win32 binary (see lua-5.2.1_Win32_bin.zip or lua-5.2.1_Win64_bin.zip here). Unzip this somewhere. How to run your script, in order of easiness and inverse order or common procedure:
Drag your script onto the Lua.exe using the Windows file Explorer.
a. Move your script to the same folder as Lua.exe
b. Shift right-click on that folder and select Open Command Window Here.
c. Type lua filename.lua and press Enter.
Add the directory containing Lua.exe to your system PATH, then do steps 2a and 2b on the folder containing your script.
Integrate Lua.exe with your editor in some way (how you do this depends on your editor).

Prebuild event works in Windows 7, fails in XP

I have a pre build event set up to generate the version/build number to embed in my exe. The event consists of a call to a batch file that does the actual work (a parameter is passed to the batch file). The batch file works as it should on all of the computers I've tried it on, including the Windows XP computers. It also runs fine as a pre build event on the 3 computers here running windows 7. The pre build event fails, however, on Windows XP. Delphi returns an error code that I can't seem to find a reference to anywhere, "20018".
I've tried a number variations to the way I call the batch file without any luck. Does anyone have an idea what's happening?
The build event is as follows:
call "..\..\Build Tools\PreBuild.bat" "$(PROJECTDIR)"
UPDATE:
I've removed the source of the batch file, since it had no relevance for the actual problem.
You gave so little information that I am tempted to vote to close. Instead I will venture a wild guess. You should post the commands in your post-build step.
If you don't know which line is failing, try the first one alone, and remove the rest, and see if that passes.
For example, I often have problems on XP machines using XCOPY commands in post-build steps, and these commands often result in really odd error codes that I am unable to diagnose or determine the meaning of. So if you have an XCOPY command, you should try the XCOPY inside and outside the build environment, and see if it works on that Windows XP box, for example.
You can copy the commands, as they are run, in their macros-expanded form, from the "Output" tab in the Rad Studio IDE, paste them into notepad, run them as a batch file, and try to figure out why they don't work on windows XP.
Here's an example of a workaround, using XCOPY. If this fails on XP, I tweak it till it works:
XCOPY SourceDir DestDir
I have had to fix it this way:
XCOPY.exe SourceDir DestDir
In another case, I found that I had to fix it this way:
call XCOPY SourceDir DestDir
You ALSO mention you are simply running a mysterious batch file and you fail to mention what it does. So let's see, what we could do differently to run a batch file from a post build step.... When I run a batch file like this, I sometimes have problems on XP, like this:
batchfilename.cmd
But when I run it differently, I find it worked on XP, but I lose the command line output:
call batchfilename.cmd
It seemed that something strange was happening when running post-build steps in the IDE, that could be resolved by trying the commands outside the IDE, in various forms.
The number (20018) you mention is a bit of a silly thing to go googling, it's probably the ERRORLEVEL (return value to the command shell) of whatever tool you are running in your batch file. Since you told us nothing about what tools you're running, I wonder if you have even done the basic step of looking at what happens when you run that batch file OUTSIDE the IDE on that XP machine. My guess is that if it didn't come from your own batch file, that it came from deep in the guts of MSBUILD itself, which is something that very few Delphi people will know the source code to (even the Delphi team itself is using a binary from Microsoft to provide MSBUild functionality). I notice that MSBUILD's built in tasks for doing post-build and pre-build steps are an area of the IDE that need improvement, especially when it comes to debugging problems like this. You can however, simply run them outside the IDE and see if they work that way, and you can try stuff, as I have suggested above.
If this is your batch file ... I suggest that due to dependency issues, you might not want to use such a batch file technique to modify an RC file, as it might expose some strange dependency issues in MSBUILD with RAD/Delphi build tasks. I have also seen some weird BRCC32 failures, on XP that I have not been able to reproduce.
Ok, I finally found the answer here:
http://delphi.about.com/od/devutilities/a/pre_post_build.htm
The problem was spaces in the path to the batch file being called. Apparently this isn't a problem in Windows 7.
Removing the space in the build tools directory and changing the pre build event to the following fixed the problem:
call ..\..\BuildTools\PreBuild.bat "$(PROJECTDIR)"
Here's the important bit from the link:
Command Line: This is the trickiest of them all, but after you get one working, they’re all easy. The trick here is not to use quotes on the program’s name but instead use the windows SFN (Short File Name). The reason is that, should you need to use quotes to enclose the path of your file, the IDE gets confused with too many quotes. So, these are the wrong ways of adding that command line above:
C:\Program Files\SoftwarePassport\Armadillo.exe D:\Dev\My Prog\Prot.arm /P
"C:\Program Files\SoftwarePassport\Armadillo.exe" D:\Dev\My Prog\Prot.arm /P
C:\Program Files\SoftwarePassport\Armadillo.exe "D:\Dev\My Prog\Prot.arm" /P
"C:\Program Files\SoftwarePassport\Armadillo.exe" "D:\Dev\My Prog\Prot.arm" /P
This last one should work, if it were not for the IDE to be confused with it. So, what does work is either of these:
C:\Progra~1\Softwa~1\Armadillo.exe "D:\Dev\My Prog\Prot.arm" /P
C:\Progra~1\SoftwarePassport\Armadillo.exe "D:\Dev\My Prog\Prot.arm" /P

F# Interactive Developement DirectoryNotFoundException: Could not find a part of the path 'C:\Users\Bob\AppData\Local\Temp\MyFolder\'

When using F# interactive apparently this line of code will search in the path shown in the subject line.
let files = Directory.GetFiles("MyFolderPath")
Is there any way to set interactive to search the same folder the current fsx file is running from? Or any way to control this behavior at all? I'm used to the search starting in bin\Debug obviously and this behavior is throwing me off.
Thanks in advance,
Bob
It depends from where the process fsi.exe is started. Fsi is separated from the IDE, it doesn't know which file is open. When you run Visual Studio, the current directory for fsi is the temp folder.
If you run the fsx file (fsi foo.fsx or right-click "Run with F# Interactive"), fsi will run from current directory.
To see where you are (in which directory), you can do:
Directory.GetCurrentDirectory()
To change directory, use this command:
Directory.SetCurrentDirectory(...)
F# interactive is completely independent of the current F# program (in fact, think of it as running in a separate CMD shell). So I'm afraid, there won't be a simple way to get the currently opened .fsx file.
You might be able to pull something from fsi.CommandLineArgs but I have no VS at hand to confirm this.

How to invoke PascalScripts UnitImporter from command line

I want to know if there is a way to start the PSUnitImporter.exe from command line. What I want to do is to have the import file created automatically as a Pre-Build Event.
So far I have found out that when running PSUnitImporter.exe "C:\folder\source.pas" it will invoke the Importer gui and automatically load the file. It will not do the conversion though and it shows the GUI which I don't want.
The gui itself isn't capable of doing that, however the source for the program is in svn at pascalscript project page. A few slight changes there will let you do what you want.
Thanks to CK who pointed me to the pascalscript projet page. I checked out the sourcecode there and found out that it already includes a project for a Commandline importer.
All I needed to do is compile this project and I was done. I wonder why this "CMDimp.exe" is not included in the Pascralscript setup.

Is it possible to write a script to easily deploy clr stored procedures?

I would like to include CLR stored procedure deployment in our deployment script (powershell at the moment), however I can't figure out a nice way to do this automatically.
I would have thought there would be a nice command line option to do the same as right-click deploy in Visual studio
Well, PowerShell itself won't give you much in the way of extra help. You don't mention which version of SQL, so I'll be a bit generic.
Really, all you need to do is have your script file copy the necessary DLLs for your CLR stored procs - PowerShell can copy files like a maniac, so no problem there. Then you need to execute the CREATE ASSEMBLY statement in SQL. PowerShell natively cannot help with this. If you're using SQL 2008, your script can Add-PSSnapin the SQL cmdlet provider, which will give you a cmdlet capable of executing SQL queries - so that gets you your CREATE statement.
If you don't have 2008, you'll have to write a short .NET routine to create a SqlConnection and SqlCommand - not difficult, and entirely possibly in PowerShell.
Next, use the same technique to execute your CREATE PROC statement to actually create the stored proc using the aforementioned assembly.
Zat help? Pity there's nothing more automated, true. MS hasn't spent a lot of brainpower simplifying complex SQL deployment stuff of this nature, I don't think, and CLR stuff adds a bit of extra spice since you have to make the assembly available.
One can use techniques described at http://msdn.microsoft.com/en-us/library/ms345099.aspx to generate deployment script from SSMS. At least this addresses the tedious part of generating a ton of CREATE PROCEDURE statements.
The SQL Server Publishing Wizard can script CLR stored procs as text. Looks like it converts the binary source of CLR stored procs as some kind of hex encoded text.

Resources