Problems conecting to doctype's database

Hey guys,

I’m needing a connection to the database of the doctype named ‘Cliente’ that I created, but as soon as I try to connect to the database i give me de folowing error.

Traceback (most recent call last):
** File “/home/xpelite-02/frappe-bench/apps/frappe/frappe/desk/form/save.py”, line 22, in savedocs**
** doc.save()**
** File “/home/xpelite-02/frappe-bench/apps/frappe/frappe/model/document.py”, line 223, in save**
_** return self.save(*args, kwargs)
_** File “/home/xpelite-02/frappe-bench/apps/frappe/frappe/model/document.py”, line 252, in save**
** self.run_before_save_methods()**
** File “/home/xpelite-02/frappe-bench/apps/frappe/frappe/model/document.py”, line 750, in run_before_save_methods**
** self.run_method(“validate”)**
** File “/home/xpelite-02/frappe-bench/apps/frappe/frappe/model/document.py”, line 651, in run_method**
** out = Document.hook(fn)(self, *args, kwargs)
** File “/home/xpelite-02/frappe-bench/apps/frappe/frappe/model/document.py”, line 858, in composer**
** return composed(self, method, *args, kwargs)
** File “/home/xpelite-02/frappe-bench/apps/frappe/frappe/model/document.py”, line 841, in runner**
** add_to_return_value(self, fn(self, *args, kwargs))
** File “/home/xpelite-02/frappe-bench/apps/frappe/frappe/model/document.py”, line 645, in **
** fn = lambda self, *args, **kwargs: getattr(self, method)(*args, kwargs)
** File “/home/xpelite-02/frappe-bench/apps/route_management/route_management/route_management/doctype/completar_ruta/completar_ruta.py”, line 14, in validate**
** self.cliente = query();**
** File “/home/xpelite-02/frappe-bench/apps/route_management/route_management/route_management/doctype/completar_ruta/completar_ruta.py”, line 27, in query**
** {‘string1’: ‘Ruta Centro’}, as_dict=True )**
** File “/home/xpelite-02/frappe-bench/apps/frappe/frappe/database.py”, line 137, in sql**
_** self.cursor.execute(query, values)**
** File “/home/xpelite-02/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/cursors.py”, line 205, in execute**
** self.errorhandler(self, exc, value)**
** File “/home/xpelite-02/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/connections.py”, line 36, in defaulterrorhandler**
** raise errorclass, errorvalue**
ProgrammingError: (1146, “Table ‘fc166eb81361ff31.Cliente’ doesn’t exist”)

Traceback (most recent call last):
** File “/home/xpelite-02/frappe-bench/apps/frappe/frappe/app.py”, line 55, in application**
** response = frappe.handler.handle()**
** File “/home/xpelite-02/frappe-bench/apps/frappe/frappe/handler.py”, line 19, in handle**
** execute_cmd(cmd)**
** File “/home/xpelite-02/frappe-bench/apps/frappe/frappe/handler.py”, line 36, in execute_cmd**
** ret = frappe.call(method, frappe.form_dict)
** File “/home/xpelite-02/frappe-bench/apps/frappe/frappe/init.py”, line 895, in call**
** return fn(*args, newargs)
** File “/home/xpelite-02/frappe-bench/apps/frappe/frappe/desk/form/save.py”, line 22, in savedocs**
** doc.save()**
** File “/home/xpelite-02/frappe-bench/apps/frappe/frappe/model/document.py”, line 223, in save**
_** return self.save(*args, kwargs)
_** File “/home/xpelite-02/frappe-bench/apps/frappe/frappe/model/document.py”, line 252, in save**
** self.run_before_save_methods()**
** File “/home/xpelite-02/frappe-bench/apps/frappe/frappe/model/document.py”, line 750, in run_before_save_methods**
** self.run_method(“validate”)**
** File “/home/xpelite-02/frappe-bench/apps/frappe/frappe/model/document.py”, line 651, in run_method**
** out = Document.hook(fn)(self, *args, kwargs)
** File “/home/xpelite-02/frappe-bench/apps/frappe/frappe/model/document.py”, line 858, in composer**
** return composed(self, method, *args, kwargs)
** File “/home/xpelite-02/frappe-bench/apps/frappe/frappe/model/document.py”, line 841, in runner**
** add_to_return_value(self, fn(self, *args, kwargs))
** File “/home/xpelite-02/frappe-bench/apps/frappe/frappe/model/document.py”, line 645, in **
** fn = lambda self, *args, **kwargs: getattr(self, method)(*args, kwargs)
** File “/home/xpelite-02/frappe-bench/apps/route_management/route_management/route_management/doctype/completar_ruta/completar_ruta.py”, line 14, in validate**
** self.cliente = query();**
** File “/home/xpelite-02/frappe-bench/apps/route_management/route_management/route_management/doctype/completar_ruta/completar_ruta.py”, line 27, in query**
** {‘string1’: ‘Ruta Centro’}, as_dict=True )**
** File “/home/xpelite-02/frappe-bench/apps/frappe/frappe/database.py”, line 137, in sql**
_** self.cursor.execute(query, values)**
** File “/home/xpelite-02/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/cursors.py”, line 205, in execute**
** self.errorhandler(self, exc, value)**
** File “/home/xpelite-02/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/connections.py”, line 36, in defaulterrorhandler**
** raise errorclass, errorvalue**
ProgrammingError: (1146, “Table ‘fc166eb81361ff31.Cliente’ doesn’t exist”)

**** This is the code that connects to the doctype ****

def query():

** vars = frappe.db.sql(""“SELECT direccion**
** FROM tab[Cliente] WHERE ruta = %(string1)s”"", **
** {‘string1’: ‘Ruta Centro’}, as_dict=True )**
** return vars[0][0]**
pass

If anyone can help me please :frowning:

try, tabCliente instead of tab[Cliente].

you can also use the frappe.db.get_value, frappe.db.get_values, frappe.get_all etc methods to get the result from the database

Thanks, Makarand

Thanks @makarand_b it worked perfectly