Simon,

On Fri, Apr 26, 2013 at 5:49 PM, Simon Slavin <slav...@bigfraud.org> wrote:

>
> On 27 Apr 2013, at 12:27am, Igor Korot <ikoro...@gmail.com> wrote:
>
> > And here is the log from the console:
> >
> > SQLite version 3.7.14 2012-09-03 15:42:36
> > Enter ".help" for instructions
> > Enter SQL statements terminated with a ";"
> > sqlite> INSERT INTO playersdrafted VALUES( 125, 1, ( SELECT ownerid FROM
> > owners WHERE ownername = "Team 1" AND id = 1 ), 38, 1, "OF" );
> > sqlite> SELECT * FROM playersdrafted;
> > 125|1|53|38.0|1|OF
> >
> > I can give a remote access to solve this mistery...
>
> Literal strings in SQLite should be in single quotes, not double quotes.
>  So first change that and see if that fixes it.
>

This code

<code>
                int res;
                query = wxString::Format( "INSERT INTO playersdrafted
VALUES( %d, %d, ( SELECT ownerid FROM owners WHERE ownername = \'%s\' AND
id = %d ), %d, %d, \'%s\' );", player.GetPlayerId(), leagueId,
const_cast<CPlayer &>( player ).GetOwner(), leagueId,
player.GetAmountPaid(), player.GetDraftOrder(), const_cast<CPlayer &>(
player ).GetDraftedPosition() );
                char *error;
                res = sqlite3_exec( m_handle, query, 0, 0, &error );
                if( res != SQLITE_OK )
                {
                    wxMessageBox( wxString::Format( "Error inserting owners
for the new league: %s", error ) );
                    delete error;
                }
                else
                {
                    res = sqlite3_prepare_v2( m_handle, "SELECT * FROM
playersdrafted;", -1, &stmt, 0 );
                    if( res == SQLITE_OK )
                    {
                        res = sqlite3_step( stmt );
                        if( res == SQLITE_ROW )
                        {
                            int playerid = sqlite3_column_int( stmt, 0 );
                            int leagueid = sqlite3_column_int( stmt, 1 );
                        }
                    }
                }
</code>

executes fine. No problem at all. Under the debugger I can even see the
proper values of playerid and leagueid.
But on the next run the retrieval of this record is not done as the table
does not have it.
And trying to query table in the console sqlite3 does not yield any results.


> If not ...
>
> show us the results of the command .schema playersdrafted
>
> show is the results of "SELECT * FROM playersdrafted;" /before/ you do the
> INSERT.
>

Here it is:

SQLite version 3.7.14 2012-09-03 15:42:36
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .schema playersdrafted
CREATE TABLE playersdrafted(playerid integer, id ineteger, ownerid integer,
draftprice double, draftorder integer, draftposition char(2), foreign
key(playerid) references players(playerid),foreign key(id) references
leagues(id), foreign key (ownerid) references owners(ownerid));
CREATE INDEX id_playerid ON playersdrafted(playerid,id);
sqlite> SELECT * FROM playersdrafted;
sqlite>


>
> and also the results of
>
> SELECT ownerid FROM owners WHERE ownername = 'Team 1' AND id = 1
>

and here

sqlite> SELECT ownerid FROM owners WHERE ownername = 'Team 1' AND id = 1;
53
sqlite>

Thank you.


> Simon.
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to