Sqlite3 with Python returning extra data










0















I am working on a personal project to learn using SQLite3 with Python by creating a dvd inventory application. I have had some success with my SQLite related functions, which are in a library file, and intended to be called from other portions of the application.



I am running into a problem with extraneous data being returned in a query, in this case, the same data twice.



I am testing a function that simply queries a table, and returns all its values. If I run that function from a call within the library file it resides in, it works properly, but if I call it from an external file that imports the library file, it returns the data twice, and I am unsure why.



The function is as follows:



def query_all():
con = db_connect()
cur = con.cursor()
cur.execute('''SELECT film_id, film_name, film_genre, date_added FROM
film_inv''')
all_rows = cur.fetchall()
for row in all_rows:
print('0 : 1, 2, 3'.format(row[0], row[1], row[2], row[3]))
con.close()


When run from within the library file, it returns proper results as:



1 : Star Wars, Comedy, 2018-11-15 12:23:28
2 : Titanic, Drama, 2018-11-15 12:28:55
3 : Cars, Family, 2018-11-15 12:29:18
4 : Christmas Vacation, Holiday, 2018-11-15 12:37:59
6 : Cinderella, Family, 2018-11-15 12:43:13

Process finished with exit code 0


When called via an external file, it returns the results twice:



try:
pydvd_utils.query_all()
except Exception as e:
print(e)

1 : Star Wars, Comedy, 2018-11-15 12:23:28
2 : Titanic, Drama, 2018-11-15 12:28:55
3 : Cars, Family, 2018-11-15 12:29:18
4 : Christmas Vacation, Holiday, 2018-11-15 12:37:59
6 : Cinderella, Family, 2018-11-15 12:43:13
1 : Star Wars, Comedy, 2018-11-15 12:23:28
2 : Titanic, Drama, 2018-11-15 12:28:55
3 : Cars, Family, 2018-11-15 12:29:18
4 : Christmas Vacation, Holiday, 2018-11-15 12:37:59
6 : Cinderella, Family, 2018-11-15 12:43:13

Process finished with exit code 0


The external file, query_all.py, is simple, only calling the function:



#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import pydvd_utils

try:
pydvd_utils.query_all()
except Exception as e:
print(e)









share|improve this question
























  • The external file must be calling query_all() twice.

    – John Gordon
    Nov 15 '18 at 18:20











  • The external file is just a single call to that function. Its full contents are: #!/usr/bin/env python3 # -*- coding: utf-8 -*- import pydvd_utils try: pydvd_utils.query_all() except Exception as e: print(e)

    – 8675309
    Nov 15 '18 at 18:22












  • Then the external file itself is being called twice. Show us how it's called.

    – John Gordon
    Nov 15 '18 at 18:24











  • I'm calling the file directly from the command prompt via D:OneDrivesourcepydvd>python query_all.py

    – 8675309
    Nov 15 '18 at 18:36











  • Edit your Question and show the __main__ entry point.

    – stovfl
    Nov 15 '18 at 18:45















0















I am working on a personal project to learn using SQLite3 with Python by creating a dvd inventory application. I have had some success with my SQLite related functions, which are in a library file, and intended to be called from other portions of the application.



I am running into a problem with extraneous data being returned in a query, in this case, the same data twice.



I am testing a function that simply queries a table, and returns all its values. If I run that function from a call within the library file it resides in, it works properly, but if I call it from an external file that imports the library file, it returns the data twice, and I am unsure why.



The function is as follows:



def query_all():
con = db_connect()
cur = con.cursor()
cur.execute('''SELECT film_id, film_name, film_genre, date_added FROM
film_inv''')
all_rows = cur.fetchall()
for row in all_rows:
print('0 : 1, 2, 3'.format(row[0], row[1], row[2], row[3]))
con.close()


When run from within the library file, it returns proper results as:



1 : Star Wars, Comedy, 2018-11-15 12:23:28
2 : Titanic, Drama, 2018-11-15 12:28:55
3 : Cars, Family, 2018-11-15 12:29:18
4 : Christmas Vacation, Holiday, 2018-11-15 12:37:59
6 : Cinderella, Family, 2018-11-15 12:43:13

Process finished with exit code 0


When called via an external file, it returns the results twice:



try:
pydvd_utils.query_all()
except Exception as e:
print(e)

1 : Star Wars, Comedy, 2018-11-15 12:23:28
2 : Titanic, Drama, 2018-11-15 12:28:55
3 : Cars, Family, 2018-11-15 12:29:18
4 : Christmas Vacation, Holiday, 2018-11-15 12:37:59
6 : Cinderella, Family, 2018-11-15 12:43:13
1 : Star Wars, Comedy, 2018-11-15 12:23:28
2 : Titanic, Drama, 2018-11-15 12:28:55
3 : Cars, Family, 2018-11-15 12:29:18
4 : Christmas Vacation, Holiday, 2018-11-15 12:37:59
6 : Cinderella, Family, 2018-11-15 12:43:13

Process finished with exit code 0


The external file, query_all.py, is simple, only calling the function:



#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import pydvd_utils

