源代码提示数据已保存,但表中没有数据。使用pyCharm和Postgres进行开发

时间:2014-07-22 09:07:31

标签: python postgresql pycharm

我有一个源代码,可以保存我开发的网页中的一组数据/输入。网页提示数据已保存,但在查看表格时,未保存任何记录。我正在使用pyCharm和Postgres进行此开发。希望有人能帮助我。

顺便说一句,我使用存储过程将数据集保存到表中,当我通过Postgres执行它时完全没问题。

-
我在编辑我的问题时添加了源代码。以下是与我的问题相关的所有源代码:

from DBHelper import DBHelper

class Manufacturer:
    def saveManufacturer(self, request):
        from django.db import connection, transaction
        helper = DBHelper()
        try:
            sql = format("SELECT savemanufacturer('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')" % (request.POST["manuCode"],
                         request.POST["longDesc"],
                         request.POST["shortDesc"],
                         request.POST["manuFlag"],
                         request.POST["activityStat"],
                         request.POST["activityDate"],
                         request.POST["street1"],
                         request.POST["street2"],
                         request.POST["city"],
                         request.POST["contactPerson1"],
                         request.POST["position1"],
                         request.POST["phone1"],
                         request.POST["contactPerson2"],
                         request.POST["position2"],
                         request.POST["phone2"],
                         request.POST["fax"],
                         request.POST["tin"]
            ))

            cursor = connection.cursor()
            cursor.execute(sql)

            result = cursor.fetchall()
        except Exception,e:
            print(e)

        return result[0]

------
我添加了我的存储过程。希望这有助于发现问题。我非常感谢你的帮助:

        CREATE OR REPLACE FUNCTION savemanufacturer(mancode text, longdesc text, shortdesc text, manuflag text, actstat text, actdate text, st1 text, st2 text, city text, person1 text, position1 text, person2 text, postion2 text, phone1 text, phone2 text, fax text, tin text)
          RETURNS integer AS
        $BODY$
        DECLARE myActDate TIMESTAMP;

        BEGIN
        myActDate := to_timestamp(ActDate,'YYYY-MM-DD');
        INSERT INTO "DEDGE_master_files_tblvendor"("VendorCode",
                               "LongDesc",
                               "ShortDesc",
                               "ManuFlag",
                               "ActivityStat",
                               "ActivityDate",
                               "Street1",
                               "Street2",
                               "City",
                               "ContactPerson1",
                               "Position1",    
                               "Phone1",
                               "ContactPerson2",
                               "Position2",
                               "Phone2",
                               "Fax",
                               "TIN")

        VALUES(ManCode,
               LongDesc,
               ShortDesc,
               ManuFlag,
               ActStat,
               myActDate,
               St1,
               St2,
               City,
               Person1,
               Position1,
               Phone1,
               Person2,
               Postion2,
               Phone2,
               Fax,
               TIN);
        RETURN 1;
        END;
        $BODY$
          LANGUAGE plpgsql VOLATILE

- - - -
最后这里是与这个问题有关的javascript:

        $("#manufacturer-add").click(function(){
            $("#manufacturer-add").fadeOut();
            $("#manufacturer-save").fadeIn();
        });

        $("#manufacturer-save").click(function (){
            var myData = {
                "token":"savemanufacturer",
                "manuCode":$("#ManufacturerCode").val(),
                "longDesc":$("#LongDesc").val(),
                "shortDesc":$("#ShortDesc").val(),
                "manuFlag":$("#ManuFlag").val(),
                "activityStat":$("#ActivityStat").val(),
                "activityDate":$("#ActivityDate").val(),
                "street1":$("#Street1").val(),
                "street2":$("#Street2").val(),
                "city":$("#City").val(),
                "contactPerson1":$("#ContactPerson1").val(),
                "position1":$("#Position1").val(),
                "phone1":$("#Phone1").val(),
                "contactPerson2":$("#ContactPerson2").val(),
                "position2":$("#Position2").val(),
                "phone2":$("#Phone2").val(),
                "fax":$("#Fax").val(),
                "tin":$("#TIN").val()
            }

            var csrftoken = getCookie('csrftoken');
            $.ajaxSetup({
                beforeSend: function (xhr, settings){
                    if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
                        xhr.setRequestHeader("X-CSRFToken", csrftoken);
                    }
                }
            });

            $.ajax({
                url: "/DEDGE/AJAX/IM/Maintain/Manufacturer",
                type: "POST",
                data: myData,
                success: function (msg){
                    if (msg==1){
                        alert("Successfully saved manufacturer!");
                    } else{
                        alert("Oops! " + msg)
                    }
                }
            })
        })

1 个答案:

答案 0 :(得分:0)

你正在使用bitnami吗?尝试重新安装独立的postgresql并尝试使用commit