5

I am trying to check whether two geographic objects intersect and remove the overlapping parts (not doing this part in the code segment below). Please find the code below. It gives me error

Cannot call methods on bit.

I am using mssql library and using node 10. I cannot find anything regarding this error. I want to know if this is a code error or some issue with mssql library. If it is then how can I solve this issue?

*****UPDATE****** It only gives this error for STIntersects(), works fine for STIntersection() and STDifference.

const sql = require('mssql');
        let path1 = `geography::STGeomFromText('POLYGON((-122.358 47.653, -122.348 47.649, -122.348 47.658, -122.358 47.658, -122.358 47.653))', 4326).MakeValid()`;
        let path2 = `geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656)', 4326).MakeValid()`;
        let query = `SELECT ${path1}.STIntersects(${path2}).ToString();
        SELECT ${path1}.STIntersection(${path2}).ToString();`;
        let dbConfig = {
            user: 'username',
            password: 'password',
            server: 'localhost',
            database: 'db_name',
            port: port,
            connectionTimeout: 30000,
            requestTimeout: 180000,
            max: 15,
            min: 3,
            idleTimeoutMillis: 30000
        };

        sql.connect(dbConfig, err => {
            if (err)
                throw err;
            console.log('Success');
            queryExecuter();

        });

        let queryExecuter = async () => {
            try {
                let request = new sql.Request();
                let result1 = await request.query(query)

                console.log(result1)
            } catch (err) {
                console.log(err)
                // ... error checks
            }
        }

        sql.on('error', err => {
            console.log(err)
            // ... error handler
        })
Safeer Raees
  • 400
  • 2
  • 11
  • 1
    Well, yeah. `.STIntersects()` returns a `bit`, and `bit` has no methods (T-SQL is not an object-oriented language; methods are the exception rather than the rule). This error is returned by the server itself. Remove the `.ToString()` from the query. – Jeroen Mostert Oct 03 '19 at 11:45
  • Ahhhh! thank you so much, that worked. I don't know what I was thinking. – Safeer Raees Oct 03 '19 at 11:50

1 Answers1

0

Basically, I was just trying to call ToString() function on a bit which is return type of STIntersects(), which is not supported/required in SQL. Thank you @Jeroen Mostert for clearing that ambiguity out.

Safeer Raees
  • 400
  • 2
  • 11