Migration From SQL Server to UniSQL: Select top (n) clause

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
mlagasio
Posts: 43
Joined: Mon 14 Mar 2011 13:42

Migration From SQL Server to UniSQL: Select top (n) clause

Post by mlagasio » Mon 14 Mar 2011 14:02

Hi all,

how could I translate a SQLServer Statement such as


select top 1 from mytable

into UniSQL statement ?

Many thanks in advance

Marco

AndreyZ

Post by AndreyZ » Mon 14 Mar 2011 16:33

Hello,

You should not use the TUniSQL component for executing SQL statements that return rows from the database. You should execute this SQL statement in the TUniQuery component. Here is a code example:

Code: Select all

UniQuery.SQL.Text := 'select top 1 * from mytable';
UniQuery.Open;

mlagasio
Posts: 43
Joined: Mon 14 Mar 2011 13:42

Post by mlagasio » Tue 15 Mar 2011 09:03

Hi

thank you for your answer.

I'm using ms visual studio in this moment (also if I'm a Delphi developer).
I'm migrating a visual studio application linked to SQLServer to Oracle and
I'd want use your classes.

Your hint applies to BDS or RAD Studio. Is it correct?

Bye Marco

mlagasio
Posts: 43
Joined: Mon 14 Mar 2011 13:42

Post by mlagasio » Tue 15 Mar 2011 09:54

Another key point, for me.

My solution is on a virtual machine (vs 2005)

I've launched the migration wizard but the wizard do nothing (exist a log?)

Best Regard
Marco

mlagasio
Posts: 43
Joined: Mon 14 Mar 2011 13:42

Post by mlagasio » Tue 15 Mar 2011 13:52

Another info on later post: the code to be processed is in AppCode folder of some web services (server side).
I've tried to make the migration on another vc# project. It's work correctly

Bye
Marco

mlagasio
Posts: 43
Joined: Mon 14 Mar 2011 13:42

Post by mlagasio » Tue 15 Mar 2011 13:52

Another info on later post: the code to be processed is in AppCode folder of some web services (server side).
I've tried to make the migration on another vc# project. It's work correctly

Bye
Marco

AndreyZ

Post by AndreyZ » Tue 15 Mar 2011 15:09

Both BDS and RAD Studio are Delphi IDEs, and my answer is correct for both of them. Migration Wizard is available only for Delphi IDE.

mlagasio
Posts: 43
Joined: Mon 14 Mar 2011 13:42

Post by mlagasio » Tue 15 Mar 2011 15:52

Excuse me,

I see Migration Wizard also in VS menu'

Regards

AndreyZ

Post by AndreyZ » Wed 16 Mar 2011 11:35

UniDAC Migration Wizard allows you to convert your BDE, IBX, ADO, ODAC, SDAC, MyDAC, and IBDAC projects to UniDAC. UniDAC Migration Wizard is available only for Delphi IDE, and it doesn't have anything to do with Migration Wizard that you've found in the Visual Studio menu.

mlagasio
Posts: 43
Joined: Mon 14 Mar 2011 13:42

Post by mlagasio » Mon 21 Mar 2011 08:25

Thank you for your answer.

Ok. I'm referring exclusively to migration wizard of visual studio and to UniSql language (not a component) used with UniCommand.

My questions (relate only to this context) are

1) how could I write in unified manner "select top 1 ....". Is it possible (I use only SQLServer and Oracle)
2) the migration wizard of vs doesn't work with AppCode of web service

For question 2 I've found a radical work-around: transfer all AppCode in a normal c# project and call it from ws

For question 1 I've not answer

Best Regard
Marco

AndreyZ

Post by AndreyZ » Tue 22 Mar 2011 10:25

You can use macros to implement such functionality. For example, you can write the following code:

Code: Select all

UniQuery.SQL.Text := 'select &mssql from test_table &ora';
, and for SQL Server use this code:

Code: Select all

UniQuery.MacroByName('ora').Active := false;
UniQuery.MacroByName('mssql').Active := true;
UniQuery.MacroByName('mssql').AsString := 'TOP 1';
, and for Oracle use this code:

Code: Select all

UniQuery.MacroByName('mssql').Active := false;
UniQuery.MacroByName('ora').Active := true;
UniQuery.MacroByName('ora').AsString := 'WHERE ROWNUM < 2';
For more information about macros, please read the "Working with macros" topic of the UniDAC documentation.

Post Reply