pofider / node-odata-to-sql

Generate SQL from OData in node.js
MIT License
5 stars 4 forks source link

Problem with NULL filter condition #3

Open SlavaUtesinov opened 3 years ago

SlavaUtesinov commented 3 years ago

I tried to use jsreport-mssql-store and I wanted to import export.zip file from current storage to new one. I had two files with same names but located at different folders: root and specific named folder. Script from root folder was not imported due to ignoring of { folder: null } (I suppose, null means root) condition, as a result false duplicate was found with same name but from another folder. Obvious inappropriate warning message "Entity with name "ScriptName" already exists at the root level...." was shown.

This is a problem at filter.js file particular at doFilter function. When condition looks like { columnName: null } it will be ignored due to if (filter[el]) clause. Moreover there is not IS NULL case at all.

module.exports = function doFilter (query, table, filter, entityType) {
  for (var el in filter) {
    if (filter[el]) {
      query = getOperation(el, filter[el])(query, table, el, filter[el], 'where', entityType[el] || entityType)
    }
  }

  return query
}

Actual behavior - generated query looks like: select * from table. Expected behavior - generated query has to look like: select * from table where columnName is null.

pofider commented 3 years ago

Thank you for the issue. It would be probably better in jsreport/jsreport repo but let's continue here.

I started jsreport with jsreport-mssql-store, created templates as you describe, exported, but don't see any issue during the import. See the gif. cap

Here is the data I import export (5).zip

How does it behave for you?

SlavaUtesinov commented 3 years ago

Sorry, that I not attached file as an example (I have some security restrictions) Yes, it works with your export.zip, but there is one detail - files should have different types, for example one of them is script and another one is template but all of them still have same names. Also I got this kind of message after not successful import:

Import failed: Unable to insert an entity (scripts) "/templ" during the import: Error: Entity with name "templ" already exists at the root level. Error: Import failed: Unable to insert an entity (scripts) "/templ" during the import: Error: Entity with name "templ" already exists at the root level.
    at module.exports (c:\Work\jsreport\node_modules\jsreport-core\lib\util\createError.js:11:13)
    at Reporter.createError (c:\Work\jsreport\node_modules\jsreport-core\lib\reporter.js:332:12)
    at validateDuplicatedName (c:\Work\jsreport\node_modules\jsreport-core\lib\folders\validateDuplicatedName.js:89:20)
From previous event:
    at T.j [as _captureStackTrace] (http://localhost:5488/studio/assets/client.721def965dc7b7e2a98c.js:1:1059825)
    at T._resolveFromExecutor (http://localhost:5488/studio/assets/client.721def965dc7b7e2a98c.js:1:1089522)
    at new T (http://localhost:5488/studio/assets/client.721def965dc7b7e2a98c.js:1:1082760)
    at Object.d.forEach.h.<computed> [as post] (http://localhost:5488/studio/assets/client.721def965dc7b7e2a98c.js:1:818620)
    at Object._.methods.forEach.n.API.<computed> [as post] (http://localhost:5488/studio/assets/client.721def965dc7b7e2a98c.js:83:287757)
    at ImportModal._callee2$ (http://localhost:5488/studio/assets/studio-extensions.client.6a5cad9dde67859271c1.js:1099:53)
    at m (http://localhost:5488/studio/assets/client.721def965dc7b7e2a98c.js:39:219330)
    at Generator._invoke (http://localhost:5488/studio/assets/client.721def965dc7b7e2a98c.js:39:219083)
    at Generator.forEach.e.<computed> [as next] (http://localhost:5488/studio/assets/client.721def965dc7b7e2a98c.js:39:219510)
    at step (http://localhost:5488/studio/assets/studio-extensions.client.6a5cad9dde67859271c1.js:842:191)
    at http://localhost:5488/studio/assets/studio-extensions.client.6a5cad9dde67859271c1.js:842:437
    at new Promise (<anonymous>)
    at ImportModal.<anonymous> (http://localhost:5488/studio/assets/studio-extensions.client.6a5cad9dde67859271c1.js:842:99)
    at ImportModal._import (http://localhost:5488/studio/assets/studio-extensions.client.6a5cad9dde67859271c1.js:1146:22)
    at onClick (http://localhost:5488/studio/assets/studio-extensions.client.6a5cad9dde67859271c1.js:1379:39)
    at Object.s (http://localhost:5488/studio/assets/client.721def965dc7b7e2a98c.js:55:458)
    at f (http://localhost:5488/studio/assets/client.721def965dc7b7e2a98c.js:55:601)
    at http://localhost:5488/studio/assets/client.721def965dc7b7e2a98c.js:55:747
    at v (http://localhost:5488/studio/assets/client.721def965dc7b7e2a98c.js:55:833)
    at at (http://localhost:5488/studio/assets/client.721def965dc7b7e2a98c.js:55:16338)
    at ot (http://localhost:5488/studio/assets/client.721def965dc7b7e2a98c.js:55:16171)
    at st (http://localhost:5488/studio/assets/client.721def965dc7b7e2a98c.js:55:16527)
pofider commented 3 years ago

Thank you. It still didn't fail for me on import but I get your point. I believe I fixed the problem in this commit https://github.com/pofider/node-odata-to-sql/commit/08af9303dfbb9e22d0e5df0bd8aee6231a31b5c3