PDO插入不起作用

时间:2015-08-07 23:37:48

标签: php mysql pdo insert

我有一个问题我每次向我返回false时都无法通过PDO编写请求。

UdpClient^ receivingUdpClient = gcnew UdpClient(30011);
//                  specify the port both here  ^^^^^  and here vvvvv
IPEndPoint^ RemoteIpEndPoint = gcnew IPEndPoint(IPAddress::Any, 30011);
array <Byte>^ receiveBytes = receivingUdpClient->Receive(RemoteIpEndPoint);

1 个答案:

答案 0 :(得分:0)

看起来您正在构建正确的查询,但无论如何,这可能是一种更简洁的方法,最后的检查应该会为您提供有关出错的更多信息:

(defn add-handlers!
  "Adds common keyboard handler and focus listener to temporary editing graphic.
  graphic is typically textfield or combo-box. cell is tablecell which
  is being edited.  getterfn is function to get value from graphic so
  it can be commited to database."
  [graphic cell getterfn]
  (let [focus-listener (make-focus-change-listener cell getterfn)]
    (println "adding focus and keyboard listener")
    (add-listener! graphic :focused focus-listener)
    (.setOnKeyPressed graphic (eventhandler [e] ;; here "cell" still refers to the tablecell
                                            (condp = (.getCode e)
                                              KeyCode/ENTER (do (println "ENTER pressed.  Removing focus listener")
                                                                (remove-listener! graphic :focused focus-listener) ;; Prevent double-commit on defocus
                                                                (.commitEdit cell (getterfn)))
                                              KeyCode/ESCAPE (do (println "ESC pressed. Removing focus listener")
                                                                 (remove-listener! graphic :focused focus-listener) ;; Prevent double-commit on defocus
                                                                 (.cancelEdit cell)) ;; Removes textfield
                                              KeyCode/TAB (let [index (.. cell getTableRow getIndex)
                                                                next-column (get-next-column cell (not (.isShiftDown e)))]
                                                            (println "TAB pressed.  Removing focus listener")
                                                            (remove-listener! graphic :focused focus-listener) ;; Prevent double-commit on defocus
                                                            (.commitEdit cell (getterfn))
                                                            (.edit (.getTableView cell) index next-column))
                                              nil))))) ;; do nothing


