Skip to content

Commit

Permalink
Implemented 0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
cnfree committed Jul 2, 2018
1 parent bd67573 commit ee7ea5b
Show file tree
Hide file tree
Showing 16 changed files with 143 additions and 111 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Compiled class file
*.class
bin/

META-INF/
.settings/
.*

# Log file
*.log
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.gudusoft</groupId>
<artifactId>sqlfrog</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.2-SNAPSHOT</version>
<name>sqlfrog</name>
<url>http://maven.apache.org</url>
<properties>
Expand Down
13 changes: 13 additions & 0 deletions release.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,16 @@
* Implement bi-directional transformations between mssql join and oracle join.
* Implement bi-directional transformations between oracle data type and mssql data type.
* Implement bi-directional transformations between mssql identifier, mysql identifier and ansi identifier.

## 0.0.2
Implement ANSI SQL compatible checker: copying structure.
Implement ANSI SQL compatible checker: Inserting several rows at a time.
Implement ANSI SQL compatible checker: SQL functions CHARACTER_LENGTH.
Implement ANSI SQL compatible checker: SUBSTRING.
Implement ANSI SQL compatible checker: TRIM.
Implement ANSI SQL compatible checker: LOCALTIMESTAMP.
Implement ANSI SQL compatible checker: Concatenation.
Implement ANSI SQL compatible checker: Automatic key generation.
Implement ANSI SQL compatible checker: Character-data-types.
Implement ANSI SQL compatible checker: Oracle proprietary join syntax.
Implement ANSI SQL compatible checker: SQL Server proprietary join.
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,27 @@ protected abstract ConvertInfo convert( DataType dataType,
EDbVendor targetVendor, boolean convert ) throws ConvertException;

