You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Finn Smith <fs...@nntllc.com> on 2001/06/13 22:43:47 UTC

templates/sql/base/mssql/*.vm fix

> On 6/13/01 10:29 AM, "Jeb Boniakowski" <jb...@nntllc.com> wrote:
>
> > I'm trying to set up Turbine to work with MSSQL Server 7.  I think I'm
> > having the same problem Hervé Guidetti posted about on Jun 6 when using
> > Postgres, according to the archives.  ant gives up trying to do target
> > "project-sql" because an exception was thrown that looks like this:
> >
> >> /.../build.xml:152: Exception thrown by
> >> 'generator.parse'. For more information consult the velocity log.
> >
> > ....and so on
> >
> > and velocity.log looks like this:
> >
> >> Wed...[error] Method chop threw exception for reference $strings in
> > template >sql/base/mssql/table.vm at  [14,26]
> >> Wed...[error] Method parse threw exception for reference
> >> $generator in template sql/base/Control.vm at  [17,17]
> >
> > Hervé was using 2.1b4, I'm using 2.1.  Jason van Zyl said that this
error
> > was due to a problem with postgres' table.vm, but that Eric Dobbs had
> > checked in a fix and that it was fixed in 2.1.
> >
> > Does anyone know if there could be a similar problem with mssql's
table.vm?
> > Or have any other ideas what is causing this to happen?
>
> If you know MSSQL than you can probably tell us. Here's a link to the
> torque templates that are in CVS. If there are problems with them
> let us know.
>
>
http://jakarta.apache.org/cvsweb/index.cgi/jakarta-turbine/conf/torque/templ
ates/sql/base/mssql/


After a lot of reading I:
(a) know a lot more about ant, torque, texen and velocity
(b) found the error in the template files that is causing this crash

Here's the diff of mssql/unique.vm to fix the problem <g>:
3a4
>

Explanation:
line 11 of mssql/table.vm stores the string in the $unique variable:

    #set ( $unique = $generator.parse("$basepath/unique.vm", "", "table",
$tbl) )

line 14 of mssql/table.vm then takes that string, if it's empty it ignores
it, if not it chops off the trailing comma & space:

    #if($unique.length()>0)$strings.chop($unique,2)#end

mssql/unique.vm has only three lines of code:

#foreach ($unique in $table.Unices)
    UNIQUE ($unique.ColumnList),
#end

if there are no elements in $table.Unices when unique.vm is parsed at line
11 of mssql/table.vm the expectation is that it will evaluate to an empty
string. However, due to the fact that there is a blank line after the
#foreach ... #end loop in mssql/unique.vm it evaluates to a one character
string. Then when the check is performed in line 14 of mssql/table.vm the
length is greater than 0, but causes an array out of bounds exception when
chop tries to take 2 characters off the end.

Changing 0 to 1 and 2 to 3 in line 14 of mssql/table.vm fixes this as well,
but just deleting the extra line in mssql/unique.vm keeps the comparison
code in line 14 consistent with other *.vm files. It seems to me, however,
that there are several other places in the *.vm files where these types of
comparisons (if length > 0 then chop two chars) occur and that having some
sort of check and error message for the length == 1 case would be a good
idea. I don't really know Velocity. Maybe someone else would know the best
way to implement this.

It would also be nice if the build.properties file listed mssql as a choice
for the database variable. As it stands, it's not mentioned in the comments
and you have to sift through and understand the directory structure to
realize you can use it.

Should I be posting this to turbine-dev in the hopes that some committer can
change the mssql/unique.vm file and make the if statements more rigorous in
the entire templates/sql/base/*/*.vm tree?

-Finn


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org