powered by simpleCommunicator - 2.0.49     © 2025 Programmizd 02
Форумы / Caché, Ensemble, DeepSee, MiniM, IRIS, GT.M [игнор отключен] [закрыт для гостей] / Custom SQL query & .NET
5 сообщений из 5, страница 1 из 1
Custom SQL query & .NET
    #38437017
vichka
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Всем привет!
Помогите пожалуйста, как решить проблему.

I have an issue with the custom query in my .NET application.
I have 4 parameters in the custom query- three Strings and one Integer. The query works fine when I passed only string parameters. When I added another parameter as an integer to select top max records, no records returned from the database in my vb.net application.

It works correct and tested without issues in WinSQL or from Cache System Management Portal.

See my code here:

GetTVRefNosForLicenceName(): Query GetTVRefNosForLicenceName(  SearchMax As %Integer , SearchFirstName As %String, SearchSurname As %String, SearchAddress As %String) As %SQLQuery
(ROWSPEC = "TVRefNo:%String, LicenceFirstName:%String, LicenceSurname:%String, LicenceAddress1:%String, LicenceAddress2:%String, LicenceAddress3:%String, LicenceAddress4:%String, LicenceIssueDate:%Date, LicenceExpiryDate:%Date, LicencePrintDate:%Date") [ SqlProc ]
{
}
GetTVRefNosForLicenceNameExecute(): /// Execute method for GetTVRefNosForLicenceName custom query
ClassMethod GetTVRefNosForLicenceNameExecute(ByRef qHandle As %Binary, SearchMax As %Integer, SearchFirstName As %String, SearchSurname As %String, SearchAddress As %String) As %Status
{
  // initialise the return status
  set ReturnStatus = $$$OK
  
  // main code block
  try {    
    // build the query
    set sql = "select top ?" 
    set sql = sql _ " tvrefno, licencefirstname, licencesurname, licenceaddress1, licenceaddress2, licenceaddress3, licenceaddress4, licenceissuedate, licenceexpirydate, licenceprintdate"
    set sql = sql _ " from epay.v_licencehistorylatest"
    set sql = sql _ " where (licencefirstname LIKE ?)"
    set sql = sql _ " and (licencesurname LIKE ?)"
    set sql = sql _ " and (DisplayAddressSingleLine LIKE ?)"    
    
    // create, prepare and execute the resultset
    set rsTVRefNoSearch = ##class(%ResultSet).%New()
    set PrepareStatus = rsTVRefNoSearch.Prepare(sql)
    if $$$ISERR(PrepareStatus) throw ##class(%Exception.StatusException).CreateFromStatus(PrepareStatus)
    set ExecuteStatus = rsTVRefNoSearch.Execute(SearchMax, SearchFirstName, SearchSurname, SearchAddress)
    if $$$ISERR(ExecuteStatus) throw ##class(%Exception.StatusException).CreateFromStatus(ExecuteStatus)
    
    // store the resultset in the handle
    set qHandle  = rsTVRefNoSearch    
  }
  
  // main error handler
  catch e {    
    // set the return status
    set ReturnStatus = $$$ERROR($$$GeneralError, "Error in " _ ..%ClassName(1) _ ".GetTVRefNosForLicenceNameExecute[#]SearchMax=" _ SearchMax _ "[~]SearchFirstName=" _ SearchFirstName _ "[~]SearchSurname=" _ SearchSurname _ "SearchAddress=" _ SearchAddress _ "[#]"_ e.DisplayString())    
  }  
  // quit the return status
  QUIT ReturnStatus
}
GetTVRefNosForLicenceNameFetch(): /// Fetch method for GetTVRefNosForLicenceName custom query
ClassMethod GetTVRefNosForLicenceNameFetch(ByRef qHandle As %Binary, ByRef Row As %List, ByRef AtEnd As %Integer = 0) As %Status [ PlaceAfter = GetTVRefNosForLicenceNameExecute ]
{
  // initialise the return status
  set ReturnStatus = $$$OK
  
  // main code block
  try {    
    // retrieve the resultset from the handle
    set rsTVRefNoSearch = qHandle    
    // check for next record in the resultset
    if rsTVRefNoSearch.Next() {      
      // retrieve the field values from the current row in the resultset
      set TVRefNo = rsTVRefNoSearch.Get("TVRefNo")
      set LicenceFirstName = rsTVRefNoSearch.Get("LicenceFirstName")
      set LicenceSurname = rsTVRefNoSearch.Get("LicenceSurname")
      set LicenceAddress1 = rsTVRefNoSearch.Get("LicenceAddress1")
      set LicenceAddress2 = rsTVRefNoSearch.Get("LicenceAddress2")
      set LicenceAddress3 = rsTVRefNoSearch.Get("LicenceAddress3")
      set LicenceAddress4 = rsTVRefNoSearch.Get("LicenceAddress4")
      set LicenceIssueDate = rsTVRefNoSearch.Get("LicenceIssueDate")
      set LicenceExpiryDate = rsTVRefNoSearch.Get("LicenceExpiryDate")
      set LicencePrintDate = rsTVRefNoSearch.Get("LicencePrintDate")      
      // build the row according to the row specification
      set Row = $lb(TVRefNo, LicenceFirstName, LicenceSurname, LicenceAddress1, LicenceAddress2, LicenceAddress3, LicenceAddress4, LicenceIssueDate, LicenceExpiryDate, LicencePrintDate)
    }    
    // there are no more records left to fetch
    else {      
      // tell the query processor to stop by setting these variables
      set Row = ""
      set AtEnd = 1      
    }    
  }  
  // main error handler
  catch e {    
    // set the return status
    set ReturnStatus = $$$ERROR($$$GeneralError, "Error in " _ ..%ClassName(1) _ ".GetTVRefNosForLicenceNameFetch[#][#]"_ e.DisplayString())    
  }
  
  // quit the return status
  QUIT ReturnStatus
}
GetTVRefNosForLicenceNameClose(): /// Close method for GetTVRefNosForLicenceName custom query
ClassMethod GetTVRefNosForLicenceNameClose(ByRef qHandle As %Binary) As %Status [ PlaceAfter = GetTVRefNosForLicenceNameExecute ]
{
  // initialise the return status
  set ReturnStatus = $$$OK  
  // main code block
  try {    
    set rsEmolumentsSummary = qHandle
    do rsEmolumentsSummary.%Close()    
  }  
  // main error handler
  catch e {    
    // set the return status
    set ReturnStatus = $$$ERROR($$$GeneralError, "Error in " _ ..%ClassName(1) _ ".GetTVRefNosForLicenceNameClose[#][#]"_ e.DisplayString())    
  }  
  // quit the return status
  QUIT ReturnStatus
}
Код: plaintext
1.
Cache for Windows (x86-32) 2010.1 (Build 413) Wed Feb 10 2010 13:42:47 EST.
Windows 7, 64-bit, Visual Studio 2012, vb.net.

