France Hardware : Forums de discussion
Retrouvez les prix près de chez vous :  
Index du forum | Liste des membres | Liste des groupes | Inscription | F-A-Q | Recherche
Pseudo :    Password :     
22 342 membres enregistrés - 1 872 895 posts - 95 150 topics
Index des forums FH  | Index des forums DegroupNews
      Programmation
           Langages Web
                transformer une BDD acces en MySQL ???
12 connectés(record : 207 le 05 juin 2007 - 05 h 23)

Vous devez vous connecter pour répondre au topic.
transformer une BDD acces en MySQL ???

ze.bassman


Messages : 781
Inscrit le 14/10/02
Ville : grenoble
Non connecté
  Posté le 19 juillet 2004 - 19 h 10 m 35 s
je débute et je me demande s'il est possible de transformer une base acces en mysql ?
si oui....... COMMENT ? :lol:

Merci




gege38
Modérateur
Chief of the
(¯`·.__[T3aM.BouL3T©]__.·´¯)
Potatoe Reloaded

Messages : 14 079
Inscrit le 05/02/03
Ville : Domène
Non connecté
  Posté le 19 juillet 2004 - 19 h 43 m 39 s



" Nous plaisons plus souvent dans le commerce de la vie par nos défauts que par nos qualités. "
--La Rochefoucauld


Erel69
206
(¯`·.__[T3aM.L1b3rTe©]__.·´¯)

Messages : 19 449
Inscrit le 07/11/01
Ville : Lyon
Non connecté
  Posté le 19 juillet 2004 - 20 h 46 m 26 s


Le 19 juillet 2004 à 19 h 43, gege38 a écrit :
Google est ton ami ;)


Faudrait arrêter un peu avec ce slogan lol

Un forum c'est aussi pour se apsser de google et discuter directement avec les gens :D



Obscurité au-delà du crépuscule, pourpre au-delà du sang qui coule, enfoui dans le flot du temps, en ton haut nom, je jure fidélité à l'obscurité. Que les fous qui se dressent devant nous soient détruits, par le pouvoir que toi et moi possédons...

Petit_PimoOosE
rsqrtps & pshufb

Messages : 4 616
Inscrit le 15/06/03
Ville : Montréal
Non connecté
  Posté le 19 juillet 2004 - 21 h 00 m 10 s
Pour ma part, j'ai utilisé ce script-là : www.cynergi.net/prod/exportsql/
La conversion (ok, la base était assez basique) s'est effectuée sans mal.

