FAQs - ApexSQL Code
General
|
What do these check boxes do?
|

Use these controls to set the values for these ApexSQL Code object model properties:
These properties don't "do anything" on their own but you can use them in a template to make a programmatic decision. For example you can write one template to create Insert, Execute, Update, Delete and Select Procedures but embed checks for "if Code.Operations.DoDelete = True then ..." to see if the user wants to output the Delete. He/she might want to only create Insert procedures. This way you can avoid writing 4 separate templates each for a different procedure type.
Since this is such a common occurrence it was decided to feature these controls prominently on the interface.
|
What languages does ApexSQL Code support?
|
ApexSQL Code supports ANY language used with SQL server, non languages like Documentation (just text) and SQL itself.
ApexSQL Code has built in support for .NET Data Type mapping.
Language syntax definitions exist for the following languages:
Visual Basic
ASP / VBScript
Java / Javascript
HTML
Pascal
Perl
PHP
C#
SQL
VBScript
XML
VB.NET
Documentation (all black text)
|
Is the 2005 version of ApexSQL Code backwards compatible with SQL Server 2000?
|
Yes. ApexSQL Code works seamlessly with all supported SQL Server versions.
|
What does the Save Selection command save?
|
Save Selection saves the state of IsChecked property (state of check boxes) and the value of Alias property for objects that are displayed in Schema Explorer.
Templates
|
I have looked through all of the templates but did not find one that suited my needs exactly - what can I do?
|
Write it yourself! ApexSQL Code is built to allow users to create their own templates vs being an out of the box canned code generation tool. The power of ApexSQL Code is providing a value added environment to allow developers to create their own templates as easily as possible.
|
Wow - these templates look complex - how can I learn to write these myself?
|
Actually ApexSQL Code templates are easy to write for a couple of reasons:
IntelliPrompt: IntelliPrompt built into the ApexSQL Code Template editor itself allows you to walk down the object model without referring to the documentation. You can select from a choice of properties that ApexSQL Code serves up to you automatically.
Powerful error handling: ApexSQL Code will handle compile-time errors and to display the EXACT line of code where the bad line of code exists. To point to the template source code, set Use Line Pragmas option in the Options dialog.
Popular .Net Languages: Templates can be written in one of the two most popular .Net languages - Visual Basic .Net or C#.
Good Support: If you have any problem or questions you can post them on the ApexSQL Support Forum and get timely responses and free support.
|
I would like to create a new template - where do I begin?
|
A good place to start is to take an existing template and modify it somewhat to suit your needs. You can also use the Template Wizard to walk through the steps of template creation.
|
Do you have any examples of how to write templates?
|
A variety of example templates are included in the installation. Every template that begins with "Example" is an example template that illustrates a variety of objects, collections and concepts. Look for these templates in the Application Directory, Templates/v2005.10/Examples folder.
But there are many other templates as well that show real world code generation examples in ASP, C#, SQL and other languages. You just need to explore Templates/v2005.10 in the Template Explorer panel.
|
Does ApexSQL Code have any built in templates?
|
Yes, the ApexSQL Code installation includes lines of pre-written templates that cover Visual Basic, VB.NET, C#, SQL, Delphi and ASP. These are installed in the installation of the application.
Output
|
Can I output to single file instead of multiple files like when building a large SQL Script?
|
Yes - set the FileOutputMode property in the Template Property panel to SingleFile / MultiFile and it will write all template output to one file for all the Checked objects.
|
How can I control how the created files are named?
|
You can set default file naming templates in the Options form using tags such as {Server}, {Type} and so on. For example, {Type}_{Owner}_{Name} will result in a code generated off the stored procedure byroyalty being called "procedure_dbo_byroyalty.sql".
If you append to a single file tags like {Type} and {Database} might be more appropriate, for example, {Database}_{Type} would render to "Northwind_Procedures.sql".
Also you can define filename template in template’s property OutputFileName or redefine it on File Output dialog.
|
How do I set the File Extension of my generated files?
|
The file extension is determined by the mapping in Options - File Extension and associated with the selected Language for the template. So if C# is chosen then the file extension will be .cs or whatever the file extension for C# is changed to in this Option tab. This is customizable by the user.
Template Editor & Programming
|
I have a question on VB.NET or C#?
|
|
How do I get the IntelliPrompt to show?
|
Simply type Code. and you can start the object model from the top and begin to walk down through it.