Спасибо.
...
Рейтинг: 0 / 0
Custom SQL query & .NET
    #38437093
Фотография DAiMor
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
А ошибки кроме того что пустой вывод еще есть ?
может просто неверно доходит значение до Cache ?

и рекомендую переделать с использования %Library.ResultSet на более современные и более быстрые %ResultSet.SQL или %SQL.Statement

а в вашем коде вообще скорее всего можно обойтись Embeded SQL
...
Рейтинг: 0 / 0
Custom SQL query & .NET
    #38437141
vichka
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
DAiMorА ошибки кроме того что пустой вывод еще есть ?

Ошибок никаких не выдает.


DAiMorможет просто неверно доходит значение до Cache ?

У меня тоже такое подозрение, что неверно доходит значение до Cache. Не знаю как проверить, из .NET выходит все правильно ...

DAiMorа в вашем коде вообще скорее всего можно обойтись Embeded SQL
Наверное так и сделаю...
...
Рейтинг: 0 / 0
Custom SQL query & .NET
    #38437186
Фотография DAiMor
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
vichkaDAiMorможет просто неверно доходит значение до Cache ?

У меня тоже такое подозрение, что неверно доходит значение до Cache. Не знаю как проверить, из .NET выходит все правильно ...
ну это проверить то как раз достаточно просто, залогируйте в глобал те значения которые приходят в Query метод Execute.
...
Рейтинг: 0 / 0
Custom SQL query & .NET
    #38437328
vichka
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Была уверена, что что-то простое, что я упустила и сделала не так!
Так и есть- очередность в добавлении параметров в .NET должна соблюдаться!
Все работает. Всем спасибо.
...
Рейтинг: 0 / 0
5 сообщений из 5, страница 1 из 1
Форумы / Caché, Ensemble, DeepSee, MiniM, IRIS, GT.M [игнор отключен] [закрыт для гостей] / Custom SQL query & .NET
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]