EDIT : ah ben zut le lien n'est pas terrible
voici le code :
    Code vb    
  1. Option Compare Database
  2. Option Explicit
  3. 
  4. ' exportSQL version 2.0
  5. ' www.cynergi.net/prod/exportsql/
  6. '
  7. ' (C) 1997-98 CYNERGI - www.cynergi.net, info@cynergi.net
  8. ' (C) Pedro Freire - pedro.freire@cynergi.net  (do not add to mailing lists without permission)
  9. '
 10. ' This code is provided free for anyone's use and is therefore without guarantee or support.
 11. ' This does NOT mean CYNERGI delegates its copyright to anyone using it! You may change the
 12. ' code in any way, as long as this notice remains on the code and CYNERGI is notified (if you
 13. ' publish the changes: if your changes/corrections prove valuable and are added to the code,
 14. ' you will be listed in a credit list on this file).
 15. '
 16. ' You may NOT sell this as part of a non-free package:
 17. ' IF YOU HAVE PAID FOR THIS CODE, YOU HAVE BEEN ROBBED! CONTACT admin@cynergi.net!
 18. 
 19. ' MODULE
 20. '   "exportSQL"
 21. '
 22. ' GOAL
 23. '   Export all tables in a MS-Access database file to 2 text files:
 24. '   one containing SQL instructions to delete the new tables to be created,
 25. '   and the other with SQL instructions to create and insert data into
 26. '   the new tables. The table structure and data will resemble as much as
 27. '   possible the current Access database.
 28. '
 29. ' HOW TO USE
 30. '   Copy-and-paste this text file into an Access module and run the first
 31. '   (and only public) function. in more detail, you:
 32. '   * Open the Access .mdb file you wish to export
 33. '   * in the default database objects window, click on "Modules", and then on "New"
 34. '   * The code window that opens has some pre-written text (code). Delete it.
 35. '   * Copy-and-paste this entire file to the code module window
 36. '   * You may hit the compile button (looks like 3 sheets of paper with an arrow on
 37. '     top of them, pressing down on them), or select Debug, Compile Loaded Modules
 38. '     from the top menu, just to make sure there are no errors, and that this code
 39. '     works on your Access version (it works on Access'97 and should work on Access'95)
 40. '   * Close the code module window - windows will prompt you to save the code:
 41. '     answer "Yes", and when promped for a name for the module, type anything
 42. '     (say, "MexportSQL")
 43. '   The module is now part of your Access database. To run the export, you:
 44. '   * Re-open the code module (by double-clicking on it, or clicking "Design"
 45. '     with it selected). Move the cursor to where the first "Function" keyword appears.
 46. '     Press F5 or select Run, Go/Continue from the top menu.
 47. '   * Alternativelly, click on "Macros" on the database objects window,
 48. '     and then on "New". On the macro window, select "RunCode" as the macro action,
 49. '     and "exportSQL" as the function name, bellow. Save the macro similarly to the
 50. '     module, and this time double-clicking on it, or clicking "Run" will run the export.
 51. '
 52. ' BEFORE RUNNING THE EXPORT
 53. '   Before running the export, be sure to check out the Export Options just bellow this
 54. '   text, and change any according to your wishes and specs.
 55. '
 56. ' TECH DATA
 57. '   Public identifiers:
 58. '   * Only one: "exportSQL", a function taking and returning no arguments. It runs the export.
 59. '   Functionallity:
 60. '   * Can export to mSQL v1, mSQL v2 or MySQL-recognised SQL statements
 61. '   * Excellent respect for name conversion, namespace verification, type matching, etc.
 62. '   * Detects default values "=Now()", "=Date()" and "=Time()" to create types like "TIMESTAMP"
 63. '   * Fully configurable via private constants on top of code
 64. '   * Exports two files: one for erasures, another for creations (useful when updating dbs)
 65. '   * Generates compatibility warnings when necessary
 66. '   * Code and generated files are paragraphed and easy to read
 67. '   * Access text and memo fields can have any type of line termination: \n\r, \r\n, \n or \r
 68. '   * Properly escapes text and memo fields, besides all types of binary fields
 69. '   * Closes all open objects and files on error
 70. '   * Known bugs / incomplete constructs are signalled with comments starting with "!!!!"
 71. '   * Two alternatives on absent date/time type on mSQL: REAL or CHAR field
 72. 
 73. 
 74. ' Export Options - change at will
 75. 
 76. Private Const DB_ENGINE As String = "MY"  ' USE ONLY "M1" (mSQL v1), "M2" (mSQL v2) or "MY" (MySQL)
 77. Private Const DB_NAME As String = ""  ' Use empty string for current. Else use filename or DSN name of database to export
 78. Private Const DB_CONNECT As String = ""  ' Used only if above string is not empty
 79. Private Const MSQL_64kb_AVG As Long = 2048  ' ALWAYS < 65536 (to be consistent with MS Access). Set to max expected size of Access MEMO field (to preserve space in mSQL v1)
 80. Private Const WS_REPLACEMENT As String = "_"  ' Use "" to simply eat whitespaces in identifiers (table and field names)
 81. Private Const IDENT_MAX_SIZE As Integer = 19  ' Suggest 64. Max size of identifiers (table and field names)
 82. Private Const PREFIX_ON_KEYWORD As String = "_"  ' Prefix to add to identifier, if it is a reserved word
 83. Private Const SUFFIX_ON_KEYWORD As String = ""  ' Suffix to add to identifier, if it is a reserved word
 84. Private Const PREFIX_ON_INDEX As String = "ix"  ' Prefix to add to index identifier, to make it unique (mSQL v2)
 85. Private Const SUFFIX_ON_INDEX As String = ""  ' Suffix to add to index identifier, to make it unique (mSQL v2)
 86. Private Const ADD_SQL_FILE As String = "c:\temp\esql_add.txt"  ' Use empty if open on #1. Will be overwritten if exists!
 87. Private Const DEL_SQL_FILE As String = "c:\temp\esql_del.txt"  ' Use empty if open on #2. Will be overwritten if exists!
 88. Private Const LINE_BREAK As String = "\n"  ' Try "<br>". String to replace line breaks in text fields
 89. Private Const QUERY_SEPARATOR As String = "\g"  ' Terminator/separator of SQL queries (to instruct some monitor program to execute them)
 90. Private Const COMMENT_PREFIX As String = "#"  ' Use empty string for no comments
 91. Private Const DISPLAY_WARNINGS As Boolean = True  ' False to output the warnings to the files, only
 92. Private Const DATE_AS_STR As Boolean = True  ' False to use real number data type for date, time and timestamp (in mSQL only)
 93. Private Const PARA_INSERT_AFTER As Integer = 3  ' Field count after which print INSERTs different lines
 94. Private Const INDENT_SIZE As Integer = 5  ' Number of spaces on indents
 95. 
 96. 
 97. ' Global var to store inter-funtion data
 98. Private warnings As String  ' Not an option: do not set in any way
 99. 
