Yes, NULL is zero, is it?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Yes, NULL is zero, is it?

papa
This is not a SQLite3 problem, it shows to be a MinGW
(mingw32/7.1.0/...)  -> Target: 64bit, however, I just wanted to know if
anyone here has experience the same problem.

     std::string sql_statement_request;
     ...
     rc = sqlite3_prepare_v2(db,
             sql_statement_request.data(),
             -1,
             &binary_sql_statement,
             NULL);
     std::cout << binary_sql_statement << std::endl; // ==> 0 (zero)
         if (binary_sql_statement != NULL) {
             //do something //==> Does not display anything
         }

Thanks in advance

--
ArbolOne.ca
Using Fire Fox and Thunderbird.
ArbolOne is composed of students and volunteers dedicated to providing free services to charitable organizations.
ArbolOne on Java Development in progress [ í ]

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Yes, NULL is zero, is it?

Igor Tandetnik-2
On 8/31/2017 9:43 PM, Papa wrote:

> This is not a SQLite3 problem, it shows to be a MinGW (mingw32/7.1.0/...)  -> Target: 64bit, however, I just wanted to know if anyone here has experience the same problem.
>
>      std::string sql_statement_request;
>      ...
>      rc = sqlite3_prepare_v2(db,
>              sql_statement_request.data(),
>              -1,
>              &binary_sql_statement,
>              NULL);
>      std::cout << binary_sql_statement << std::endl; // ==> 0 (zero)

Well, apparently,  sqlite3_prepare_v2 call failed. Figure out why. I'm not sure I quite grasp the nature of your difficulty.
--
Igor Tandetnik

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Yes, NULL is zero, is it?

Keith Medcalf
In reply to this post by papa

Works perfectly fine for me with gcc 7.1.0.

Why do you think that a pointer to an arbitrary data block can be sent to cout?

What result are you expecting?


---
The fact that there's a Highway to Hell but only a Stairway to Heaven says a lot about anticipated traffic volume.


>-----Original Message-----
>From: sqlite-users [mailto:sqlite-users-
>[hidden email]] On Behalf Of Papa
>Sent: Thursday, 31 August, 2017 19:43
>To: SQLite Mailing List
>Subject: [sqlite] Yes, NULL is zero, is it?
>
>This is not a SQLite3 problem, it shows to be a MinGW
>(mingw32/7.1.0/...)  -> Target: 64bit, however, I just wanted to know
>if
>anyone here has experience the same problem.
>
>     std::string sql_statement_request;
>     ...
>     rc = sqlite3_prepare_v2(db,
>             sql_statement_request.data(),
>             -1,
>             &binary_sql_statement,
>             NULL);
>     std::cout << binary_sql_statement << std::endl; // ==> 0 (zero)
>         if (binary_sql_statement != NULL) {
>             //do something //==> Does not display anything
>         }
>
>Thanks in advance
>
>--
>ArbolOne.ca
>Using Fire Fox and Thunderbird.
>ArbolOne is composed of students and volunteers dedicated to
>providing free services to charitable organizations.
>ArbolOne on Java Development in progress [ í ]
>
>_______________________________________________
>sqlite-users mailing list
>[hidden email]
>http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users



_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Yes, NULL is zero, is it?

Igor Tandetnik-2
On 8/31/2017 10:20 PM, Keith Medcalf wrote:
> Why do you think that a pointer to an arbitrary data block can be sent to cout?

Because cout provides operator<<(void*)
--
Igor Tandetnik

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Yes, NULL is zero, is it?

Keith Medcalf

Ah.  Ok.  So it prints the pointer value.  Thanks.


---
The fact that there's a Highway to Hell but only a Stairway to Heaven says a lot about anticipated traffic volume.


>-----Original Message-----
>From: sqlite-users [mailto:sqlite-users-
>[hidden email]] On Behalf Of Igor Tandetnik
>Sent: Thursday, 31 August, 2017 20:32
>To: [hidden email]
>Subject: Re: [sqlite] Yes, NULL is zero, is it?
>
>On 8/31/2017 10:20 PM, Keith Medcalf wrote:
>> Why do you think that a pointer to an arbitrary data block can be
>sent to cout?
>
>Because cout provides operator<<(void*)
>--
>Igor Tandetnik
>
>_______________________________________________
>sqlite-users mailing list
>[hidden email]
>http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users



