[Gambas-user] How To INSERT INTO in MySQL?

Ivan Williams ivanwms64 at ...43...
Tue Feb 7 02:36:07 CET 2012



I build a array of inserts  - first item in the array is "begin transaction"


            i19 = i19 + 1
            sql = "Insert into disks "
            sql = sql & "( diskno,dirno, nof,disknum, dirnum) "
            sql = sql & "Values ('"
            sql = sql & i17 & "', '" & i3 & "', '" & i20 & "', '" & tmp19 & "', '" & tmp15 & "');"
            rcnt = rcnt + 1
            qrs2[rcnt] = sql
'
'
'    lots of code omitted

'
'     I insert records in blocks of 10,000 to speed up insert rather than single inserts but feel free to insert one rec at atime if you wish

'


      IF rcnt > 10000 THEN
            rcnt = rcnt + 1
            qrs2[rcnt] = "commit;"
            FOR i7 = 1 TO rcnt
                databaseconnection.Exec(qrs2[i7])
            NEXT
           rcnt = 1
           qrs2[rcnt] = "begin transaction;"
     ENDIF       

'
'
'
This is how I do it.  Do some error checking to make sure your single quotes and special chars are taken care of - have fun.  
 
 
Ivan    \~/

 
I never saw a wild thing sorry for itself.
A small bird will drop frozen dead from a bough
Without ever having felt sorry for itself.
-- D.H. Lawrence


http://www.usconstitution.net/const.html

Linux - Live Free or Die.



________________________________
 From: M. Cs. <mohareve at ...626...>
To: mailing list for gambas users <gambas-user at lists.sourceforge.net> 
Sent: Monday, February 6, 2012 9:18 AM
Subject: Re: [Gambas-user] How To INSERT INTO in MySQL?
 
And I agree with Fabien!!!!
I just over with the transcription of former wrongly formatted query style ->
query="INSERT INTO....."
MyConn.Exec(query)
Don't use that style! You will make only troubles with escaping characters.
The right way is MyConn.Exec("INSERT Into ...
VALUES(&1,&2...);",myvar1,myvar2,...)

2012/2/6, Fabien Bodard <gambas.fr at ...626...>:
> sql = "INSERT INTO statistic (TimeCode, SessionStart, SessionEnd, Kluch,
> Comp) VALUES (&1,&2,&3,&4,&5)"
> MODMain.$Con.Subst(sql, T, Now(), Now(), kluch, Nc)
> MODMain.$Con.Exec(sql)
>
>
> ????
>
> i prefer like that :
>
> MODMain.$Con.Exec("INSERT INTO statistic (TimeCode, SessionStart,
> SessionEnd, Kluch, Comp) VALUES (&1,&2,&3,&4,&5)",T, Now(), Now(),
> kluch, Nc)
>
> ------------------------------------------------------------------------------
> Try before you buy = See our experts in action!
> The most comprehensive online learning library for Microsoft developers
> is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
> Metro Style Apps, more. Free future releases when you subscribe now!
> http://p.sf.net/sfu/learndevnow-dev2
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Gambas-user mailing list
Gambas-user at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


More information about the User mailing list