Surreal DB - Query from Sets - surrealdb

I have created an author user in surreal DB like this:
CREATE author:shivam SET
name.first = 'Shivam',
name.last = 'Sahil',
name.full = string::join(' ', name.first, name.last),
age = 23,
admin = true,
signup_at = time::now()
;
Now I want to query all the authors, but when I do:
SELECT * FROM author;
I get 0 results.
Is it supposed to be queried in some other way?

What you did should work well as you can see here
Don't forget to start your server with something like this for example
surreal start --log info --user root --pass root memory
and log-in as in my above screenshot with:
surreal sql --conn http://localhost:8000 --ns yoloswag --db compabie
Then, your create query and select should work well!
Alternatively, you can give a try to that video or documentation's quick start.
Creating another author like this is properly fetched afterwards.
CREATE author:123 SET
name.first = 'bob',
name.last = 'hoh',
name.full = string::join(' ', name.first, name.last),
age = 30,
admin = false,
signup_at = time::now()
;
Don't forget that 123 is supposed to be a unique ID (a string should be fine tho).

Related

'No Rows Selected' when running query on sqlplus using CMD

Hi i am trying to run a file named query.sql using sqlplus on cmd but getting 'No Rows Selected' inside csv while the same query gives results when Run on Oracle SQL Developer
I have run the following command on cmd
sqlplus <username>/<password>#sid #query.sql > output.csv
The query inside query.sql is
SELECT
SR.SOID,
EL.SOID,
EO.EPTNUMBER,
EO.SLELABEL,
EL.LOGTEXT,
utl_raw.cast_to_varchar2(dbms_lob.substr(SR.SODATA, 3000, 1)) AS NAC_DATA
FROM
SORECORD SR,
SOAPPKEY SK,
EPTORDER EO,
EPTLOG EL
WHERE
SK.APPKEYNAME = 'MSISDN'
AND SK.appkeyvalue = '<ctn here>'
AND SK.SOID = SR.SOID
AND SR.SOTYPE = 'NAC'
AND SR.Receipttimestamp LIKE '07-JAN-20'
AND SR.SOID = EO.SOID
AND EO.EPTNUMBER = EL.EPTNUMBER
AND EL.SOID LIKE TO_CHAR((
Select
SUBSTR(TO_CHAR(SR.SOID), 1, LENGTH(SR.SOID) - 1)
FROM
SORECORD SR, SOAPPKEY SK
WHERE
SK.APPKEYNAME = 'MSISDN'
AND SK.appkeyvalue = '<ctn here>'
AND SK.SOID = SR.SOID
AND SR.SOTYPE = 'NAC'
AND SR.Receipttimestamp LIKE '07-JAN-20')) || '%'
AND EL.SOID > TO_NUMBER((
Select
SUBSTR(TO_CHAR(SR.SOID), 1, LENGTH(SR.SOID) - 1)
FROM
SORECORD SR, SOAPPKEY SK
WHERE
SK.APPKEYNAME = 'MSISDN'
AND SK.appkeyvalue = '<ctn here>'
AND SK.SOID = SR.SOID
AND SR.SOTYPE = 'NAC'
AND SR.Receipttimestamp LIKE '07-JAN-20') || '0');
I tried other queries to generate csv and they were working fine. I have no clue why this one is giving 'No Rows Selected' for sqlplus cmd when this same query fetches results in Oracle SQL Developer.
Can anyone help me out in pointing out the issue?
If SR.Receipttimestamp column's datatype is DATE, why are you comparing it to a string? '07-JAN-20' is a string, not a date. You're relying on Oracle's capabilities to implicitly convert that string into a valid date value, but - that doesn't work always. I presume that's what bothers your query.
I'd suggest you to rewrite it; a simple option - just to see whether it helps - is
where trunc(SR.Receipttimestamp) = date '2020-01-07'
i.e.
with trunc, "remove" time component (it'll set that column's value to 00:00 hours)
compare it to a date literal which is always in date 'yyyy-mm-dd' format
#Littlefoot, I made the mentioned change and it worked but facing a few issues in the csv file now
I have used the below Spool Code:
set pagesize 0
set feed off
set term off
spool '<my path here>'
SELECT
SR.SOID,
EL.SOID,
EO.EPTNUMBER,
EO.SLELABEL,
EL.LOGTEXT,
utl_raw.cast_to_varchar2(dbms_lob.substr(SR.SODATA, 3000, 1)) AS NAC_DATA
FROM
SORECORD SR,
SOAPPKEY SK,
EPTORDER EO,
EPTLOG EL
WHERE
SK.APPKEYNAME = 'MSISDN'
AND SK.appkeyvalue = '07996703863'
AND SK.SOID = SR.SOID
AND SR.SOTYPE = 'NAC'
AND trunc(SR.Receipttimestamp) = date '2020-01-07'
AND SR.SOID = EO.SOID
AND EO.EPTNUMBER = EL.EPTNUMBER
AND EL.SOID LIKE TO_CHAR((
Select
SUBSTR(TO_CHAR(SR.SOID), 1, LENGTH(SR.SOID) - 1)
FROM
SORECORD SR, SOAPPKEY SK
WHERE
SK.APPKEYNAME = 'MSISDN'
AND SK.appkeyvalue = '07996703863'
AND SK.SOID = SR.SOID
AND SR.SOTYPE = 'NAC'
AND trunc(SR.Receipttimestamp) = date '2020-01-07')) || '%'
AND EL.SOID > TO_NUMBER((
Select
SUBSTR(TO_CHAR(SR.SOID), 1, LENGTH(SR.SOID) - 1)
FROM
SORECORD SR, SOAPPKEY SK
WHERE
SK.APPKEYNAME = 'MSISDN'
AND SK.appkeyvalue = '07996703863'
AND SK.SOID = SR.SOID
AND SR.SOTYPE = 'NAC'
AND trunc(SR.Receipttimestamp) = date '2020-01-07') || '0');
spool off
and CMD used
sqlplus <username>/<password>#sid #<path of spool txt>
Now I am getting csv data as below
5764377,5764371,1,EEVMS,
Tue Jan 07 08:29:49:887 2020SOAP MESSAGE SENT:
<S:Envel
5764377,5764375,1,EEVMS,
Tue Jan 07 08:30:49:900 2020SOAP MESSAGE SENT:
<S:Envel
5764377,5764376,1,EEVMS,
Tue Jan 07 08:31:50:003 2020SOAP MESSAGE SENT:
<S:Envel
Now i am facing 2 issues in this:
I am getting partial data from EL.LOGTEXT whose data type is CLOB
Data column of utl_raw.cast_to_varchar2(dbms_lob.substr(SR.SODATA, 3000, 1)) AS NAC_DATA is all together missing from the csv
Here is the snapshot of query data on SQL Developer. I actually want the data in this tabular format in my CSV:

