diff --git a/TheBigOne.cls b/TheBigOne.cls index c403f9b..66b29ad 100644 --- a/TheBigOne.cls +++ b/TheBigOne.cls @@ -2374,7 +2374,7 @@ Function MISCe_col_to_letter(ByRef x As Long) As String End Function -Public Function SQLp_build_sql_values(ByRef tbl() As String, trim As Boolean, headers As Boolean, syntax As SQLsyntax, ByRef quote_headers As Boolean) As String +Public Function SQLp_build_sql_values(ByRef tbl() As String, trim As Boolean, headers As Boolean, syntax As SQLsyntax, ByRef quote_headers As Boolean, ParamArray typeflag()) As String Dim i As Long @@ -2388,6 +2388,14 @@ Public Function SQLp_build_sql_values(ByRef tbl() As String, trim As Boolean, he Dim strip_text As String Dim strip_num As String Dim strip_date As String + Dim nullText As String + + If syntax = PostgreSQL Then + nullText = "text" + Else + nullText = "varchar(255)" + End If + Set rx = CreateObject("vbscript.regexp") rx.Global = True @@ -2396,40 +2404,48 @@ Public Function SQLp_build_sql_values(ByRef tbl() As String, trim As Boolean, he strip_num = "[^0-9\.]" strip_date = "[^0-9\/\-\:\.]" - ReDim type_flag(UBound(tbl, 1)) - For j = 0 To UBound(tbl, 1) - If IsNumeric(tbl(j, 1)) Then - If InStr(1, tbl(j, 1), ".") > 0 Then - type_flag(j) = "N" - Else - type_flag(j) = "S" - End If - Else - If Len(tbl(j, 1)) >= 6 Then - If IsDate(tbl(j, 1)) Then - type_flag(j) = "D" + '------if a type flag array has been supplied copy its contents--------------- + If UBound(typeflag) <> -1 Then + ReDim type_flag(UBound(typeflag)) + For i = 0 To UBound(typeflag) + type_flag(i) = typeflag(i) + Next i + Else + ReDim type_flag(UBound(tbl, 1)) + For j = LBound(tbl, 1) To UBound(tbl, 1) + If IsNumeric(tbl(j, LBound(tbl, 2) + 1)) Then + If InStr(1, tbl(j, 1), ".") > 0 Then + type_flag(j) = "N" Else type_flag(j) = "S" End If Else - type_flag(j) = "S" + If Len(tbl(j, 1)) >= 6 Then + If IsDate(tbl(j, 1)) Then + type_flag(j) = "D" + Else + type_flag(j) = "S" + End If + Else + type_flag(j) = "S" + End If End If - End If - Next j + Next j + End If rx.Pattern = strip_text If headers Then - start_row = 1 - For i = 0 To UBound(tbl, 1) - If i > 0 Then col_name = col_name & "," + start_row = LBound(tbl, 2) + 1 + For i = LBound(tbl, 1) To UBound(tbl, 1) + If i > LBound(tbl, 1) Then col_name = col_name & "," If quote_headers Then - col_name = col_name & """" & rx.Replace(tbl(i, 0), "") & """" + col_name = col_name & """" & rx.Replace(tbl(i, LBound(tbl, 2)), "") & """" Else - col_name = col_name & rx.Replace(tbl(i, 0), "") + col_name = col_name & rx.Replace(tbl(i, LBound(tbl, 2)), "") End If Next i Else - start_row = 0 + start_row = LBound(tbl, 2) End If @@ -2437,8 +2453,8 @@ Public Function SQLp_build_sql_values(ByRef tbl() As String, trim As Boolean, he rec = "" If i <> start_row Then sql = sql & "," & vbCrLf rec = rec & "(" - For j = 0 To UBound(tbl, 1) - If j <> 0 Then rec = rec & "," + For j = LBound(tbl, 1) To UBound(tbl, 1) + If j <> LBound(tbl, 1) Then rec = rec & "," Select Case type_flag(j) Case "N" '-------N = numeric but should probably be N for numeric---- rx.Pattern = strip_num @@ -2450,7 +2466,7 @@ Public Function SQLp_build_sql_values(ByRef tbl() As String, trim As Boolean, he Case "S" '-------S = string------------------------------------------ rx.Pattern = strip_text If LTrim(RTrim(tbl(j, i))) = "" Then - rec = rec & "CAST(NULL AS VARCHAR(255))" + rec = rec & "CAST(NULL AS " & nullText & ")" Else If trim Then rec = rec & "'" & LTrim(RTrim(rx.Replace(tbl(j, i), ""))) & "'" @@ -2469,7 +2485,7 @@ Public Function SQLp_build_sql_values(ByRef tbl() As String, trim As Boolean, he Case Else '-------Assume text------------------------------------------ rx.Pattern = strip_text If LTrim(RTrim(tbl(j, i))) = "" Then - rec = rec & "CAST(NULL AS VARCHAR(255))" + rec = rec & "CAST(NULL AS " & nullText & ")" Else If trim Then rec = rec & "'" & LTrim(RTrim(rx.Replace(tbl(j, i), ""))) & "'"