# Constant declaration in modules (SQLite)

**URL:** https://discourse.julialang.org/t/constant-declaration-in-modules-sqlite/14801
**Category:** New to Julia
**Tags:** sqlite, constants
**Created:** [September 11, 2018, 6:28am UTC](https://discourse.julialang.org/t/constant-declaration-in-modules-sqlite/14801 "2018-09-11T06:28:18Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![moesphere](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moesphere/32/3348_2.png) [@moesphere](https://discourse.julialang.org/u/moesphere)
#### Post date: [September 11, 2018, 6:28am UTC](https://discourse.julialang.org/t/constant-declaration-in-modules-sqlite/14801/1 "2018-09-11T06:28:18Z")

</div>

Following minimal code worked fine with julia 0.6.4, but does not work with 1.0.0.

Defining a minimal module:

```julia
module TestModule

using SQLite

fp = ""
const db = SQLite.DB(fp)

end

```

Loading the module and execute operations:

```julia
using TestModule
SQLite.query(TestModule.db, "SELECT ROWID,* FROM " * "table1")
SQLite.query(SQLite.DB(""), "SELECT ROWID,* FROM " * "table1")

```

Following exceptions are thrown:

```julia
SQLite.SQLiteException("Cannot operate on null pointer")
SQLite.SQLiteException("no such table: table1")

```

Hence, somehow the constant definition within the module does not work as it did in 0.6.4. Any ideas how I can fix that?

---

<div class="post-metadata">

### Author: ![Simon\_Bolland](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simon_bolland/32/8920_2.png) [@Simon\_Bolland](https://discourse.julialang.org/u/Simon_Bolland)
#### Post date: [September 11, 2018, 8:29am UTC](https://discourse.julialang.org/t/constant-declaration-in-modules-sqlite/14801/2 "2018-09-11T08:29:18Z")

</div>

Shouldn’t it be

> SQLite.query(TestModule.db, "SELECT ROWID,\* FROM " \* “table1”)

You don’t include code to create/populate table1, but creating one with a couple of int columns and inserting a couple of rows gives me

```julia
julia> SQLite.query(TestModule.db, "SELECT ROWID,* FROM " * "table1")
2×3 DataFrame
│ Row │ rowid │ i │ j │
├─────┼───────┼───┼───┤
│ 1 │ 1 │ 1 │ 2 │
│ 2 │ 2 │ 2 │ 3 │

julia> versioninfo()
Julia Version 1.0.0
Commit 5d4eaca0c9 (2018-08-08 20:58 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 4
julia> Pkg.installed()["SQLite"]
v"0.6.0"

```

---

<div class="post-metadata">

### Author: ![moesphere](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moesphere/32/3348_2.png) [@moesphere](https://discourse.julialang.org/u/moesphere)
#### Post date: [September 11, 2018, 8:36am UTC](https://discourse.julialang.org/t/constant-declaration-in-modules-sqlite/14801/3 "2018-09-11T08:36:39Z")

</div>

Thanks for the answer! Your are right: There is no table1 as there is also no database. However, the point I was trying to stress out, is the fact, that the constant declaration in the module does not seem to work in v1.0.0. In v0.6.4. it worked though.  
Assuming there is a database with table1 the first query will still give you the “Cannot operate on null pointer” error, whereas the second query will return table1 of the database. My question is therefore why does the constant declaration not work as in v0.6.4., is it an SQLite problem and how can it be fixed?

---

<div class="post-metadata">

### Author: ![Simon\_Bolland](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simon_bolland/32/8920_2.png) [@Simon\_Bolland](https://discourse.julialang.org/u/Simon_Bolland)
#### Post date: [September 11, 2018, 8:40am UTC](https://discourse.julialang.org/t/constant-declaration-in-modules-sqlite/14801/4 "2018-09-11T08:40:25Z")

</div>

In the example posted you create a const TestModule.db then try to use SQLite.db

---

<div class="post-metadata">

### Author: ![moesphere](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moesphere/32/3348_2.png) [@moesphere](https://discourse.julialang.org/u/moesphere)
#### Post date: [September 11, 2018, 8:49am UTC](https://discourse.julialang.org/t/constant-declaration-in-modules-sqlite/14801/5 "2018-09-11T08:49:25Z")

</div>

It’s corrected now.

---

<div class="post-metadata">

### Author: ![Simon\_Bolland](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simon_bolland/32/8920_2.png) [@Simon\_Bolland](https://discourse.julialang.org/u/Simon_Bolland)
#### Post date: [September 11, 2018, 9:00am UTC](https://discourse.julialang.org/t/constant-declaration-in-modules-sqlite/14801/6 "2018-09-11T09:00:45Z")

</div>

To clarify, do you mean it’s working now or that you’ve amended the example (and if so, do you still get the same exception)

---

<div class="post-metadata">

### Author: ![moesphere](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moesphere/32/3348_2.png) [@moesphere](https://discourse.julialang.org/u/moesphere)
#### Post date: [September 11, 2018, 9:01am UTC](https://discourse.julialang.org/t/constant-declaration-in-modules-sqlite/14801/7 "2018-09-11T09:01:31Z")

</div>

Precompiling seems to be causing the problem.

Putting ` __precompile__ (false)` at the beginning of the module, solves the issue at least for now.

---

<div class="post-metadata">

### Author: ![moesphere](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moesphere/32/3348_2.png) [@moesphere](https://discourse.julialang.org/u/moesphere)
#### Post date: [September 11, 2018, 9:17am UTC](https://discourse.julialang.org/t/constant-declaration-in-modules-sqlite/14801/8 "2018-09-11T09:17:14Z")

</div>

Better using the ` __init__ ()` function, see [here](https://docs.julialang.org/en/stable/manual/modules/#Module-initialization-and-precompilation-1).