How to refactor on easy way simple rspec test to use subject/let/it and FactoryGirl?

Basically i am having very simple test where i check if account_id from Grant (so id of his parent) is equal to account_id of Role model.
Test seems ok, but i need to refactor it to use subject/let and to use FactoryGirl and i can't do that even with all the info on this subject i found.
So, test is fine i just need help with refactoring.
It's first time for me working with rails and writing test on it, so i am forced to ask this type of question here.
describe "validations" do
it "should have equal account_id" do
first_acc, second_acc = Account.new, Account.new
first_acc.id, second_acc.id = 10, 11
vlada_role, vlada_grant = Role.new, Grant.new
vlada_role1, vlada_grant1 = Role.new, Grant.new
vlada_role.account_id = first_acc.id
vlada_grant.account_id = second_acc.id
vlada_role.id, vlada_grant.id = 8000, 255
rg = RoleGrant.new
rg1 = RoleGrant.new
rg.role, rg1.role = vlada_role, vlada_role1
rg.grant, rg1.grant = vlada_grant, vlada_grant1
expect(rg.role.account_id).not_to eql(rg.grant.account_id)
expect(rg1.role.account_id).to eql(rg1.grant.account_id)
end
end

first_or_initialize is not working for relative model and creating new record each time

ccs.each do |cd|
relative_model = main_model.relative_model.where(start_date: XYZ, end_date: XYZ).first_or_initialize
relative_model.capacity = cd['capacity'].to_f
relative_model.save!
end
As per above code, first_or_initialize is not working for relative model and creating new record each time.
Here is the query run at background for both inr:
SELECT `capacity_commitments`.* FROM `capacity_commitments` WHERE `capacity_commitments`.`participants_subscription_id` = 1 AND `capacity_commitments`.`start_date` = '2016-11-16' AND `capacity_commitments`.`end_date` = '2016-11-21'
SELECT `capacity_commitments`.* FROM `capacity_commitments` WHERE `capacity_commitments`.`participants_subscription_id` = 1 AND `capacity_commitments`.`start_date` = '2016-11-16' AND `capacity_commitments`.`end_date` = '2016-11-21'
NEED INITIAL HELP OR POINT OUT WHAT IS WRONG IN ABOVE CODE?
Try to use find_or_initialize_by method
relative_model = main_model.relative_model.find_or_initialize_by(start_date: XYZ, end_date: XYZ)

