Column headers in SQL Box

Moderator: crythias

Locked
HervE
Znuny wizard
Posts: 391
Joined: 03 Jan 2011, 17:15
Znuny Version: 3.3.8
Location: France

Column headers in SQL Box

Post by HervE »

Hello,

As mentioned here, I am looking for a way to add column headers in SQL Box results.
crythias wrote:Not directly from sqlbox, but I suppose you could tweak the Kernel/Modules/AdminSelectBox.pm for it.
I checked in AdminSelectBox.pm, and noticed this:

Code: Select all

while ( my @Row = $Self->{DBObject}->FetchrowArray( RowNames => 1 ) ) {
So let's see the role of RowNames parameter!

I opened FetchrowArray Sub definition from Kernel\System\DB.pm and... can't see anything about RowNames parameter!! This parameter just doesn't exist!

What's the point?

Regards,
HervE
OTRS 3.3.8 - Windows 7 - IIS7 - SQL Server - Firefox 30
bpb85
Znuny newbie
Posts: 1
Joined: 04 Jun 2012, 09:45
Znuny Version: 3.1.4
Location: France

Re: Column headers in SQL Box

Post by bpb85 »

Hi
I have already add the "Json" output to generate a json file with sqlbox.
But my json is not really good because there is no headers on this.

Code: Select all

[
[
"1",
"2010080210123456",
"Welcome to OTRS!",
"2",
"1",
"0",
null,
null,
null,
"1",
"1",
"1",
"3",
"1",
null,
null,
null,
null,
null,
null,
"0",
"0",
"0",
"0",
"0",
"0",
"1",
"0",
"1280750400",
"2012-05-29 15:31:19",
"1",
"2012-05-29 15:31:19",
"1"
],
[
"2",
"2012053010000018",
"ytreza",
"4",
"1",
"0",
"1",
null,
null,
"1",
"1",
"1",
"3",
"4",
null,
null,
null,
null,
"azerty",
"azerty",
"0",
"0",
"0",
"0",
"0",
"0",
"1",
"0",
"1338387850",
"2012-05-30 16:24:10",
"1",
"2012-05-30 16:24:10",
"1"
]
]
(result of select * from ticket on a test DB)

I want to add the column name on each line so, it's the same problem ...
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Column headers in SQL Box

Post by crythias »

RowNames is only referenced once in the code in AdminSelectBox.pm and calls Kernel/System/DB.pm FetchrowArray which ignores it, essentially.

Want to do it the hard way? :)

Code: Select all

select 'id', 'name', 'comments' union select id, name, comments from article_type
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
HervE
Znuny wizard
Posts: 391
Joined: 03 Jan 2011, 17:15
Znuny Version: 3.3.8
Location: France

Re: Column headers in SQL Box

Post by HervE »

Naturally you can do it the hard way (very clever!), but what if you just don't know the column names? (basically when you "select * from...")

Regards,
HervE
OTRS 3.3.8 - Windows 7 - IIS7 - SQL Server - Firefox 30
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Column headers in SQL Box

Post by crythias »

If you don't know the column names, you can DESCRIBE and get them, but it isn't necessarily good practice to select * ... I know, that doesn't help,
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
HervE
Znuny wizard
Posts: 391
Joined: 03 Jan 2011, 17:15
Znuny Version: 3.3.8
Location: France

Re: Column headers in SQL Box

Post by HervE »

DESCRIBE doesn't work in SQL Box :(
And neither does SHOW COLUMNS FROM :(

Regards,
HervE
OTRS 3.3.8 - Windows 7 - IIS7 - SQL Server - Firefox 30
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Column headers in SQL Box

Post by crythias »

Describe works when you remove the limit.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
HervE
Znuny wizard
Posts: 391
Joined: 03 Jan 2011, 17:15
Znuny Version: 3.3.8
Location: France

Re: Column headers in SQL Box

Post by HervE »

And so does SHOW COLUMNS FROM

(I didn't remove the limit first, because I noticed it works for queries like UPDATE or DELETE even with limit.)

Thanks,
HervE
OTRS 3.3.8 - Windows 7 - IIS7 - SQL Server - Firefox 30
Locked