protected ConvertInfo generateConvertInfo( TTypeName dataType,
EDbVendor targetVendor )
EDbVendor targetVendor, boolean convert )
{
ConvertInfo info = new ConvertInfo( );
info.setInfo( "Can convert the "
+ SQLUtil.getVendorName( dataType.getStartToken( )
.getDbvendor( ) )
+ " data type "
+ dataType.toString( )
+ " to "
+ SQLUtil.getVendorName( targetVendor )
+ " automatically." );
info.setPosition( new Tuple<Long>( dataType.getLineNo( ),
dataType.getColumnNo( ) ) );
String filePath = dataType.getStartToken( ).container.getGsqlparser( )
.getSqlfilename( );
if ( !SQLUtil.isEmpty( filePath ) )
if ( convert )
{
info.setFilePath( filePath );
info.setInfo( "Can convert the "
+ SQLUtil.getVendorName( dataType.getStartToken( )
.getDbvendor( ) )
+ " data type "
+ dataType.toString( )
+ " to "
+ SQLUtil.getVendorName( targetVendor )
+ " automatically." );
info.setPosition( new Tuple<Long>( dataType.getLineNo( ),
dataType.getColumnNo( ) ) );
String filePath = dataType.getStartToken( ).container.getGsqlparser( )
.getSqlfilename( );
if ( !SQLUtil.isEmpty( filePath ) )
{
info.setFilePath( filePath );
}
}
return info;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ protected ConvertInfo convert( DataType dataType, EDbVendor targetVendor,
throw generateConvertException( typeName, targetVendor );
}

ConvertInfo info = generateConvertInfo( typeName, targetVendor );
ConvertInfo info = generateConvertInfo( typeName,
targetVendor,
convert );
switch ( typeName.getDataType( ) )
{
case character_t :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ protected ConvertInfo convert( DataType dataType, EDbVendor targetVendor,
throw generateConvertException( typeName, targetVendor );
}

ConvertInfo info = generateConvertInfo( typeName, targetVendor );
ConvertInfo info = generateConvertInfo( typeName,
targetVendor,
convert );
switch ( typeName.getDataType( ) )
{
case character_t :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ protected ConvertInfo convert( DataType dataType, EDbVendor targetVendor,
throw generateConvertException( typeName, targetVendor );
}

ConvertInfo info = generateConvertInfo( typeName, targetVendor );
ConvertInfo info = generateConvertInfo( typeName,
targetVendor,
convert );
switch ( typeName.getDataType( ) )
{
case character_t :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
package com.gudusoft.sqlfrog.converter.function;

import gudusoft.gsqlparser.EDbVendor;
import gudusoft.gsqlparser.nodes.TFunctionCall;

import com.gudusoft.sqlfrog.converter.FunctionConverter;
import com.gudusoft.sqlfrog.converter.exception.ConvertException;
import com.gudusoft.sqlfrog.model.ConvertInfo;
import com.gudusoft.sqlfrog.model.Function;
import com.gudusoft.sqlfrog.model.Tuple;
import com.gudusoft.sqlfrog.util.SQLUtil;

public abstract class AbstractFunctionConverter implements FunctionConverter
{
Expand All @@ -31,49 +28,49 @@ public void convert( Function function, EDbVendor targetVendor )
protected abstract ConvertInfo convert( Function function,
EDbVendor targetVendor, boolean convert ) throws ConvertException;

protected ConvertInfo generateConvertInfo( TFunctionCall function,
EDbVendor targetVendor )
{
ConvertInfo info = new ConvertInfo( );
info.setInfo( "Can convert the "
+ SQLUtil.getVendorName( function.getStartToken( )
.getDbvendor( ) )
+ " function "
+ function.toString( )
+ " to "
+ SQLUtil.getVendorName( targetVendor )
+ " automatically." );
info.setPosition( new Tuple<Long>( function.getLineNo( ),
function.getColumnNo( ) ) );
String filePath = function.getStartToken( ).container.getGsqlparser( )
.getSqlfilename( );
if ( !SQLUtil.isEmpty( filePath ) )
{
info.setFilePath( filePath );
}
return info;
}

protected ConvertInfo generateScanInfo( TFunctionCall function,
EDbVendor targetVendor )
{
ConvertInfo info = new ConvertInfo( );
info.setInfo( "Can convert the "
+ SQLUtil.getVendorName( function.getStartToken( )
.getDbvendor( ) )
+ " function "
+ function.toString( )
+ " to "
+ SQLUtil.getVendorName( targetVendor )
+ " automatically." );
info.setPosition( new Tuple<Long>( function.getLineNo( ),
function.getColumnNo( ) ) );
String filePath = function.getStartToken( ).container.getGsqlparser( )
.getSqlfilename( );
if ( !SQLUtil.isEmpty( filePath ) )
{
info.setFilePath( filePath );
}
return info;
}
// protected ConvertInfo generateConvertInfo( TFunctionCall function,
// EDbVendor targetVendor )
// {
// ConvertInfo info = new ConvertInfo( );
// info.setInfo( "Can convert the "
// + SQLUtil.getVendorName( function.getStartToken( )
// .getDbvendor( ) )
// + " function "
// + function.toString( )
// + " to "
// + SQLUtil.getVendorName( targetVendor )
// + " automatically." );
// info.setPosition( new Tuple<Long>( function.getLineNo( ),
// function.getColumnNo( ) ) );
// String filePath = function.getStartToken( ).container.getGsqlparser( )
// .getSqlfilename( );
// if ( !SQLUtil.isEmpty( filePath ) )
// {
// info.setFilePath( filePath );
// }
// return info;
// }
//
// protected ConvertInfo generateScanInfo( TFunctionCall function,
// EDbVendor targetVendor )
// {
// ConvertInfo info = new ConvertInfo( );
// info.setInfo( "Can convert the "
// + SQLUtil.getVendorName( function.getStartToken( )
// .getDbvendor( ) )
// + " function "
// + function.toString( )
// + " to "
// + SQLUtil.getVendorName( targetVendor )
// + " automatically." );
// info.setPosition( new Tuple<Long>( function.getLineNo( ),
// function.getColumnNo( ) ) );
// String filePath = function.getStartToken( ).container.getGsqlparser( )
// .getSqlfilename( );
// if ( !SQLUtil.isEmpty( filePath ) )
// {
// info.setFilePath( filePath );
// }
// return info;
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ private boolean isSubStringFunction( TFunctionCall functionCall )
}
}

if ( "SUBSTR".equals( functionName )
if ( "SUBSTRING".equals( functionName )
|| "SUBSTR".equals( functionName )
|| "SUBSTRB".equals( functionName )
|| "SUBSTRC".equals( functionName )
|| "SUBSTR2".equals( functionName )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,27 @@ protected abstract ConvertInfo convert( Identifier identifier,
EDbVendor targetVendor, boolean convert ) throws ConvertException;

protected ConvertInfo generateConvertInfo( TObjectName identifier,
EDbVendor targetVendor )
EDbVendor targetVendor, boolean convert )
{
ConvertInfo info = new ConvertInfo( );
info.setInfo( "Can convert the "
+ SQLUtil.getVendorName( identifier.getStartToken( )
.getDbvendor( ) )
+ " identifier "
+ identifier.toString( )
+ " to "
+ SQLUtil.getVendorName( targetVendor )
+ " automatically." );
info.setPosition( new Tuple<Long>( identifier.getLineNo( ),
identifier.getColumnNo( ) ) );
String filePath = identifier.getStartToken( ).container.getGsqlparser( )
.getSqlfilename( );
if ( !SQLUtil.isEmpty( filePath ) )
if ( convert )
{
info.setFilePath( filePath );
info.setInfo( "Can convert the "
+ SQLUtil.getVendorName( identifier.getStartToken( )
.getDbvendor( ) )
+ " identifier "
+ identifier.toString( )
+ " to "
+ SQLUtil.getVendorName( targetVendor )
+ " automatically." );
info.setPosition( new Tuple<Long>( identifier.getLineNo( ),
identifier.getColumnNo( ) ) );
String filePath = identifier.getStartToken( ).container.getGsqlparser( )
.getSqlfilename( );
if ( !SQLUtil.isEmpty( filePath ) )
{
info.setFilePath( filePath );
}
}
return info;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ protected ConvertInfo convert( Identifier identifier,
TSourceTokenList tokens = identifier.getElement( ).getStartToken( ).container;

ConvertInfo info = generateConvertInfo( identifier.getElement( ),
targetVendor );
targetVendor,
convert );
info.setNeedConvert( false );

for ( int i = startTokenIndex; i <= endTokenIndex; i++ )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ protected ConvertInfo convert( Identifier identifier,
TSourceTokenList tokens = identifier.getElement( ).getStartToken( ).container;

ConvertInfo info = generateConvertInfo( identifier.getElement( ),
targetVendor );
targetVendor,
convert );
info.setNeedConvert( false );

for ( int i = startTokenIndex; i <= endTokenIndex; i++ )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ protected ConvertInfo convert( Identifier identifier,
TSourceTokenList tokens = identifier.getElement( ).getStartToken( ).container;

ConvertInfo info = generateConvertInfo( identifier.getElement( ),
targetVendor );
targetVendor,
convert );
info.setNeedConvert( false );

for ( int i = startTokenIndex; i <= endTokenIndex; i++ )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,27 @@ protected abstract ConvertInfo convert( JoinCondition joinCondition,
EDbVendor targetVendor, boolean convert ) throws ConvertException;

protected ConvertInfo generateConvertInfo( TExpression joinCondition,
EDbVendor targetVendor )
EDbVendor targetVendor, boolean convert )
{
ConvertInfo info = new ConvertInfo( );
info.setInfo( "Can convert the "
+ SQLUtil.getVendorName( joinCondition.getStartToken( )
.getDbvendor( ) )
+ " join "
+ joinCondition.toString( )
+ " to "
+ SQLUtil.getVendorName( targetVendor )
+ " automatically." );
info.setPosition( new Tuple<Long>( joinCondition.getLineNo( ),
joinCondition.getColumnNo( ) ) );
String filePath = joinCondition.getStartToken( ).container.getGsqlparser( )
.getSqlfilename( );
if ( !SQLUtil.isEmpty( filePath ) )
if ( convert )
{
info.setFilePath( filePath );
info.setInfo( "Can convert the "
+ SQLUtil.getVendorName( joinCondition.getStartToken( )
.getDbvendor( ) )
+ " join "
+ joinCondition.toString( )
+ " to "
+ SQLUtil.getVendorName( targetVendor )
+ " automatically." );
info.setPosition( new Tuple<Long>( joinCondition.getLineNo( ),
joinCondition.getColumnNo( ) ) );
String filePath = joinCondition.getStartToken( ).container.getGsqlparser( )
.getSqlfilename( );
if ( !SQLUtil.isEmpty( filePath ) )
{
info.setFilePath( filePath );
}
}
return info;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ protected ConvertInfo convert( JoinCondition join, EDbVendor targetVendor,
}

ConvertInfo info = generateConvertInfo( join.getElement( ),
targetVendor );
targetVendor,
convert );
boolean ansi = true;

switch ( targetVendor )
Expand Down Expand Up @@ -64,10 +65,8 @@ protected ConvertInfo convert( JoinCondition join, EDbVendor targetVendor,
{
ConvertInfo appendInfo = SqlFrog.getConvertPointMessage( join,
"F401, Oracle proprietary join syntax." );
if ( info != null )
{
info.setInfo( appendInfo.getInfo( ) + "\n" + info.getInfo( ) );
}
appendInfo.setNeedAnsiJoin( ansi );
return appendInfo;
}

return info;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ protected ConvertInfo convert( JoinCondition join, EDbVendor targetVendor,
}

ConvertInfo info = generateConvertInfo( join.getElement( ),
targetVendor );
targetVendor,
convert );
boolean ansi = true;

switch ( targetVendor )
Expand Down Expand Up @@ -65,10 +66,8 @@ protected ConvertInfo convert( JoinCondition join, EDbVendor targetVendor,
{
ConvertInfo appendInfo = SqlFrog.getConvertPointMessage( join,
"F401, SQL Server proprietary join syntax." );
if ( info != null )
{
info.setInfo( appendInfo.getInfo( ) + "\n" + info.getInfo( ) );
}
appendInfo.setNeedAnsiJoin( ansi );
return appendInfo;
}

return info;
Expand Down

0 comments on commit ee7ea5b

Please sign in to comment.