try:
pydvd_utils.query_all()
except Exception as e:
print(e)









share|improve this question
























  • The external file must be calling query_all() twice.

    – John Gordon
    Nov 15 '18 at 18:20











  • The external file is just a single call to that function. Its full contents are: #!/usr/bin/env python3 # -*- coding: utf-8 -*- import pydvd_utils try: pydvd_utils.query_all() except Exception as e: print(e)

    – 8675309
    Nov 15 '18 at 18:22












  • Then the external file itself is being called twice. Show us how it's called.

    – John Gordon
    Nov 15 '18 at 18:24











  • I'm calling the file directly from the command prompt via D:OneDrivesourcepydvd>python query_all.py

    – 8675309
    Nov 15 '18 at 18:36











  • Edit your Question and show the __main__ entry point.

    – stovfl
    Nov 15 '18 at 18:45













0












0








0








I am working on a personal project to learn using SQLite3 with Python by creating a dvd inventory application. I have had some success with my SQLite related functions, which are in a library file, and intended to be called from other portions of the application.



I am running into a problem with extraneous data being returned in a query, in this case, the same data twice.



I am testing a function that simply queries a table, and returns all its values. If I run that function from a call within the library file it resides in, it works properly, but if I call it from an external file that imports the library file, it returns the data twice, and I am unsure why.



The function is as follows:



def query_all():
con = db_connect()
cur = con.cursor()
cur.execute('''SELECT film_id, film_name, film_genre, date_added FROM
film_inv''')
all_rows = cur.fetchall()
for row in all_rows:
print('0 : 1, 2, 3'.format(row[0], row[1], row[2], row[3]))
con.close()


When run from within the library file, it returns proper results as:



1 : Star Wars, Comedy, 2018-11-15 12:23:28
2 : Titanic, Drama, 2018-11-15 12:28:55
3 : Cars, Family, 2018-11-15 12:29:18
4 : Christmas Vacation, Holiday, 2018-11-15 12:37:59
6 : Cinderella, Family, 2018-11-15 12:43:13

Process finished with exit code 0


When called via an external file, it returns the results twice:



try:
pydvd_utils.query_all()
except Exception as e:
print(e)

1 : Star Wars, Comedy, 2018-11-15 12:23:28
2 : Titanic, Drama, 2018-11-15 12:28:55
3 : Cars, Family, 2018-11-15 12:29:18
4 : Christmas Vacation, Holiday, 2018-11-15 12:37:59
6 : Cinderella, Family, 2018-11-15 12:43:13
1 : Star Wars, Comedy, 2018-11-15 12:23:28
2 : Titanic, Drama, 2018-11-15 12:28:55
3 : Cars, Family, 2018-11-15 12:29:18
4 : Christmas Vacation, Holiday, 2018-11-15 12:37:59
6 : Cinderella, Family, 2018-11-15 12:43:13

Process finished with exit code 0


The external file, query_all.py, is simple, only calling the function:



#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import pydvd_utils

try:
pydvd_utils.query_all()
except Exception as e:
print(e)









share|improve this question
















I am working on a personal project to learn using SQLite3 with Python by creating a dvd inventory application. I have had some success with my SQLite related functions, which are in a library file, and intended to be called from other portions of the application.



I am running into a problem with extraneous data being returned in a query, in this case, the same data twice.



I am testing a function that simply queries a table, and returns all its values. If I run that function from a call within the library file it resides in, it works properly, but if I call it from an external file that imports the library file, it returns the data twice, and I am unsure why.



The function is as follows:



def query_all():
con = db_connect()
cur = con.cursor()
cur.execute('''SELECT film_id, film_name, film_genre, date_added FROM
film_inv''')
all_rows = cur.fetchall()
for row in all_rows:
print('0 : 1, 2, 3'.format(row[0], row[1], row[2], row[3]))
con.close()


When run from within the library file, it returns proper results as:



1 : Star Wars, Comedy, 2018-11-15 12:23:28
2 : Titanic, Drama, 2018-11-15 12:28:55
3 : Cars, Family, 2018-11-15 12:29:18
4 : Christmas Vacation, Holiday, 2018-11-15 12:37:59
6 : Cinderella, Family, 2018-11-15 12:43:13

Process finished with exit code 0


When called via an external file, it returns the results twice:



try:
pydvd_utils.query_all()
except Exception as e:
print(e)

1 : Star Wars, Comedy, 2018-11-15 12:23:28
2 : Titanic, Drama, 2018-11-15 12:28:55
3 : Cars, Family, 2018-11-15 12:29:18
4 : Christmas Vacation, Holiday, 2018-11-15 12:37:59
6 : Cinderella, Family, 2018-11-15 12:43:13
1 : Star Wars, Comedy, 2018-11-15 12:23:28
2 : Titanic, Drama, 2018-11-15 12:28:55
3 : Cars, Family, 2018-11-15 12:29:18
4 : Christmas Vacation, Holiday, 2018-11-15 12:37:59
6 : Cinderella, Family, 2018-11-15 12:43:13

Process finished with exit code 0


The external file, query_all.py, is simple, only calling the function:



#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import pydvd_utils