CT_FETCH error in PowerBuilder Program

I'm still learning PowerBuilder and trying to get familiar with it. I'm receiving the following error when I try to run a program against a specific document in my database:
ct_fetch(): user api layer: internal common library error: The bind of result set item 4 resulted in an overflow. ErrCode: 2.
What does this error mean? What is item 4? This is only when I run this program against a specific document in my database, any other document works fine. Please see code below:
string s_doc_nmbr, s_doc_type, s_pvds_doc_status, s_sql
long l_rtn, l_current_fl, l_apld_fl, l_obj_id
integer l_pvds_obj_id, i_count
IF cbx_1.checked = True THEN
SELECT dsk_obj.obj_usr_num,
dsk_obj.obj_type,
preaward_validation_doc_status.doc_status,
preaward_validation_doc_status.obj_id
INTO :s_doc_nmbr, :s_doc_type, :s_pvds_doc_status, :l_pvds_obj_id
FROM dbo.dsk_obj dsk_obj,
preaward_validation_doc_status
WHERE dsk_obj.obj_id = :gx_l_doc_obj_id
AND preaward_validation_doc_status.obj_id = dsk_obj.obj_id
using SQLCA;
l_rtn = sqlca.uf_sqlerrcheck("w_pdutl095_main", "ue_run_script", TRUE)
IF l_rtn = -1 THEN
RETURN -1
END IF
//check to see if document (via obj_id) exists in the preaward_validation_doc_status table.
SELECT count(*)
into :i_count
FROM preaward_validation_doc_status
where obj_id = :l_pvds_obj_id
USING SQLCA;
IF i_count = 0 THEN
//document doesn't exist
// messagebox("Update Preaward Validation Doc Status", + gx_s_doc_nmbr + ' does not exist in the Preaward Validation Document Status table.', Stopsign!)
//MC - 070815-0030-MC Updating code to insert row into preaward_validation_doc_status if row doesn't already exist
// s_sql = "insert into preaward_validation_doc_status(obj_id, doc_status) values (:gx_l_doc_obj_id, 'SUCCESS') "
INSERT INTO preaward_validation_doc_status(obj_id, doc_status)
VALUES (:gx_l_doc_obj_id, 'SUCCESS')
USING SQLCA;
IF sqlca.sqldbcode <> 0 then
messagebox('SQL ERROR Message',string(sqlca.sqldbcode)+'-'+sqlca.sqlerrtext)
return -1
end if
MessageBox("PreAward Validation ", 'Document number ' + gx_s_doc_nmbr + ' has been inserted and marked as SUCCESS for PreAward Validation.')
return 1
Else
//Update document status in the preaward_validation_doc_status table to SUCCESS
Update preaward_validation_doc_status
Set doc_status = 'SUCCESS'
where obj_id = :l_pvds_obj_id
USING SQLCA;
IF sqlca.sqldbcode <> 0 then
messagebox('SQL ERROR Message',string(sqlca.sqldbcode)+'-'+sqlca.sqlerrtext)
return -1
end if
MessageBox("PreAward Validation ", 'Document number '+ gx_s_doc_nmbr + ' has been marked as SUCCESS for PreAward Validation.')
End IF
update crt_script
set alt_1 = 'Acknowledged' where
ticket_nmbr = :gx_s_ticket_nmbr and
alt_2 = 'Running' and
doc_nmbr = :gx_s_doc_nmbr
USING SQLCA;
Return 1
ElseIF cbx_1.checked = False THEN
messagebox("Update Preaward Validation Doc Status", 'The acknowledgment checkbox must be selected for the script to run successfully. The script will now exit. Please relaunch the script and try again . ', Stopsign!)
Return -1
End IF
Save yourself a ton of headaches and use datawindows... You'd reduce that entire script to about 10 lines of code.
Paul Horan gave you good advice. This would be simple using DataWindows or DataStores. Terry Voth is on the right track for your problem.
In your code, Variable l_pvds_obj_id needs to be the same type as gx_l_doc_obj_id because if you get a result, it will always be equal to it. From the apparent naming scheme it was intended to be long. This is the kind of stuff we look for in peer reviews.
A few other things:
Most of the time you want SQLCode not SQLDbCode but you didn't say what database you're using.
After you UPDATE crt_script you need to check the result.
I don't see COMMIT or ROLLBACK. Autocommit isn't suitable when you need to update multiple tables.
You aren't using most of the values from the first SELECT. Perhaps you've simplified your code for posting or troubleshooting.