Make sure the Enable IntelliPrompt checkbox is checked.
|
What are the code delimiters?
|
- <%
code %>
- defines code area to be processed
- <%=
expression %>
- expression to evaluate at runtime. It is equal to:
<%
Out.Write(expression) %>
for VB.Net
or
<%
Out.Write(expression); %>
for C#
- <%#
custom_class_members %>
- code declaration (in term of C#/VB.NET – class members), allows you
defining the custom class members (functions/procedures/variables).
|
How can I get more control over how output files are written?
|
Use the standard .Net classes to do your file processing instead of ApexSQL Code. Set the File Output Mode property in Template Property Page to Suppress and this will tell ApexSQL Code to suppress any File I/O operations allowing you to assume complete control.
Use Example_FileWriting.ptpx as an example of how to do this
|
Does ApexSQL Code offer support for multiple Include files?
|
Yes, ApexSQL Code supports unlimited count of the Include files.
|
Can I instantiate objects from other assemblies in my ApexSQL Code templates?
|
Yes, first you should define you assemblies in the Import Assemblies property of a template and declare needed namespaces in the Import Namespaces property. Then you can instantiate your objects from the imported assemblies.
|
How can I prevent ASP.NET tags from confusing my templates?
|
Use <%% instead of <%
in template.
|
How can I output messages to the Debug output window?
|
Use System.Diagnostics.Debug or System.Diagnostics.Trace classes from .Net Framework. To use System.Diagnostics.Debug please ensure that Generate Debug Info option is checked (Options dialog -> Processing tab). For example:
VB.Net
<%
Debug.WriteLine("My Debug Message!!!")
%>
C#
<%
Debug.WriteLine("My Debug Message!!!");
%>
See also the Example_Tracing.ptpx template.
|
How can I declare a constant in my template?
|
Use code declaration delimiter and define it as you are writing in the class scope.
VB.Net
<%#
Private Const MyConstant As String = "constant"
%>
C#
<%#
private const string MyConstant = "constant";
%>
|
How can I add custom properties?
|
It is described in the help file: Templates -> Template Properties topic.
|
How do I change an Alias for an Object?
|
Find the Alias property in the Schema Browser Property Page. By default an alias value is the object name. This property is editable and you can overwrite that.
|
How can I obtain the Custom Properties values in the template?
|
Custom Properties are accessible as members of your template. You just need to type the Custom Property name for accessing. For example, to obtain a value of the custom property MyCustomProperty of a string type you should write <%string
customPropertyValue = MyCustomProperty%>.
|
How do I put quote mark (") into the Out.WriteLine method?
|
- In VB.NET you should
use a sequence of two double-quote characters ( "" ).
Out.WriteLine("""")
' This prints out: "
- In C# you should use
an escape sequence \".
Out.WriteLine("\"");
// This prints out: "
|
Can I create a new object instance, something like this: DbObject obj = new DbObject(PrimaryKey) and then read the primary key values?
|
No, this is data-oriented approach, but our ApexSQL Code model is structure-oriented and it is not applicable for the described task.
|
Help is displayed that TablesCollection.Item property accept both index or table name, but if I pass the index all is fine, while if I pass between parenthesis and quote a table name, while executing the code, the Code return me error. What am I doing wrong?
|
To get a Table from Code.Database.Tables by name, you should pass a qualified name of table as a parameter:
currentTable
= Code.Database.Tables("[dbo].[Employees]")
|
How to determine a value of the default bound to a column?
|
To determine, whether a particular column
has an associated default value, you should check a value of Column.SQLDefault
property. If Column.SQLDefault
is not null (Nothing in VB), the Column.SQLDefault.TextBody
property contains an expression of the bound Default and the Column.SQLDefault.Name
contains a name of expression of the bound Default. This is shown in Example_Column.ptpx
template. Below there is a sample (c - Column object):
If c.SQLDefault.Name IsNot Nothing Then
Out.WriteLine("Default Name:"
& vbTab & c.SQLDefault.Name)
Out.WriteLine("Text body:" &
c.SQLDefault.TextBody)
End If