Thanks, Alan, for your advice.
I fully agree with you - I still need to understand basic Python (I
actually warned that I am a complete noob) and how it works. And
probably I need a couple of goof books.
I once told you that I consider your website an excellent one and I am
going there from time to time and will do it again.

Maybe I am trying to do the things which are too advanced for my level
of python knowledge - databases, web development, which I understand
are considered as advanced topics but the reason is that for me I need
a real project to work with to learn a programming language. That was
the case also with VBA (visual basic for applications) - learning for
the sake of learning almost never worked with me. It does not mean I
am an expert in VBA - far from it! But I had this project working with
MS Excel VBA+ MS SQL Server Express 2005 T-SQL - an automated
financial accounting consolidated reporting application. I am pumping
data from two remote Interbase/Firebird databases, putting it in a
local MS SQL Server DB, processing with T-SQL and doing the reporting
with Excel.

Now I am working to do the same with Python and SQLite at the same
time learning on my way them both. And if you work on a real thing
there are many bits and pieces which are coming up - and its not like
this 'spam' and 'egg' thing all the time.

Also I am completely self-taught in programming.

I see what was my problem in particular in this case and I understand
it now. And I will try not to bother people on this list too often. Or
If I do please feel free tell me to [EMAIL PROTECTED] off and do some more
reading!

Again, thank you Alan for the help!

Aivars



2008/12/3 Alan Gauld <[EMAIL PROTECTED]>:
> "aivars" <[EMAIL PROTECTED]> wrote
>
>> Finally I managed to get it working!
>>
>> I had to remove [year] braces from the second argument - year.
>
> You really need to do some reading on basicv Python before
> you go any further, otherwise you will never understand what
> you are doing.
>
> That is what I told you was wrong in the first place - you can't
> pass a list of values (even of one value)  into a database field.
> But you obviously didn't realize that putting square brackets
> (not braces which are {} and signify a dictionary) indicates
> a list.
>
>> reason I used [] was the posts we exchanged recently (7th of November)
>> about CGI script where it was recommended by Kent that I put [] around
>> string argument:
>
> But that was an entirely different scenario, again you need to do some
> basic level reading so that you understand what we are telling you.
> Blindly using "poke and hope" techniques leads to an excercise
> in frustration for you and us both.
>
>> The second argument to execute() is a *sequence* of parameter values.
>> A string is a sequence of characters, so by passing a plain string you
>> are saying that each character of the string is a parameter to the
>> SQL.
>>
>> Try adding braces around the parameter to make  list:
>> cur.execute("insert into test (name) values (?)", [sPath])
>
> Notice, Kent told you to "make a list" by putting[] around
> your string. But in that case the arument was looking for a sequence
> (eg list) of values. In your case you were trying to insert a list of values
> into a single field which you can't do in normal SQL
>
>> Now the year argument is string so I thought I should do the same
>> again but it is not working.
>
> Yes but it is a single string so you need to pass a single string.
> In the previous case the SQL was looking for a list of arguments
> but you passed a single string so the execute interpreted that
> as a list of letters.
>
> You must ensure that the arguments in the execute match
> what the SQL is expecting. And that usually means both matching
> what you defined the database to be and the nature of the operation.
>
>> The reason is of course is that I am new to python and there are so
>> many things to learn so the question really is why in this case there
>> were no [] or () necessary?
>
> See above, but you really need to take the time out to understand
> the basics of Python.
>
> Try reading my  tutorial, in particular the "raw materials"  topic
> which covers the different Python data types. Then try my database
> topic near the end. But ideally just take a few hours - literally an
> afternoon will do - to go through any beginners tutorial. They will
> all cover these elementary issues.
>
>
>>>>> Perhaps but I think it is the list parameter that it doesn't like.
>>>>> Unless I misunderstand the syntax.
>>>>>
>>>>> --
>>>>> Alan Gauld
>>>>> Author of the Learn to Program web site
>>>>> http://www.freenetpages.co.uk/hp/alan.gauld
>
>
> Alan G.
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to