(defn make-combobox
  "Implements dropdown combobox.  'cell' is fancy table cell in
  question.  'items' is list of things for dropdown, which can be
  anything that the dropdown can render and choose as the final item"
  [cell initvalue & [items]]
  (let [cmb (jfxnode ComboBox (observable items))
        cell-factory FANCY-LISTCELL-FACTORY
        blank-cell (.call cell-factory nil)]
    (doto cmb
      (add-handlers! cell #(.getValue cmb))
      (.setValue initvalue)
      (.setButtonCell blank-cell)
      (.setCellFactory cell-factory))))


(defn render-cell-with-item!
  "Puts correct item in cell graphic and/or text property based on item
  type.  Additional arguments for editing such as drop-down, are
  handled in the startEdit function; this function just renders the
  cell when called by updateItem or cancelEdit."
  [cell item]
  (cond
    (instance? Node item) (set-graphic-text! cell item nil) ;; for a graphic/Node item
    (instance? Boolean item) (let [[var full-accesspath] (calc-full-accesspath cell)
                                   cb (jfxnode CheckBox
                                               :text (str item)
                                               :selected item
                                               :disable (not (mutable? var)))]
                               (.setEditable cell false)
                               (set-graphic-text! cell cb nil)
                               (when (mutable? var)
                                 (uni-bind! (.selectedProperty cb) var full-accesspath)))
    (instance? clojure.lang.PersistentVector item) (set-graphic-text! cell (Label. "Put vector editor here") nil)
    (instance? Color item) (set-graphic-text! cell (make-color-box item) (color-map-inverse item))
    ;; All other types go here, presumably text types, so assume editable
    :else (set-graphic-text! cell nil (si/to-normstr item))))   ;; else set underlying text


(def FANCY-TABLECELL-FACTORY
  "The main callback interface which constructs the actual each cell
  for arbitrary types.  Assumes an editable cell for text representations."
  (callback [column]  
            (proxy [TableCell] []
              (updateItem [item empty]
                (proxy-super updateItem item empty)
                (when (not empty) 
                  (render-cell-with-item! this item)))

              (startEdit []
                (proxy-super startEdit)
                ;; Change to appropriate graphic when editing
                (println "in proxy's startEdit.  Column commitHandler is" (.getOnEditCommit column))
                (let [item (apply access-db (calc-full-accesspath this))
                      options (get-field-options this)] ;; could be nil ...
                  (if-let [combo-items (:combo-items options)] ;; ... so put as argument to :combo-items
                    (let [cmb (make-combobox this item combo-items)]
                      (set-graphic-text! this cmb nil)
                      (.requestFocus cmb)
                      (.show cmb)) ;; This makes drop-down appear without clicking twice.
                    (when (textish? item)
                      (let [tf (make-textfield-editor this)]
                        (set-graphic-text! this tf nil) ;; just set tf as graphic; leave existing text alone
                        (.requestFocus tf)
                        (.selectAll tf))))))
              (cancelEdit []
                ;; CancelEdit gets called either by defocus or by ESC.
                ;; In any case, use the item currently in the database
                ;; for this cell and just render as in updateItem
                (proxy-super cancelEdit)
                (let [item (apply access-db (calc-full-accesspath this))]
                  (render-cell-with-item! this item)))
              (commitEdit [value]
                ;; Nothing to do here.  All commits happen either in the textField callback or in the column edit callback
                (println "in cell's commitEdit, before super")
                (proxy-super commitEdit value)
                (println "in cell's commitEdit, after super")))))


(defn inner-table-view*
  "Make inner table view for use by inspector-view and table-view"
  [var accesspath columns]
  (let [obslist (observable (var-snapshot var accesspath))]
    (jfxnode TableView
             :user-data {:var var ;; the actual var... 
                         :accesspath accesspath }  ;; ... and how to get to the displayed data
             :items obslist
             :columns columns
             :editable (mutable? var))))

(defn inspector-view
  "Takes plain map or atom/var/ref/agent of map and displays fields
  and values in JFX TableView. Compound values (ie maps, vectors,
  etc., for now are just displayed as their string value.  If access
  is supplied, assumes m is var/ref/atom and assigns appropriate
  linkage between m and view contents.  The topmost available var or
  map is assigned to the TableView, and the accessor for each field is
  assigned to each column."
  [var & {:keys [accesspath field-options]}]
  (let [ismutable (mutable? var)
        field-col (jfxnode TableColumn "Field"
                           :cell-value-factory CELL-VALUE-FACTORY
                           :cell-factory SIMPLE-TABLECELL-FACTORY
                           :user-data {:accessfn key } ;; label-only option not relevant yet
                           :editable false
                           :sortable true)
        value-col (jfxnode TableColumn "Value"
                           :cell-value-factory CELL-VALUE-FACTORY
                           :cell-factory FANCY-TABLECELL-FACTORY
                           :user-data {:accessfn val} ;; val is fn for accessing cell values from data item
                           :on-edit-start (eventhandler [e] (println "editing column " (.getOldValue e) (.getNewValue e)))
                           :on-edit-cancel (eventhandler [e] (println "canceling column with event" e))
                           :on-edit-commit (eventhandler [e] (do (println "column's on-edit-commit handler calling column-commit") (column-commit e)))
                           :editable ismutable
                           :comparator columnComparator)
        type-col (jfxnode TableColumn "Type"
                          :cell-value-factory CELL-VALUE-FACTORY
                          :cell-factory SIMPLE-TABLECELL-FACTORY
                          :user-data {:accessfn #(type (val %))}
                          :editable false
                          :sortable true)
        cols [field-col value-col type-col]

        tv (inner-table-view* var accesspath cols)]
    ;; Add options to table's userData.  This is for inspector-view
    ;; not table-view, so we don't put this in inner-table-view
    ;; function
    (let [userdata (.getUserData tv)
          newuserdata (conj userdata {:field-options field-options})]
      (.setUserData tv newuserdata))

    ;; Add watches, use tv instance as key so we can remove it later
    ;; This gets called each time db is changed.
    (if (mutable? var)
      (add-watch var tv (fn [k r o n] ;; Key Ref Old New
                          (println "Inside KRON with new var" n)
                          ;; Capture the existing sort order and type
                          ;; Taken from http://stackoverflow.com/questions/11096353/javafx-re-sorting-a-column-in-a-tableview
                          (let [sort-order (vec (.getSortOrder tv)) ;; need to remember ObservableList<TableColumn> and vectorize or it gets reset from underneath us
                                sort-types (map #(.getSortType %) sort-order)
                                sortables (map #(.isSortable %) sort-order)]

                            ;; Here we actually put the items into the tableview after the change
                            (.setItems tv (observable (var-snapshot var accesspath))) 

                            ;; Sort order is now empty up so we put back what was in it
                            (let [new-sort-order (.getSortOrder tv)] ;; get ObservableList<TableColumn>
                              (.setAll new-sort-order (into-array sort-order)) ;; reset the sort order based on what was there before

                              ;; Assign sorting to each column
                              (doseq [col sort-order, sort-type sort-types, sortable sortables]
                                (.setSortType col sort-type)
                                (.setSortable col sortable)))))))
    tv))