_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Yes, NULL is zero, is it?

J Decker
That and MinGW defines NULL as 0 if C++ and not void(*)

#ifndef NULL
#ifdef __cplusplus
#ifndef _WIN64
#define NULL 0
#else
#define NULL 0LL
#endif  /* W64 */
#else
#define NULL ((void *)0)
#endif
#endif


On Thu, Aug 31, 2017 at 7:34 PM, Keith Medcalf <[hidden email]> wrote:

>
> Ah.  Ok.  So it prints the pointer value.  Thanks.
>
>
> ---
> The fact that there's a Highway to Hell but only a Stairway to Heaven says
> a lot about anticipated traffic volume.
>
>
> >-----Original Message-----
> >From: sqlite-users [mailto:sqlite-users-
> >[hidden email]] On Behalf Of Igor Tandetnik
> >Sent: Thursday, 31 August, 2017 20:32
> >To: [hidden email]
> >Subject: Re: [sqlite] Yes, NULL is zero, is it?
> >
> >On 8/31/2017 10:20 PM, Keith Medcalf wrote:
> >> Why do you think that a pointer to an arbitrary data block can be
> >sent to cout?
> >
> >Because cout provides operator<<(void*)
> >--
> >Igor Tandetnik
> >
> >_______________________________________________
> >sqlite-users mailing list
> >[hidden email]
> >http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
>
>
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Yes, NULL is zero, is it?

Simon Slavin-3


On 1 Sep 2017, at 4:49am, J Decker <[hidden email]> wrote:

> That and MinGW defines NULL as 0 if C++ and not void(*)

Oh Gawd, the old C/C++ problem.

Some compilers and IDEs, by default, compile ".c" files as if they are C++.  This leads to all sorts of weird behaviour including both compiler error messages and programs which compile fine then misbehave while running.  NULL is one of the things C and C++ do differently.

I’m not saying this is the problem here, merely that it deserves a mention.

Simon.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Yes, NULL is zero, is it?

Igor Tandetnik-2
In reply to this post by J Decker
On 8/31/2017 11:49 PM, J Decker wrote:
> That and MinGW defines NULL as 0 if C++ and not void(*)

I don't see how this is relevant. The OP isn't doing  cout << NULL , they are doing cout << binary_sql_statement , where binary_sql_statement is presumably a sqlite_statement* - definitely a pointer.
--
Igor Tandetnik

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Yes, NULL is zero, is it?

Cory Nelson
In reply to this post by Simon Slavin-3
On Thu, Aug 31, 2017 at 11:01 PM, Simon Slavin <[hidden email]> wrote:

>
>
> On 1 Sep 2017, at 4:49am, J Decker <[hidden email]> wrote:
>
>> That and MinGW defines NULL as 0 if C++ and not void(*)
>
> Oh Gawd, the old C/C++ problem.
>
> Some compilers and IDEs, by default, compile ".c" files as if they are C++.  This leads to all sorts of weird behaviour including both compiler error messages and programs which compile fine then misbehave while running.  NULL is one of the things C and C++ do differently.
>
> I’m not saying this is the problem here, merely that it deserves a mention.

If you're in any slightly modern compiler, always use nullptr instead of NULL.

--
Cory Nelson
http://int64.org
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Yes, NULL is zero, is it?

Keith Medcalf

It would be nice to know what return-code is.  One ought to be checking the return code and if-and-only-if the return code is SQLITE_OK was the prepare successful.  

Without knowing the value of the return-code, examining the statement pointer is only worthwhile after determinine that the prepare was successful ... and looking at the returned statement pointer is not a substitute for checking the return code.

if-and-only-if the return code is demonstrably SQLITE_OK AND the statement pointer is NULL/0 AND the statement is not a comment or other no-op, is there anything meaningful to be derived from the fact that the statement pointer is 0/NULL.

Only by seeing all of the input SQL statement, the return code, and statement pointer value is it possible to even posit that there is anything wrong at all.

---
The fact that there's a Highway to Hell but only a Stairway to Heaven says a lot about anticipated traffic volume.