try:
pydvd_utils.query_all()
except Exception as e:
print(e)






python python-3.x sqlite3






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 19:10







8675309

















asked Nov 15 '18 at 18:13









86753098675309

45117




45117












  • The external file must be calling query_all() twice.

    – John Gordon
    Nov 15 '18 at 18:20











  • The external file is just a single call to that function. Its full contents are: #!/usr/bin/env python3 # -*- coding: utf-8 -*- import pydvd_utils try: pydvd_utils.query_all() except Exception as e: print(e)

    – 8675309
    Nov 15 '18 at 18:22












  • Then the external file itself is being called twice. Show us how it's called.

    – John Gordon
    Nov 15 '18 at 18:24











  • I'm calling the file directly from the command prompt via D:OneDrivesourcepydvd>python query_all.py

    – 8675309
    Nov 15 '18 at 18:36











  • Edit your Question and show the __main__ entry point.

    – stovfl
    Nov 15 '18 at 18:45

















  • The external file must be calling query_all() twice.

    – John Gordon
    Nov 15 '18 at 18:20











  • The external file is just a single call to that function. Its full contents are: #!/usr/bin/env python3 # -*- coding: utf-8 -*- import pydvd_utils try: pydvd_utils.query_all() except Exception as e: print(e)

    – 8675309
    Nov 15 '18 at 18:22












  • Then the external file itself is being called twice. Show us how it's called.

    – John Gordon
    Nov 15 '18 at 18:24











  • I'm calling the file directly from the command prompt via D:OneDrivesourcepydvd>python query_all.py

    – 8675309
    Nov 15 '18 at 18:36











  • Edit your Question and show the __main__ entry point.

    – stovfl
    Nov 15 '18 at 18:45
















The external file must be calling query_all() twice.

– John Gordon
Nov 15 '18 at 18:20





The external file must be calling query_all() twice.

– John Gordon
Nov 15 '18 at 18:20













The external file is just a single call to that function. Its full contents are: #!/usr/bin/env python3 # -*- coding: utf-8 -*- import pydvd_utils try: pydvd_utils.query_all() except Exception as e: print(e)

– 8675309
Nov 15 '18 at 18:22






The external file is just a single call to that function. Its full contents are: #!/usr/bin/env python3 # -*- coding: utf-8 -*- import pydvd_utils try: pydvd_utils.query_all() except Exception as e: print(e)

– 8675309
Nov 15 '18 at 18:22














Then the external file itself is being called twice. Show us how it's called.

– John Gordon
Nov 15 '18 at 18:24





Then the external file itself is being called twice. Show us how it's called.

– John Gordon
Nov 15 '18 at 18:24













I'm calling the file directly from the command prompt via D:OneDrivesourcepydvd>python query_all.py

– 8675309
Nov 15 '18 at 18:36





I'm calling the file directly from the command prompt via D:OneDrivesourcepydvd>python query_all.py

– 8675309
Nov 15 '18 at 18:36













Edit your Question and show the __main__ entry point.

– stovfl
Nov 15 '18 at 18:45





Edit your Question and show the __main__ entry point.

– stovfl
Nov 15 '18 at 18:45












1 Answer
1






active

oldest

votes


















0














Face palm moment!



The function was definitely running twice, due to a PEBKAC error.



I had a call of the function I was using for direct testing within the library, and it wasn't commented out. Calling the function externally was running the function, and then the call to the function that both existed in the library file.



Commenting out the test call to the function in the library resolved the problem.



Thank you to everyone for the direction.






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53325567%2fsqlite3-with-python-returning-extra-data%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Face palm moment!



    The function was definitely running twice, due to a PEBKAC error.



    I had a call of the function I was using for direct testing within the library, and it wasn't commented out. Calling the function externally was running the function, and then the call to the function that both existed in the library file.



    Commenting out the test call to the function in the library resolved the problem.



    Thank you to everyone for the direction.






    share|improve this answer



























      0














      Face palm moment!



      The function was definitely running twice, due to a PEBKAC error.



      I had a call of the function I was using for direct testing within the library, and it wasn't commented out. Calling the function externally was running the function, and then the call to the function that both existed in the library file.



      Commenting out the test call to the function in the library resolved the problem.



      Thank you to everyone for the direction.






      share|improve this answer

























        0












        0








        0







        Face palm moment!



        The function was definitely running twice, due to a PEBKAC error.



        I had a call of the function I was using for direct testing within the library, and it wasn't commented out. Calling the function externally was running the function, and then the call to the function that both existed in the library file.



        Commenting out the test call to the function in the library resolved the problem.



        Thank you to everyone for the direction.






        share|improve this answer













        Face palm moment!



        The function was definitely running twice, due to a PEBKAC error.



        I had a call of the function I was using for direct testing within the library, and it wasn't commented out. Calling the function externally was running the function, and then the call to the function that both existed in the library file.



        Commenting out the test call to the function in the library resolved the problem.



        Thank you to everyone for the direction.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 19:13









        86753098675309

        45117




        45117





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53325567%2fsqlite3-with-python-returning-extra-data%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Barbados

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3