Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ SQL » simple example sqlite ref. not working core console
simple example sqlite ref. not working core console [message #52514] Tue, 15 October 2019 02:47 Go to next message
mtdew3q is currently offline  mtdew3q
Messages: 181
Registered: July 2010
Location: Upstate, NY (near Canada)
Experienced Member

HI all-

Am I doing something wrong with this code?

I am running the most recent nightly build. MinGW with SQLite plug-in.

I tried another type of join too. That one didn't work either. At the end, I will put in a code block the SQLite code that works.

I also added a foreign key statement in the create table for SQLite.

Is there a trick for joining SQLite tables?

Hey guys, I am having bad juju. Today, I got a virus off a mirror that I frequent for code. Wah!
I ran this on my system with nmap, and there are no open ports Smile

thanks,
roboloki

TABLE_(a)
    INT_    (id) PRIMARY_KEY AUTO_INCREMENT
    INT_ (mydate)
END_TABLE
 
TABLE_(b)
    INT     (id) PRIMARY_KEY AUTO_INCREMENT
    INT_    (fk_A) REFERENCES (a)
    STRING_ (mytext, 35) 
END_TABLE


#include <Core/Core.h>
#include <plugin/sqlite3/Sqlite3.h>

using namespace Upp;

#define SCHEMADIALECT <plugin/sqlite3/Sqlite3Schema.h>
#define MODEL <sqliteTest/ailien.sch>
#include "Sql/sch_header.h"
 
 
CONSOLE_APP_MAIN
{
    Sqlite3Session sqlite3;
    if(!sqlite3.Open(ConfigFile("ailien.db3"))) {
        Cout() << "Can't create or open database file\n";
        return;
    }
    
#ifdef _DEBUG
    sqlite3.SetTrace();
#endif

SqlId a("a"), b("b"), fk_A("fk_A"), mydate("mydate"), id("id"), mytext("mytext");
 
    Sql sql(sqlite3);
 Select(id.Of(a), mytext.Of(b))
.From(a)
.InnerJoin(b)
.On(id.Of(a) == fk_A.Of(b))
.Where(id.Of(a) == 2);
    while(sql.Fetch())
        Cout() << sql[0] << ' ' << sql[1] <<'\n'  ;
    
    //Error: Schema join not found ,a,       b (if I used a reference join syntax instead of plain old join)
}


select a.id, b.mytext from a join b
where a.id ==2;
Re: simple example sqlite ref. not working core console [message #52515 is a reply to message #52514] Tue, 15 October 2019 04:26 Go to previous messageGo to next message
mtdew3q is currently offline  mtdew3q
Messages: 181
Registered: July 2010
Location: Upstate, NY (near Canada)
Experienced Member

Hi-

Is sqlexp better supported with PostgreSQL?

I'd like to switch to PostgreSQL if so.

Maybe though I am just doing something spacey.

thanks,
roboloki
Re: simple example sqlite ref. not working core console [message #52516 is a reply to message #52515] Tue, 15 October 2019 05:46 Go to previous messageGo to next message
mtdew3q is currently offline  mtdew3q
Messages: 181
Registered: July 2010
Location: Upstate, NY (near Canada)
Experienced Member

Hi u++,
I'm going to switch to Postgres. That is where the samples in tutorial come from with sqlexp.

If I run an execute, I can do joins in sqlite in native format without sqlexp possibly.

Have cool night.
Roboloki
Re: simple example sqlite ref. not working core console [message #56366 is a reply to message #52514] Sat, 27 February 2021 16:57 Go to previous message
JeyCi is currently offline  JeyCi
Messages: 50
Registered: July 2020
Member
mtdew3q wrote on Tue, 15 October 2019 02:47
Am I doing something wrong with this code?
Is there a trick for joining SQLite tables?

Sql sql(sqlite3);
Select(id.Of(a), mytext.Of(b))
.From(a)
.InnerJoin(b)
.On(id.Of(a) == fk_A.Of(b))
.Where(id.Of(a) == 2);
while(sql.Fetch())
Cout() << sql[0] << ' ' << sql[1] <<'\n' ;

//Error: Schema join not found ,a, b (if I used a reference join syntax instead of plain old join)

it was just an example of unattentiveness while reading SQL Tutorial
- just need to use cursor "sql*" to get then records from recordset while fetching
Sql sql(sqlite3);
sql * Select(id.Of(a), mytext.Of(b))
.From(a)   
.InnerJoin(b)
.On(id.Of(a) == fk_A.Of(b)) 
.Where(id.Of(a) == 2);

the code of topic_starter is working...


Best regards.

[Updated on: Sat, 27 February 2021 17:09]

Report message to a moderator

Previous Topic: with MariaDB (MySql) to capture error with Skylark
Next Topic: Jsonize() in database table structures (S_*) [patch]
Goto Forum:
  


Current Time: Fri Jun 21 21:55:27 CEST 2024

Total time taken to generate the page: 0.00986 seconds