>-----Original Message-----
>From: sqlite-users [mailto:sqlite-users-
>[hidden email]] On Behalf Of Cory Nelson
>Sent: Thursday, 31 August, 2017 22:42
>To: SQLite mailing list
>Subject: Re: [sqlite] Yes, NULL is zero, is it?
>
>On Thu, Aug 31, 2017 at 11:01 PM, Simon Slavin <[hidden email]>
>wrote:
>>
>>
>> On 1 Sep 2017, at 4:49am, J Decker <[hidden email]> wrote:
>>
>>> That and MinGW defines NULL as 0 if C++ and not void(*)
>>
>> Oh Gawd, the old C/C++ problem.
>>
>> Some compilers and IDEs, by default, compile ".c" files as if they
>are C++.  This leads to all sorts of weird behaviour including both
>compiler error messages and programs which compile fine then
>misbehave while running.  NULL is one of the things C and C++ do
>differently.
>>
>> I’m not saying this is the problem here, merely that it deserves a
>mention.
>
>If you're in any slightly modern compiler, always use nullptr instead
>of NULL.
>
>--
>Cory Nelson
>http://int64.org
>_______________________________________________
>sqlite-users mailing list
>[hidden email]
>http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users



_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Yes, NULL is zero, is it?

Olivier Mascia
In reply to this post by papa
> Le 1 sept. 2017 à 03:43, Papa <[hidden email]> a écrit :
>
> std::string sql_statement_request;
>     ...
>     rc = sqlite3_prepare_v2(db,
>             sql_statement_request.data(),
>             -1,

The (calling program) bug starts here above.
sql_statement_request.data() is not guaranteed to be zero-terminated (and generally isn't).

You either have to do:

>     rc = sqlite3_prepare_v2(db,
>             sql_statement_request.c_str(),
>             -1,

Or

>     rc = sqlite3_prepare_v2(db,
>             sql_statement_request.data(),
>             (int)sql_statement_request.size(),

Whatever else might happen to be wrong with this query, chances are SQLite parses a longer string than you intended and might fail with syntax errors, which would explain you get a null statement pointer.

--
Best Regards, Meilleures salutations, Met vriendelijke groeten,
Olivier Mascia, http://integral.software



_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Yes, NULL is zero, is it?

Dominique Devienne
On Fri, Sep 1, 2017 at 9:08 AM, Olivier Mascia <[hidden email]> wrote:
>
> The (calling program) bug starts here above.
> sql_statement_request.data() is not guaranteed to be zero-terminated (and
> generally isn't).
>

FWIW, it is since std C++11, i.e. .data() and .c_str() are equivalent going
forward [1].

It wasn't before, of course, you are right, in pre-C++11 situations.

Note that in C++17 and later, std::string implicitly converts [2] to the
new std::string_view [3],
whose .data() member [4] does behave like the old pre-C++11 .data() of
std::string [1]. --DD

[1] http://en.cppreference.com/w/cpp/string/basic_string/data
[2]
http://en.cppreference.com/w/cpp/string/basic_string/operator_basic_string_view
[3] http://en.cppreference.com/w/cpp/string/basic_string_view
[4] http://en.cppreference.com/w/cpp/string/basic_string_view/data
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Yes, NULL is zero, is it?

papa
In reply to this post by papa
Thanks everyone for your input.
I am sorry, the error was cause by human error, i.e. my mistake :-P


On 2017-08-31 9:43 PM, Papa wrote:

> This is not a SQLite3 problem, it shows to be a MinGW
> (mingw32/7.1.0/...)  -> Target: 64bit, however, I just wanted to know
> if anyone here has experience the same problem.
>
>     std::string sql_statement_request;
>     ...
>     rc = sqlite3_prepare_v2(db,
>             sql_statement_request.data(),
>             -1,
>             &binary_sql_statement,
>             NULL);
>     std::cout << binary_sql_statement << std::endl; // ==> 0 (zero)
>         if (binary_sql_statement != NULL) {
>             //do something //==> Does not display anything
>         }
>
> Thanks in advance
>

--
ArbolOne.ca
Using Fire Fox and Thunderbird.
ArbolOne is composed of students and volunteers dedicated to providing free services to charitable organizations.
ArbolOne on Java Development in progress [ í ]

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users