100. 
101. ' Primary Export Function
102. 
103. Sub exportSQL()
104. On Error GoTo exportSQL_error
105. 
106.     Dim cdb As Database
107.     Dim ctableix As Integer, ctablename As String
108. 
109.     If DB_NAME = "" Then
110.         Set cdb = CurrentDb()
111.     Else
112.         Set cdb = OpenDatabase(DB_NAME, False, True, DB_CONNECT) ' Shared, read-only
113.     End If
114.     
115.     If ADD_SQL_FILE <> "" Then Open ADD_SQL_FILE For Output As #1
116.     If DEL_SQL_FILE <> "" Then Open DEL_SQL_FILE For Output As #2
117. 
118.     DoCmd.Hourglass True
119. 
120.     If COMMENT_PREFIX <> "" Then
121.         Print #1, COMMENT_PREFIX & " Exported from MS Access to " & IIf(Left$(DB_ENGINE, 2) = "MY", "MySQL", "mSQL")
122.         Print #1, COMMENT_PREFIX & " (C) 1997-98 CYNERGI - www.cynergi.net, info@cynergi.net"
123.         Print #1,
124.     
125.         Print #2, COMMENT_PREFIX & " Exported from MS Access to " & IIf(Left$(DB_ENGINE, 2) = "MY", "MySQL", "mSQL")
126.         Print #2, COMMENT_PREFIX & " (C) 1997-98 CYNERGI - www.cynergi.net, info@cynergi.net"
127.         Print #2,
128.     End If
129. 
130.     'Go through the table definitions
131.     For ctableix = 0 To cdb.TableDefs.Count - 1
132.     
133.         Dim cfieldix As Integer, cfieldname As String
134.         Dim fieldlst As String, sqlcode As String
135.         Dim primary_found As Boolean
136.         Dim crs As Recordset
137.     
138.         ' Let's take only the visible tables
139.         If (((cdb.TableDefs(ctableix).Attributes And DB_SYSTEMOBJECT) Or _
140.         (cdb.TableDefs(ctableix).Attributes And DB_HIDDENOBJECT))) = 0 Then
141.             
142.             ctablename = conv_name("" & cdb.TableDefs(ctableix).Name)
143.             
144.             Print #2,
145.             Print #2, "DROP TABLE " & ctablename & QUERY_SEPARATOR
146.             
147.             ' CREATE clause
148.             Print #1,
149.             Print #1, "CREATE TABLE " & ctablename
150.             Print #1, Space$(INDENT_SIZE) & "("
151.             
152.             warnings = ""
153.             fieldlst = ""
154.             primary_found = False
155.             
156.             ' loop thorugh each field in the table
157.             For cfieldix = 0 To cdb.TableDefs(ctableix).Fields.Count - 1
158.                 
159.                 Dim typestr As String, fieldsz As Integer, dvstr As String
160.                 Dim found_ix As Boolean, cindex As Index, cfield As Field
161.                 
162.                 ' if this is not the first iteration, add separators
163.                 If fieldlst <> "" Then
164.                     fieldlst = fieldlst & ", "
165.                     Print #1, ","
166.                 End If
167.                 
168.                 ' get field name
169.                 cfieldname = conv_name("" & cdb.TableDefs(ctableix).Fields(cfieldix).Name)
170.                 fieldlst = fieldlst & cfieldname
171.                 
172.                 ' translate types
173.                 If DB_ENGINE = "M1" Or DB_ENGINE = "M2" Then
174.                     Select Case cdb.TableDefs(ctableix).Fields(cfieldix).type
175.                         Case dbChar
176.                             typestr = "CHAR(" & cdb.TableDefs(ctableix).Fields(cfieldix).Size & ")"
177.                         Case dbText
178.                             fieldsz = cdb.TableDefs(ctableix).Fields(cfieldix).Size
179.                             If fieldsz = 0 Then fieldsz = 255
180.                             typestr = "CHAR(" & fieldsz & ")"
181.                         Case dbBoolean, dbByte, dbInteger, dbLong
182.                             typestr = "INT"
183.                         Case dbDouble, dbFloat, dbSingle
184.                             typestr = "REAL"
185.                         Case dbCurrency, dbDecimal, dbNumeric
186.                             typestr = "REAL"
187.                             warn "In new field '" & cfieldname & "', currency/BCD will be converted to REAL - there may be precision loss!", False
188.                         Case dbDate
189.                             typestr = IIf(DATE_AS_STR, "CHAR(19)", "REAL") ' use Access internal format: IEEE 64-bit (8-byte) FP
190.                             warn "In new field '" & cfieldname & "', date/time/timestamp will be converted to " & typestr & ".", False
191.                         Case dbTime
192.                             typestr = IIf(DATE_AS_STR, "CHAR(8)", "REAL") ' use Access internal format: IEEE 64-bit (8-byte) FP
193.                             warn "In new field '" & cfieldname & "', date/time/timestamp will be converted to " & typestr & ".", False
194.                         Case dbTimeStamp
195.                             typestr = IIf(DATE_AS_STR, "CHAR(19)", "REAL") ' use Access internal format: IEEE 64-bit (8-byte) FP
196.                             warn "In new field '" & cfieldname & "', date/time/timestamp will be converted to " & typestr & "." & IIf(DB_ENGINE = "M2", " Consider using pseudo field '_timestamp'.", ""), False
197.                         Case dbMemo
198.                             If DB_ENGINE = "M2" Then
199.                                 typestr = "TEXT(" & MSQL_64kb_AVG & ")"
200.                             Else
201.                                 typestr = "CHAR(" & MSQL_64kb_AVG & ")"
202.                                 warn "In new field '" & cfieldname & "', dbMemo is not supported by mSQL v1 - fields larger than MSQL_64kb_AVG (" & MSQL_64kb_AVG & ") will not be accepted!", False
203.                             End If
204.                         Case dbBinary, dbVarBinary
205.                             typestr = "CHAR(255)"
206.                             warn "In new field '" & cfieldname & "', dbBinary and dbVarBinary are not supported by mSQL! - will use a text (CHAR(255)) field.", True
207.                         Case dbLongBinary
208.                             typestr = "CHAR(" & MSQL_64kb_AVG & ")"
209.                             warn "In new field '" & cfieldname & "', dbLongBinary is not supported by mSQL! - will use a text (CHAR(" & MSQL_64kb_AVG & ")) field.", True
210.                         Case Else
211.                             warn "In new field '" & cfieldname & "', dbBigInt and dbGUID are not currently supported!", True
212.                             Error 5  ' invalid Procedure Call
213.                     End Select
214.                 Else
215.                     Select Case cdb.TableDefs(ctableix).Fields(cfieldix).type
216.                         Case dbBinary
217.                             typestr = "TINYBLOB"
218.                         Case dbBoolean
219.                             typestr = "TINYINT"
220.                         Case dbByte
221.                             typestr = "TINYINT UNSIGNED"
222.                         Case dbChar
223.                             typestr = "CHAR(" & cdb.TableDefs(ctableix).Fields(cfieldix).Size & ")"
224.                         Case dbCurrency
225.                             typestr = "DECIMAL(20,4)"
226.                         Case dbDate
227.                             typestr = "DATETIME"
228.                         Case dbDecimal
229.                             typestr = "DECIMAL(20,4)"
230.                         Case dbDouble
231.                             typestr = "REAL"
232.                         Case dbFloat
233.                             typestr = "REAL"
234.                         Case dbInteger
235.                             typestr = "SMALLINT"
236.                         Case dbLong
237.                             typestr = "INT"
238.                         Case dbLongBinary
239.                             typestr = "LONGBLOB"
240.                         Case dbMemo
241.                             typestr = "LONGBLOB"  ' !!!!! MySQL bug! Replace by LONGTEXT when corrected!
242.                         Case dbNumeric
243.                             typestr = "DECIMAL(20,4)"
244.                         Case dbSingle
245.                             typestr = "FLOAT"
246.                         Case dbText
247.                             fieldsz = cdb.TableDefs(ctableix).Fields(cfieldix).Size
248.                             If fieldsz = 0 Then fieldsz = 255
249.                             typestr = "CHAR(" & fieldsz & ")"
250.                         Case dbTime
251.                             typestr = "TIME"
252.                         Case dbTimeStamp
253.                             typestr = "TIMESTAMP"
254.                         Case dbVarBinary
255.                             typestr = "TINYBLOB"
256.                         Case dbBigInt, dbGUID
257.                             warn "In new field '" & cfieldname & "', dbBigInt and dbGUID are not currently supported!", True
258.                             Error 5  ' invalid Procedure Call
259.                         Case Else
260.                             typestr = "LONGBLOB"
261.                     End Select
262.                 End If
263.                 
264.                 ' check not null and auto-increment properties
265.                 If ((cdb.TableDefs(ctableix).Fields(cfieldix).Attributes And dbAutoIncrField) <> 0) Then
266.                     If Left$(DB_ENGINE, 2) = "MY" Then
267.                         typestr = typestr & " NOT NULL AUTO_INCREMENT"
268.                     Else
269.                         typestr = typestr & " NOT NULL"
270.                         warn "In new field '" & cfieldname & "', mSQL does not support auto-increment fields! - they will be pure INTs." & IIf(DB_ENGINE = "M2", " Consider using pseudo field '_rowid' or SEQUENCEs.", ""), False
271.                     End If
272.                 ElseIf cdb.TableDefs(ctableix).Fields(cfieldix).Required = True Then
273.                     typestr = typestr & " NOT NULL"
274.                 End If
275.                     
276.                 ' default value
277.                 dvstr = cdb.TableDefs(ctableix).Fields(cfieldix).DefaultValue
278.                 If dvstr <> "" Then
279.                     If Left$(DB_ENGINE, 2) <> "MY" Then
280.                         warn "In new field '" & cfieldname & "', mSQL does not support default values! - they won't be initialised.", False
281.                     ElseIf cdb.TableDefs(ctableix).Fields(cfieldix).Required = False Then
282.                         warn "In new field '" & cfieldname & "', MySQL needs NOT NULL to support default values! - it won't be set a default.", False
283.                     ElseIf Left$(dvstr, 1) = """" Then
284.                         typestr = typestr & " DEFAULT '" & conv_str(Mid$(dvstr, 2, Len(dvstr) - 2)) & "'"
285.                     ElseIf ((LCase(dvstr) = "now()" Or LCase(dvstr) = "date()" Or LCase(dvstr) = "time()") And _
286.                     (Left$(typestr, 5) = "DATE " Or Left$(typestr, 5) = "TIME " Or Left$(typestr, 9) = "DATETIME ")) Then
287.                         typestr = "TIMESTAMP " & Right$(typestr, Len(typestr) - InStr(typestr, " "))
288.                     ElseIf LCase(dvstr) = "no" Then
289.                         typestr = typestr & " DEFAULT 0"
290.                     ElseIf LCase(dvstr) = "yes" Then
291.                         typestr = typestr & " DEFAULT 1"
292.                     Else
293.                         typestr = typestr & " DEFAULT " & dvstr
294.                     End If
295.                 End If
296.                 
297.                 ' check if primary key (for mSQL v1)
298.                 If DB_ENGINE = "M1" Then
299.                     found_ix = False
300.                     For Each cindex In cdb.TableDefs(ctableix).Indexes
301.                         If cindex.Primary Then
302.                             For Each cfield In cindex.Fields
303.                                 If cfield.Name = cdb.TableDefs(ctableix).Fields(cfieldix).Name Then
304.                                     found_ix = True
305.                                     Exit For
306.                                 End If
307.                             Next cfield
308.                             If found_ix Then Exit For
309.                         End If
310.                     Next cindex
311.                     If found_ix Then
312.                         If primary_found Then
313.                             warn "On new table '" & ctablename & "', mSQL v1 does not support more than one PRIMARY KEY! Only first key was set.", False
314.                         Else
315.                             typestr = typestr & " PRIMARY KEY"
316.                             primary_found = True
317.                         End If
318.                     End If
319.                 End If
320.                 
321.                 'print out field info
322.                 Print #1, Space$(INDENT_SIZE) & cfieldname & Space$(IDENT_MAX_SIZE - Len(cfieldname) + 2) & typestr;
323.             
324.             Next cfieldix
325.                   
326.             ' terminate CREATE clause
327.             If DB_ENGINE = "M2" Then
328.                 Print #1,
329.                 Print #1, Space$(INDENT_SIZE) & ")" & QUERY_SEPARATOR
330.             End If
331.                   
332.             ' primary key and other index declaration
333.             If DB_ENGINE = "M2" Or Left$(DB_ENGINE, 2) = "MY" Then
334.                 For Each cindex In cdb.TableDefs(ctableix).Indexes
335.                     sqlcode = ""
336.                     For Each cfield In cindex.Fields
337.                         sqlcode = sqlcode & IIf(sqlcode = "", "", ", ") & conv_name(cfield.Name)
338.                     Next cfield
339.                     If DB_ENGINE = "M2" Then
340.                         Print #1, "CREATE " & IIf(cindex.Unique, "UNIQUE ", "") & "INDEX " & _
341.                         conv_name(PREFIX_ON_INDEX & cindex.Name & SUFFIX_ON_INDEX) & " ON " & _
342.                         ctablename & " (" & sqlcode & ")" & QUERY_SEPARATOR
343.                     Else
344.                         Print #1, ","
345.                         Print #1, Space$(INDENT_SIZE) & IIf(cindex.Primary, "PRIMARY ", "") & _
346.                         "KEY (" & sqlcode & ")";
347.                     End If
348.                 Next cindex
349.             End If
350.             
351.             ' terminate CREATE clause
352.             If DB_ENGINE <> "M2" Then
353.                 Print #1,
354.                 Print #1, Space$(INDENT_SIZE) & ")" & QUERY_SEPARATOR
355.             End If
356. 
357.             ' print any warnings bellow it
358.             If COMMENT_PREFIX <> "" And warnings <> "" Then
359.                 If DB_ENGINE = "M2" Then Print #1, COMMENT_PREFIX & " "
360.                 Print #1, warnings
361.                 warnings = ""
362.             End If
363.             
364.             Print #1,
365.             
366.             ' INSERT clause
367.             Set crs = cdb.OpenRecordset(cdb.TableDefs(ctableix).Name)
368.             If crs.RecordCount <> 0 Then
369.                 
370.                 ' loop thorugh each record in the table
371.                 crs.MoveFirst
372.                 Do Until crs.EOF
373.                     
374.                     ' start paragraphing
375.                     sqlcode = "INSERT INTO " & ctablename
376.                     If crs.Fields.Count > PARA_INSERT_AFTER Then
377.                         Print #1, sqlcode
378.                         If DB_ENGINE = "M1" Then Print #1, Space$(INDENT_SIZE) & "(" & fieldlst & ")"
379.                         Print #1, "VALUES ("
380.                         sqlcode = Space$(INDENT_SIZE)
381.                     Else
382.                         If DB_ENGINE = "M1" Then sqlcode = sqlcode & " (" & fieldlst & ")"
383.                         sqlcode = sqlcode & " VALUES ("
384.                     End If
385.                     
386.                     ' loop through each field in each record
387.                     For cfieldix = 0 To crs.Fields.Count - 1
388.                     
389.                         ' based on type, prepare the field value
390.                         If IsNull(crs.Fields(cfieldix).Value) Then
391.                             sqlcode = sqlcode & "NULL"
392.                         Else
393.                             Select Case crs.Fields(cfieldix).type
394.                                 Case dbBoolean
395.                                     sqlcode = sqlcode & IIf(crs.Fields(cfieldix).Value = True, "1", "0")
396.                                 Case dbChar, dbText, dbMemo
397.                                     sqlcode = sqlcode & "'" & conv_str(crs.Fields(cfieldix).Value) & "'"
398.                                 Case dbDate, dbTimeStamp
399.                                     If Left$(DB_ENGINE, 2) = "MY" Or DATE_AS_STR Then
400.                                         sqlcode = sqlcode & "'" & Format(crs.Fields(cfieldix).Value, "YYYY-MM-DD HH:MM:SS") & "'"
401.                                     Else
402.                                         'print in Access internal format: IEEE 64-bit (8-byte) FP
403.                                         sqlcode = sqlcode & "'" & Format(crs.Fields(cfieldix).Value, "#.#########") & "'"
404.                                     End If
405.                                 Case dbTime
406.                                     If Left$(DB_ENGINE, 2) = "MY" Or DATE_AS_STR Then
407.                                         sqlcode = sqlcode & "'" & Format(crs.Fields(cfieldix).Value, "HH:MM:SS") & "'"
408.                                     Else
409.                                         'print in Access internal format: IEEE 64-bit (8-byte) FP
410.                                         sqlcode = sqlcode & "'" & Format(crs.Fields(cfieldix).Value, "#.#########") & "'"
411.                                     End If
412.                                 Case dbBinary, dbLongBinary, dbVarBinary
413.                                     sqlcode = sqlcode & "'" & conv_bin(crs.Fields(cfieldix).Value) & "'"
414.                                 Case Else
415.                                     sqlcode = sqlcode & conv_str(crs.Fields(cfieldix).Value)
416.                             End Select
417.                         End If
418.                         
419.                         ' paragraph separators
420.                         If cfieldix < crs.Fields.Count - 1 Then
421.                             sqlcode = sqlcode & ", "
422.                             If crs.Fields.Count > PARA_INSERT_AFTER Then
423.                                 Print #1, sqlcode
424.                                 sqlcode = Space$(INDENT_SIZE)
425.                             End If
426.                         End If
427.                         
428.                     Next cfieldix
429.                     
430.                     ' print out result and any warnings
431.                     sqlcode = sqlcode & IIf(crs.Fields.Count > PARA_INSERT_AFTER, " )", ")") & QUERY_SEPARATOR
432.                     Print #1, sqlcode
433.                     If COMMENT_PREFIX <> "" And warnings <> "" Then
434.                         Print #1, warnings
435.                         warnings = ""
436.                     End If
437.                     If crs.Fields.Count > PARA_INSERT_AFTER Then Print #1,
438.                     
439.                     crs.MoveNext
440.                 Loop
441.                 
442.             Else
443.                 
444.                 ' if there is no data on the table
445.                 If COMMENT_PREFIX <> "" Then Print #1, COMMENT_PREFIX & " This table has no data"
446.             
447.             End If
448.             
449.             crs.Close
450.             Set crs = Nothing
451.         
452.         End If  'print only unhidden tables
453.     
454.     Next ctableix
455.     
456. exportSQL_exit:
457.     Close #2
458.     Close #1
459.     
460.     cdb.Close
461.     Set cdb = Nothing
462. 
463.     DoCmd.Hourglass False
464. 
465.     Exit Sub
466. 
467. exportSQL_error:
468.     MsgBox Err.Description
469.     Resume exportSQL_exit
470. 
471. End Sub
472. 
473. 
474. Private Function conv_name(strname As String) As String
475.     Dim i As Integer, str As String
476. 
477.     ' replace inner spaces with WS_REPLACEMENT
478.     str = strname
479.     i = 1
480.     While i <= Len(str)
481.         Select Case Mid$(str, i, 1)
482.             Case " ", Chr$(9), Chr$(10), Chr$(13)  ' space, tab, newline, carriage return
483.                 str = Left$(str, i - 1) & WS_REPLACEMENT & Right$(str, Len(str) - i)
484.                 i = i + Len(WS_REPLACEMENT)
485.             Case Else
486.                 i = i + 1
487.         End Select
488.     Wend
489.     ' restrict tablename to IDENT_MAX_SIZE chars, *after* eating spaces
490.     str = Left$(str, IDENT_MAX_SIZE)
491.     ' check for reserved words
492.     conv_name = str
493.     If Left$(DB_ENGINE, 2) = "MY" Then
494.         Select Case LCase$(str)
495.             Case "add", "all", "alter", "and", "as", "asc", "auto_increment", "between", _
496.             "bigint", "binary", "blob", "both", "by", "cascade", "char", "character", _
497.             "change", "check", "column", "columns", "create", "data", "datetime", "dec", _
498.             "decimal", "default", "delete", "desc", "describe", "distinct", "double", _
499.             "drop", "escaped", "enclosed", "explain", "fields", "float", "float4", _
500.             "float8", "foreign", "from", "for", "full", "grant", "group", "having", _
501.             "ignore", "in", "index", "infile", "insert", "int", "integer", "interval", _
502.             "int1", "int2", "int3", "int4", "int8", "into", "is", "key", "keys", _
503.             "leading", "like", "lines", "limit", "lock", "load", "long", "longblob", _
504.             "longtext", "match", "mediumblob", "mediumtext", "mediumint", "middleint", _
505.             "numeric", "not", "null", "on", "option", "optionally", "or", "order", _
506.             "outfile", "partial", "precision", "primary", "procedure", "privileges", _
507.             "read", "real", "references", "regexp", "repeat", "replace", "restrict", _
508.             "rlike", "select", "set", "show", "smallint", "sql_big_tables", _
509.             "sql_big_selects", "sql_select_limit", "straight_join", "table", "tables", _
510.             "terminated", "tinyblob", "tinytext", "tinyint", "trailing", "to", "unique", _
511.             "unlock", "unsigned", "update", "usage", "values", "varchar", "varying", _
512.             "with", "write", "where", "zerofill"
513.                 conv_name = Left$(PREFIX_ON_KEYWORD & str & SUFFIX_ON_KEYWORD, IDENT_MAX_SIZE)
514.                 If (str = conv_name) Then
515.                     warn "In identifier '" & strname & "', the new form '" & strname & _
516.                     "' is a reserved word, and PREFIX_ON_KEYWORD ('" & _
517.                     PREFIX_ON_KEYWORD & "') and SUFFIX_ON_KEYWORD ('" & SUFFIX_ON_KEYWORD & _
518.                     "') make it larger than IDENT_MAX_SIZE, and after cut it is the same as the original! " & _
519.                     "This is usually caused by a void or empty PREFIX_ON_KEYWORD.", True
520.                     Error 5  ' invalid Procedure Call
521.                 End If
522.         End Select
523.     End If
524. End Function
525. 
526. 
527. Private Function conv_str(str As String) As String
528.     Dim i As Integer, nlstr As String, rstr As Variant
529.     
530.     nlstr = ""
531.     rstr = Null
532.     i = 1
533.     While i <= Len(str)
534.         Select Case Mid$(str, i, 1)
535.             Case Chr$(0)  ' ASCII NUL
536.                 nlstr = ""
537.                 rstr = "\0"
538.             Case Chr$(8)  ' backspace
539.                 nlstr = ""
540.                 rstr = "\b"
541.             Case Chr$(9)  ' tab
542.                 nlstr = ""
543.                 rstr = "\t"
544.             Case "'"
545.                 nlstr = ""
546.                 rstr = "\'"
547.             Case """"
548.                 nlstr = ""
549.                 rstr = "\"""
550.             Case "\"
551.                 nlstr = ""
552.                 rstr = "\\"
553.             Case Chr$(10), Chr$(13)  ' line feed and carriage return
554.                 If nlstr <> "" And nlstr <> Mid$(str, i, 1) Then
555.                     ' there was a previous newline and this is its pair: eat it
556.                     rstr = ""
557.                     nlstr = ""
558.                 Else
559.                     ' this is a fresh newline
560.                     rstr = LINE_BREAK
561.                     nlstr = Mid$(str, i, 1)
562.                 End If
563.             Case Else
564.                 nlstr = ""
565.         End Select
566.         If Not IsNull(rstr) Then
567.             str = Left$(str, i - 1) & rstr & Right$(str, Len(str) - i)
568.             i = i + Len(rstr)
569.             rstr = Null
570.         Else
571.             i = i + 1
572.         End If
573.     Wend
574.     conv_str = str
575. End Function
576. 
577. 
578. Private Function conv_bin(str As String) As String
579.     Dim i As Integer, rstr As String
580.     
581.     rstr = ""
582.     i = 1
583.     While i <= Len(str)
584.         Select Case Mid$(str, i, 1)
585.             Case Chr$(0)  ' ASCII NUL
586.                 rstr = "\0"
587.             Case Chr$(8)  ' backspace
588.                 rstr = "\b"
589.             Case Chr$(9)  ' tab
590.                 rstr = "\t"
591.             Case "'"
592.                 rstr = "\'"
593.             Case """"
594.                 rstr = "\"""
595.             Case "\"
596.                 rstr = "\\"
597.             Case Chr$(10)  ' line feed
598.                 rstr = "\n"
599.             Case Chr$(13)  ' carriage return
600.                 rstr = "\r"
601.         End Select
602.         If rstr <> "" Then
603.             str = Left$(str, i - 1) & rstr & Right$(str, Len(str) - i)
604.             i = i + Len(rstr)
605.             rstr = ""
606.         Else
607.             i = i + 1
608.         End If
609.     Wend
610.     conv_bin = str
611. End Function
612. 
613. 
614. Private Sub warn(str As String, abortq As Boolean)
615.     If DISPLAY_WARNINGS Then MsgBox str, vbOKOnly Or vbExclamation, "Warning"
616.     warnings = warnings & COMMENT_PREFIX & " Warning: " & str & Chr$(13) & Chr$(10)
617. End Sub
618. 
619. 


Message édité 1 fois, la dernière par Petit_PimoOosE le 19 juillet 2004 - 22 h 05.

Huile de fraise.

gege38
Modérateur
Chief of the
(¯`·.__[T3aM.BouL3T©]__.·´¯)
Potatoe Reloaded

Messages : 14 079
Inscrit le 05/02/03
Ville : Domène
Non connecté
  Posté le 19 juillet 2004 - 21 h 56 m 54 s


Le 19 juillet 2004 à 20 h 46, Erel69 a écrit :


Le 19 juillet 2004 à 19 h 43, gege38 a écrit :
Google est ton ami ;)


Faudrait arrêter un peu avec ce slogan lol

Un forum c'est aussi pour se apsser de google et discuter directement avec les gens :D
Ouais mais bon, au moins, les gens évitent de croire que j'ai la science infuse :P
Non, je me suis pris 4.5 en BDD donc on peut dire que je suis loin d'etre un root de la BD :P



" Nous plaisons plus souvent dans le commerce de la vie par nos défauts que par nos qualités. "
--La Rochefoucauld


gomme
Schlakapouère (¯`·.__[T3aM.BouL3T©]__.·´¯) (¯`·.__[Alternatifs]__.·´¯)