1 result set from 3 queries?

I'm at my wits end attempting to make this happen. Currently I have 3 separate queries. For automation purposes I need to get the results of these three queries in one output, I cannot seem to join them properly to get the expected results.
QUERY 1:
SELECT OH.EXTN_HOST_ORDER_REF,
OL.EXTN_HOST_ORDER_LINE_REF,
OL.ORIGINAL_ORDERED_QTY,
OL.EXTN_TENDER_QUANTITY,
OL.EXTN_CUM_PICK_QTY,
OL.SHIPPED_QUANTITY,
OL.EXTN_REFUND_QTY
FROM YFS_ORDER_HEADER OH,
YFS_ORDER_LINE OL
WHERE OH.ORDER_HEADER_KEY = OL.ORDER_HEADER_KEY
AND OH.DOCUMENT_TYPE = '0001'
AND OH.EXTN_HOST_ORDER_REF = 'xxxxxxxxxxx'
ORDER BY PL.EXTN_HOST_ORDER_LINE_REF ASC;
QUERY 2:
SELECT RS.STATUS_QUANTITY AS RETURNED_QTY
FROM YFS_ORDER_HEADER OH,
YFS_ORDER_LINE OL,
YFS_ORDER_RELEASE_STATUS RS
WHERE OH.ORDER_HEADER_KEY = OL.ORDER_HEADER_KEY
AND OL.ORDER_LINE_KEY = RS.ORDER_LINE_KEY
AND RS.STATUS = '3700.02'
AND OH.EXTN_HOST_ORDER_REF = 'xxxxxxxxxxx';
QUERY 3
SELECT RS.STATUS_QUANTITY AS CANCELLED_QTY
FROM YFS_ORDER_HEADER OH,
YFS_ORDER_LINE OL,
YFS_ORDER_RELEASE_STATUS RS
WHERE OH.ORDER_HEADER_KEY = OL.ORDER_HEADER_KEY
AND OL.ORDER_LINE_KEY = RS.ORDER_LINE_KEY
AND RS.STATUS = '9000'
AND OH.EXTN_HOST_ORDER_REF = 'xxxxxxxxxxx';
The query should show NULL values where no data exists from query 2 & 3.
Thanks in advance for your help and advice!
If you are allowed to show both returned and cancelled quantities, the following simple edit should work. Hope this helps.
SELECT oh.extn_host_order_ref,
ol.extn_host_order_line_ref,
ol.original_ordered_qty,
ol.extn_tender_quantity,
ol.extn_cum_pick_qty,
ol.shipped_quantity,
ol.extn_refund_qty,
DECODE (rs.status, '3700.02', rs.status_quantity) AS returned_qty,
DECODE (rs.status, '9000', rs.status_quantity) AS cancelled_qty
FROM yfs_order_header oh
INNER JOIN yfs_order_line ol
ON oh.order_header_key = ol.order_header_key
LEFT OUTER JOIN yfs_order_release_status rs
ON ol.order_line_key = rs.order_line_key
WHERE oh.document_type = '0001' AND oh.extn_host_order_ref = 'xxxxxxxxxxx'
ORDER BY pl.extn_host_order_line_ref ASC;

Resources