How to get output of sql queries in FitNesse + DbFit? - fitnesse

I am trying to get sql query output in DBfit using i.e. !|Execute|select * from abc| but don't know how it will display in DBfit.

I think that you are looking for the Inspect Query table (you can find reference docs about it here).
!|Inspect Query|select * from abc|
When executed, this will print the resultset of the query.

First, the execute fixture is typically used for actions that do not return data, e.g.:
!|Execute|insert into tablename values (…)|
or
!|Execute|update tablename st... where...|
However, even some non-data actions have more specific commands. The above update can be done with, for example, with:
!|Update|tablename |
|field_to_change=|field_to_select|
|new value |matching value |
For returning data, use the query fixture
!|query|select Id, BatchNum from tablename|
|Id |BatchNum? |
|1 |>>Bat1 |
|2 |<<Bat1 |
As shown, just put your field names in the row below the fixture, then your data rows below that.

Related

call data from sql in processmaker

i have a table in sql which is like this:
| product code | weight|
| ----------------------|-----------|
| 1235896 | 0.5|
| 3256kms | 1.5|
| dk-kmsw | 3 |
and the data type for [product code] is nvarchar
now i want to call the weight by putting the product code in processmaker
the code that i wrote is this:
select [weight] from table where [product code] = ##textVar047
and by this code i get nothing, i have changed the ## to ##, #= but it did not work.
how can i do this?
any comment is appreciated.
When you use ## in the SQL of a control, it means you are referencing another control's value. If that's your scenario I'd suggest first to retrieve the full list of product codes in a Suggest control (instead of a Textbox) with this SQL:
select PRODUCT_CODE, PRODUCT_CODE FROM YOUR_TABLE_NAME
(you call product code twice since Suggest controls, like dropdowns, need 2 values to be filled up, one for the id and one for the label)
Now that you have a way to obtain the actual code and it's saved in the suggest control id, you can make another field a dependent field with the SQL you where proposing:
select WEIGHT FROM YOUR_TABLE_NAME where PRODUCT_CODE = ##your_suggest_control_id
(## should work just fine as it just adds quotes to the variable)
You can also check the wiki page to get an in depth explanation of this. https://wiki.processmaker.com/3.1/Dependent_Fields
I hope this helps!
select CAST(weight AS nvarchar(max)) from table where [product code] = ##textVar047

Is it possible to use literal data as stream source in Sumologic?

Is it possible for a Sumologic user to define data source values inside a Query and use it in subquery condition?
For example in SQL, one can use literal data as source table.
-- example in MySQL
SELECT * FROM (
SELECT 1 as `id`, 'Alice' as `name`
UNION ALL
SELECT 2 as `id`, 'Bob' as `name`
-- ...
) as literal_table
I wonder if Sumo logic also have such kind of functionality.
I believe combining such literal with subqueries would make user's life easier.
I believe the equivalent in a Sumo Logic query would be combining the save operator to create a lookup table in a subquery: https://help.sumologic.com/05Search/Subqueries#Reference_data_from_child_query_using_save_and_lookup
Basically something like this:
_sourceCategory=katta
[subquery:(_sourceCategory=stream explainJSONPlan.ETT) error
| where !(statusmessage="Finished successfully" or statusmessage="Query canceled" or isNull(statusMessage))
| count by sessionId, statusMessage
| fields -_count
| save /explainPlan/neededSessions
| compose sessionId keywords]
| parse "[sessionId=*]" as sessionId
| lookup statusMessage from /explainPlan/neededSessions on sessionid=sessionid
Where /explainPlan/neededSessions is your literal data table that you select from later on in the query (using lookup).
You can define a lookup table with some static map/dictionary you update not so often (you can even point to a file in the internet in case you change the mapping often).
And then you can use the |lookup operator. It's nothing special for subqueries.
Disclaimer: I am currently employed by Sumo Logic.

Getting "undefined method" when attempting to order the result of a Rails query

I'm using Ruby on Rails 5. I'm having trouble ordering results returned from this query:
#crypto_currencies = CryptoIndexCurrency
.all
.pluck("crypto_currency_id")
.order(:name)
The name field is a valid member of the table from which I want to order.
cindex=# \d crypto_currencies;
Table "public.crypto_currencies"
Column | Type | Modifiers
--------------------------+-----------------------------+----------------------------------------------------------------
id | integer | not null default nextval('crypto_currencies_id_seq'::regclass)
name | character varying |
symbol | character varying |
latest_market_cap_in_usd | bigint |
latest_total_supply | bigint |
created_at | timestamp without time zone | not null
updated_at | timestamp without time zone | not null
Unfortunately whe I run the above I get the error:
undefined method `order' for #<Array:0x007fa3b2b27bd8>
How do I correct this?
That's right, pluck returns an array. Here is a note from documentation:
Pluck returns an Array of attribute values type-casted to match the plucked column names
where and order and other methods like that return Relation so that you can chain them. pluck should be in the end.
Say you're trying to cook eggs for yourself -- you're trying to scramble an egg carton instead of the egg inside the carton.
name is a field of CryptoCurrency, but .pluck is returning an array of CryptoCurrency objects -- the array has no name field.
You have to get the specific CryptoCurrency array element by either iterating through the array (for example, using .each... do) or accessing an element by index (#crypto_currencies[0]).
For more tutorial information on how to access the elements of an array, either by iteration or by element, please consult the official documentation.

How to show same column in dbgrid with different criteria

i need your help to finish my delphi homework.
I use ms access database and show all data in 1 dbgrid using sql. I want to show same column but with criteria (50 record per column)
i want select query to produce output like:
No | Name | No | Name |
1 | A | 51 | AA |
2 | B | 52 | BB |
3~50 | | 53~100| |
Is it possible ?
I can foresee issues if you choose to return a dataset with duplicate column names. To fix this, you must change your query to enforce strictly unique column names, using as. For example...
select A.No as No, A.Name as Name, B.No as No2, B.Name as Name2 from TableA A
join TableB B on B.Something = A.Something
Just as a note, if you're using a TDBGrid, you can customize the column titles. Right-click on the grid control in design-time and select Columns Editor... and a Collection window will appear. When adding a column, link it to a FieldName and then assign a value to Title.Caption. This will also require that you set up all columns. When you don't define any columns here, it automatically returns all columns in the query.
On the other hand, a SQL query may contain duplicate field names in the output, depending on how you structure the query. I know this is possible in SQL Server, but I'm not sure about MS Access. In any case, I recommend always returning a dataset with unique column names and then customizing the DB Grid's column titles. After all, it is also possible to connect to an excel spreadsheet, which can very likely have identical column names. The problem arrives when you try to read from one of those columns for another use.

Returning all results in one column, but using a where statement to filter another column

Using SQlite 3, and have a table that looks like the following
PKEY|TS | A |B |C
1 |00:05:00|200|200|200
2 |00:10:00|100|100|100
3 |00:15:00| |25 |
4 |00:20:00| | |
Currently I'm using
select ts, (a+b+c) from tablename WHERE a !='null' AND b !='null' and c !='null';"
which returns
TS | (a+b+c)
00:05:00|600
00:10:00|300
I want my results to look like the following though:
TS | total
00:05:00|600
00:10:00|300
00:15:00|
00:20:00|
So in other words, I always want to return everything from the TS column, but I don't want to return the total unless A,B, and C have values.
I think I might need a union or a join, but I can't seem to find an example where the results from a single column are always returned.
Testing for a != 'null' will never be true. you need to use a is not null.
However, to return a null total if any of the numbers are null, just do this:
select ts, a+b+c
from tablename;
Why does this work? Because in SQL if any part of an expression is null, the whole expression is null. This makes sense when you consider that null means "unknown". Logically, when part of a calculation is unknown, then the result is unknown.

Resources