Skip to main content
Solved

How to convert fBQL or BQL to SQL statement while debugging in Visual Studio

  • September 8, 2022
  • 8 replies
  • 590 views

Hello,

While working with fBQL or BQL I have often wanted to see what exactly the equivalent SQL statement be. Is there an inbuilt function something like like .ToSQLString() that we can use on a fBQL statement or View that can show us the equivalent SQL.

 

So for example, if I have the following View

SelectFrom<CSAnswers>
.InnerJoin<InventoryItem>
	.On<InventoryItem.noteID.IsEqual<CSAnswers.refNoteID>>
.Where<CSAnswers.attributeID.IsEqual<Use<slots>.AsString>
	.And<InventoryItem.inventoryID.IsEqual<@P.AsInt>>>
.View.Select(cache.Graph, invtID)

 

How can I see the exact SQL that’s generated (including the parameter values in the Where clause)?

One option is I can run SQL profiler, but is there anything inbuilt Acumatica SDK/Framework that can help me view the SQL statement while debugging in VS?

Best answer by MoulaliShaik79

Hi @kashif78,

Please check the below link:

https://help-2021r2.acumatica.com/(W(15))/Help?ScreenId=ShowWiki&pageid=5bc68600-61ab-4a49-958c-da5d732b2ac2

 

I hope this may help you.

 

Thanks,

Moulali Shaik.

View original
Did this topic help you find an answer to your question?

8 replies

Forum|alt.badge.img+1
  • Semi-Pro II
  • 61 replies
  • Answer
  • September 8, 2022

Hi @kashif78,

Please check the below link:

https://help-2021r2.acumatica.com/(W(15))/Help?ScreenId=ShowWiki&pageid=5bc68600-61ab-4a49-958c-da5d732b2ac2

 

I hope this may help you.

 

Thanks,

Moulali Shaik.


  • Author
  • Freshman I
  • 4 replies
  • September 8, 2022

Thank you @MoulaliShaik79, that documentation helped me come up with the required code.

So here’s the updated code that I have used and can see the strSQL while debugging

 

var strSQL = 
	SelectFrom<CSAnswers>
	.InnerJoin<InventoryItem>
		.On<InventoryItem.noteID.IsEqual<CSAnswers.refNoteID>>
	.Where<CSAnswers.attributeID.IsEqual<Use<slots>.AsString>
		.And<InventoryItem.inventoryID.IsEqual<@P.AsInt>>>
	.View.GetCommand().GetQuery(Base).SQLQuery(Base.SqlDialect.GetConnection());  

 


  • Author
  • Freshman I
  • 4 replies
  • September 8, 2022

While I was debugging using the above technique/code, I noticed that the query doesn’t includes the filter for CompanyID in Where, Join and Group By clauses. Any ideas how I can make Acumatica give me the SQL query after it adds the CompanyID to the SQL Query Tree?


Forum|alt.badge.img+1

Hi @kashif78,

The Company ID column is used for Multi-Tenet support purposes. We can not find it in our DAC Fields.

Please check the below link to get some information about the Company ID column.

https://help-2021r2.acumatica.com/(W(16))/Help?ScreenId=ShowWiki&pageid=d0945e20-1949-40b1-bd0f-92c7c432aa24

 

Note: Till now I didn’t use the Company ID column in FBQL or BQL queries.

 

Thanks,

Moulali Shaik.


  • Author
  • Freshman I
  • 4 replies
  • September 8, 2022

Yes, I’m aware that we don’t add a CmpanyID field in our DAC. But Acumatica does add the filters for CmpanyID when running a query against the SQL DB. I wanted to see what all places in the query it adds the CompanyID filter

 

PS: My dev environment is a multi-tenant one having around 5 companies. 


Leonardo Justiniano
Jr Varsity II
Forum|alt.badge.img+4

Hi All

Recent versions of Acumatica add an option under tools to trace SQL statements:

 

 

When you stop the logging a zip file is generated for downloading

 

You can then see all the add-ons Acumatica includes in your simple (F)BQL query.

Also you can use MS SQL Profiler if you want to see it coming as it happens (Enjoy the cache as not all the time those queries are triggered)


  • Freshman I
  • 2 replies
  • September 8, 2022

Another option that you have is you can wire up a SQL profiler as to see the end result of what gets sent to SQL server.


  • Author
  • Freshman I
  • 4 replies
  • September 9, 2022
Leonardo Justiniano wrote:

Hi All

Recent versions of Acumatica add an option under tools to trace SQL statements:

 

 

When you stop the logging a zip file is generated for downloading

 

You can then see all the add-ons Acumatica includes in your simple (F)BQL query.

Also you can use MS SQL Profiler if you want to see it coming as it happens (Enjoy the cache as not all the time those queries are triggered)

 

Thanks for the tip @Leonardo Justiniano 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings